January 18, 2019, 03:44:37 AM
Robotforum | Industrial Robots Community

 UDP PORT problem with D Series Controller


Author Topic:  UDP PORT problem with D Series Controller  (Read 853 times)

0 Members and 1 Guest are viewing this topic.

October 25, 2018, 10:32:43 AM
Read 853 times
Offline

4wheeled


Hi,

I'm new here. We have a Kawasaki robot with D series controller. We tried to do some communication from PC with the controller using UDP.

The problem we have right now is that, the robot can send UDP data to the PC, but we don't know how to send commands back to the robot with UDP.

Here is our procedure that does not work:
First, in the AS, we use UDP_SENDTO to send the data to PC. When the PC received the data, the PC determines the PORT number of the robot from the data. And we use this PORT number to send the commands to the robot, where in the AS program UDP_RECVFROM is used. It does not work. We found that the PORT number always different each time the data is sent.

So are we in the right direction? What would be the solution to this?

Thanks,

Jay

Linkback: https://www.robot-forum.com/robotforum/index.php?topic=29313.0
  • Like    Thanks

Today at 03:44:37 AM
Reply #1

Advertisement

Guest

October 25, 2018, 03:59:28 PM
Reply #1
Offline

Alexandru


hello,

what kind of information do you want to send? I have an example in which i send via TCP communication some strings, something like this:
1,2,3,5,6,1,2 with the feedback from the robot if it can receive the information or not. The controller used was E controller.
  • Like    Thanks

October 25, 2018, 07:28:49 PM
Reply #2
Offline

kwakisaki

Global Moderator
Welcome to the board............ :beerchug:

Can you post any code snippets as an example?

Make sure the port number on the Kawasaki for UDP_SENDTO and UDP_RECVFROM is between 8192-65535, the socket should automatically open/close with each execution.
Try Sending and Receiving on different port numbers, it may be that the socket has failed to close on the Kawasaki (I think from memory a max of 8 sockets can be open).
What is your 'error return value' coming back with, this will assist in troubleshooting the issue?
Are you sure your PC is sending the data - ie is that successfully opening the socket to the port on the correct IP address?
  • Like    Thanks

October 26, 2018, 12:22:29 AM
Reply #3
Offline

4wheeled


“what kind of information do you want to send? ”, we are trying to do laser guided tracking. So we need to continuously send track data to the robot.

We were able to send data to the robot with TCP/IP, but we would like to try UDP as it is faster.
  • Like    Thanks

October 26, 2018, 12:59:14 AM
Reply #4
Offline

4wheeled


"Welcome to the board........"
Thanks!

"What is your 'error return value' coming back"
Timeout. Basically it does not receive anything.

"Are you sure your PC is sending the data"
Actually I'm not sure. So I guess we will check.

But I'm worried that maybe there is some conceptual issue here: in my understanding, on the PC side when we send the data to the robot, we need to specify the port where the robot will receive the data. But the point is, where can we find the port number on the robot side?

  • Like    Thanks

October 26, 2018, 02:05:05 AM
Reply #5
Offline

4wheeled


PC side of the code:

#include "tracker.h"
#include "ui_tracker.h"

using namespace std;

QString robot2str(RobotPos f)
{
    QString c2fstr = QString::number(f.x,'f',3);
    c2fstr.append(",");
    c2fstr.append(QString::number(f.y,'f',3));
    c2fstr.append(",");
    c2fstr.append(QString::number(f.z,'f',3));
    c2fstr.append(",");
    c2fstr.append(QString::number(f.a,'f',3));
    c2fstr.append(",");
    c2fstr.append(QString::number(f.b,'f',3));
    c2fstr.append(",");
    c2fstr.append(QString::number(f.c,'f',3));
    return c2fstr;
}




//////////////////////tracker.h

class tracker : public QWidget
{
    Q_OBJECT

public:
    explicit tracker(QWidget *parent = 0);
    ~tracker();

private:
    Ui::tracker *ui;
    QUdpSocket * posSock;   //autostart
    QUdpSocket * us;        //conudp
    QHostAddress robotAddr; //UDP IP
    quint16      robotPort; //UDP
    RobotPos     curpos;    //
    bool         asStatus;  //UDP status
private slots:
    void readPos();
    void readPendingDatagrams();
    void on_absoluteRunBtn_clicked();
    void on_curposBtn_clicked();
};




//////////////////////tracker.cpp

tracker::tracker(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::tracker)
{
    asStatus = false;
    posSock = new QUdpSocket;
    posSock->bind(QHostAddress("192.168.1.120"),10000);
    connect(posSock,SIGNAL(readyRead()),this,SLOT(readPos()));
    us = new QUdpSocket;
    us->bind(QHostAddress("192.168.1.120"),10013);
    connect(us,SIGNAL(readyRead()),this,SLOT(readPendingDatagrams()));
    ui->setupUi(this);
}

tracker::~tracker()
{
    delete ui;
}

void tracker::readPos()
{
    while(posSock->hasPendingDatagrams())
    {
        QByteArray datagram;
        datagram.resize(posSock->pendingDatagramSize());
        QHostAddress pos_sender;
        quint16 pos_senderPort;
        posSock->readDatagram(datagram.data(),datagram.size(),&pos_sender,&pos_senderPort);
        QString posstr = QString(datagram);
        posstr.replace(" ","");
        QStringList poslst = posstr.split(",");
        if(poslst.size()< 12)
            continue;
        QString axlestr = "J1:"+poslst[6]+" J2:"+poslst[7]+" J3:"+poslst[8]+" J4:"+poslst[9]+" J5:"+poslst[10]+" J6:"+poslst[11];
        ui->lblaxle->setText(axlestr);
        QString rposstr = "X:"+poslst[0]+" Y:"+poslst[1]+" Z:"+poslst[2]+" O:"+poslst[3]+" A:"+poslst[4]+" T:"+poslst[5];
        ui->lblcurpos->setText(rposstr);
        curpos = {poslst[0].toDouble(),poslst[1].toDouble(),poslst[2].toDouble(),poslst[3].toDouble(),poslst[4].toDouble(),poslst[5].toDouble(),CURRENT};
    }
}

void tracker::readPendingDatagrams()
{
    while(us->hasPendingDatagrams())
    {
        QByteArray datagram;
        datagram.resize(us->pendingDatagramSize());
        us->readDatagram(datagram.data(),datagram.size(),&robotAddr,&robotPort);
        QString msg(datagram);
        if(msg != "kawasaki")
        {
            robotPort = 0;
            continue;
        }
        else
        {
            asStatus = true;
            ui->lblconnStatus->setText("AS Connected");
        }
    }
}

// current position
void tracker::on_curposBtn_clicked()
{
    ui->abPosEdt->setText(robot2str(curpos));
}

void tracker::on_absoluteRunBtn_clicked()
{
    QString text = "1,";
    text.append(ui->abPosEdt->text());
    //us->writeDatagram(text.toLatin1(),QHostAddress::Broadcast,0);
    us->writeDatagram(text.toLatin1(),robotAddr,robotPort);
}
  • Like    Thanks

October 26, 2018, 02:06:20 AM
Reply #6
Offline

4wheeled


AS side of the code:

cx = 0
px = 0
ip[0] = 192
ip[1] = 168
ip[2] = 1
ip[3] = 120
port = 9000
.$msg[1] = "kawasaki"
.ret = 0
loop:
UDP_SENDTO .ret,ip[0],10013,.$msg[1],1,1
IF .ret<>0 THEN
GOTO ends
END
.$recv1 = ""
.$recv[0] = ""
PRINT "ready to receive!"
UDP_RECVFROM .ret,10013,.$recv[0],pp,2,ip[0],255
IF .ret<>0 THEN
CASE .ret OF
VALUE -34019:
.$msg[1] = "-34019"
VALUE -34020:
.$msg[1] = "-34019"
VALUE -34021:
.$msg[1] = "-34019"
VALUE -34022:
.$msg[1] = "-34019"
VALUE -34023:
.$msg[1] = "-34019"
VALUE -34024:
.$msg[1] = "-34019"
VALUE -34025:
.$msg[1] = "-34019"
VALUE -34026:
.$msg[1] = "-34019"
VALUE -34027:
.$msg[1] = "-34019"
ANY:
.$msg[1] = "undefined"
END
GOTO loop
END
.$recv1 = .$recv[0]
IF .$recv1!="" THEN
vj = 0
DO
.$temp = $DECODE(.$recv1,",",0)
.vl[vj] = VAL(.$temp)
IF .$recv1=="" GOTO work
.$temp = $DECODE(.$recv1,",",1)
vj = vj+1
UNTIL .$recv1==""
END
IF vj<6 THEN
GOTO loop
END
work:
CASE .vl[0] OF
VALUE 1:
POINT .tp[px] = TRANS(.vl[1],.vl[2],.vl[3],.vl[4],.vl[5],.vl[6])
px = px+1
IF px == 10 THEN
px = 0
END
IF cx != px THEN
GOTO trace
END
.vl[0] = 0
VALUE 2:
VALUE 3:
VALUE 4:
ANY:
PRINT "coordinate is not 01,02,03,04"
END
trace:
LMOVE .tp[cx]
cx = cx+1
IF cx == 10 THEN
cx = 0
END
GOTO loop
ends:

  • Like    Thanks

Today at 03:44:37 AM
Reply #7

Advertisement

Guest

October 26, 2018, 10:36:59 AM
Reply #7
Offline

kwakisaki

Global Moderator
Not to sure about your other code, but have tested your AS code between a Robot and Hercules (app on PC) and the UDP comms is working between them.

I also used a quick 'squirt' test and confirmed the actual UDP structure works too.

Code: [Select]
.PROGRAM udp_rcv()
;==========================================
;Receive string from Hercules (PC)
;==========================================
  .ret = 0; error return
  .ele = 1; No. of elements to receive
  .$rcv[0] = "Nothing"
  ip[0] = 192
  ip[1] = 168
  ip[2] = 0
  ip[3] = 254; IP Array of PC
  prt_no = 10013; Socket to use Port No.
;==========================================
  UDP_RECVFROM .ret,prt_no,.$rcv[0],.ele,10,ip[0],255
  IF .ret<>0 THEN
    PRINT "Error during Receive = ",.ret
  ELSE
    PRINT .$rcv[0]
  END
.END
.PROGRAM udp_snd()
;==========================================
;Send string to Hercules (PC)
;==========================================
  .ret = 0; error return
  ip[0] = 192
  ip[1] = 168
  ip[2] = 0
  ip[3] = 254; IP Array of PC
  prt_no = 10013; Socket to use Port No.
  .$snd[0] = "From Kawasaki"; String to send
;==========================================
  UDP_SENDTO .ret,ip[0],prt_no,.$snd[0],1,2
  IF .ret<>0 THEN
    PRINT "Error during Send = ",.ret
  END
.END
.REALS
ip[0] = 192
ip[1] = 168
ip[2] = 0
ip[3] = 254
prt_no = 10013
.END

So I suspect it is down to your coding in the PC side.
- perhaps the sockets are being incorrectly bound.
Quote
{
    asStatus = false;
    posSock = new QUdpSocket;
    posSock->bind(QHostAddress("192.168.1.120"),10000);
    connect(posSock,SIGNAL(readyRead()),this,SLOT(readPos()));
    us = new QUdpSocket;
    us->bind(QHostAddress("192.168.1.120"),10013);
    connect(us,SIGNAL(readyRead()),this,SLOT(readPendingDatagrams()));
    ui->setupUi(this);
}
« Last Edit: October 26, 2018, 10:41:03 AM by kwakisaki »
  • Like    Thanks

October 27, 2018, 02:33:59 AM
Reply #8
Offline

4wheeled


Thank you so much! This is great!

We will try using the Hercules. If it's possible, could you post a few screen captures on how to setup the Hercules?
  • Like    Thanks

October 27, 2018, 07:35:39 AM
Reply #9
Offline

kwakisaki

Global Moderator
See attached.
- This worked with my quick squirt and also your code.
- However, your code I did not test any functionality, only the comms side.
  • Like    Thanks

October 28, 2018, 12:45:45 PM
Reply #10
Offline

4wheeled


Thank you so much.

So it looks like the IP (192.168.0.2) and the port (10013) are all for the PC (Hercules) side. It does not show the IP and port number for the robot, I guess.
  • Like    Thanks

October 28, 2018, 06:05:15 PM
Reply #11
Offline

kwakisaki

Global Moderator
What is circled:
- Is the IP of the device you want to connect to (That is the IP of the Robot Controller - Kawasaki IP is static only, not dynamic, so you need to set this manually).
- The Port Number you want the socket of Hercules to Listen on (Which has to be the same Port No as what you are using in the UDP command structure in the Kawasaki, again you need to set this manually).
- You do of course, need to make sure the IP of the PC is in the same scope/subnet as the Kawasaki.

Remember, you open a port using a socket:
- Hercules Opens a socket to this port and listens using the IP of the PC.
- Kawasaki Open/Closes a socket when you execute the UDP_SENDTO/UDP_RECVFROM to the IP and Port No. in the command iteration.
- Kawasaki UDP should always close the socket after each instruction, irrespective of errors........so in theory you are only ever using one socket (unless you are UDP'ing to more than one device at the same time).
  • Like    Thanks

October 31, 2018, 10:57:07 AM
Reply #12
Offline

4wheeled


Hi Kwakisaki,

Communication with the robot is ok now with Hercules. We are trying to implement the C++ code now. Still having some problem, but I will keep you guys posted.

Thanks,

Jay
  • Like    Thanks

October 31, 2018, 12:26:13 PM
Reply #13
Offline

kwakisaki

Global Moderator
Good man.... :bravo:
Handy tool Hercules, can help with testing/evaluating comms code especially when you’re not sure which device the issue is occurring with..
Glad to help...
  • Like    Thanks

Today at 03:44:37 AM
Reply #14

Advertisement

Guest


Share via facebook Share via linkedin Share via pinterest Share via reddit Share via twitter

xx
z series robot with E controller encoder problem

Started by ebb on Kawasaki Robots

3 Replies
379 Views
Last post October 24, 2018, 05:46:54 PM
by kwakisaki
question
Kawasaki D-series controller D7x SERIES encoder battery replacement

Started by Virgilio on Kawasaki Robots

3 Replies
382 Views
Last post November 14, 2018, 07:31:22 AM
by Alexandru
xx
KRC2 KR210 usb port problem

Started by Blackeyed on KUKA Robot Forum

8 Replies
2492 Views
Last post September 25, 2016, 10:04:12 PM
by Event Robotics
question
Controller communication port For dx200

Started by omran_1431 on Yaskawa Motoman Robot Forum

1 Replies
546 Views
Last post May 21, 2018, 08:46:12 PM
by David Casella