<jupyter_start><jupyter_text>This is the code for object oriented programming of Yasakawa Robot DX100 working on UDP protocol.  I have not yet completed the problem but i am very close to completing it.  the UDP reader in Yasakawa is reading data in bytes in big endian format but the data is to be sent before the timeout period.. that is 1 second roughly.  so when we are sending we are converting everything we want to send to a list of bytes this list is then sent (one-by-one) then there is a delay of 1 second hopefully this whole message is considered as one<jupyter_code>class RobotDX100:
    import socket
    import time
    
    #variables and the order for sending variables
    
    tosend1 = [89, 69, 82, 67, 32, 0, 4, 0, 3, 1, 0]
    #reqid = 01,02,03
    tosend2 = [0, 0, 0, 0, 57, 57, 57, 57, 57, 57, 57, 57]
    #cdno = int('83') 
    tosend3 = [0]
    #inst = 2
    tosend4 = [0] 
    #att = [1] 
    #ser = int('10')
    tosend5 = [0, 0]
    #dataon = [1,0,0,0]
    
    def __init__(self, ip = '192.168.0.151', port = 10040):
        self.ip = ip
        self.port = port
        
    def connect(self):
        import socket
        #to create the socket through which we will be sending our UDP message to the server
        clientSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    
    def servo(self, on = 1):
        import socket

        #to write the code that will send our UDP message (turn on)
        reqid = [1]
        cdno = [83]
        inst = [2] 
        att = [1]
        ser = [10]
        dataon = [1, 0, 0, 0]
        dataoff = [2, 0, 0, 0]
        var = RobotDX100.tosend1
        var.extend(reqid)
        var.extend(RobotDX100.tosend2)
        var.extend(cdno)
        var.extend(RobotDX100.tosend3)
        var.extend(inst)
        var.extend(RobotDX100.tosend4)
        var.extend(att)
        var.extend(ser)
        var.extend(RobotDX100.tosend5)
        dataservoon = var
        dataservoon.extend(dataon)
        dataservooff = var
        dataservooff.extend(dataoff)
        
        
        if on == True:
            return dataservoon
        else:
            #to write the code that will send our UDP message (turn off)
            return dataservooff
                
        time.sleep(5)# number of seconds
        
    
r = RobotDX100()
r.connect()
r.var.to_bytes(1,'big')
import socket
import time
UDP_IP_ADDRESS = r.ip
UDP_PORT_NO = r.port

#make x = dataservoon in bytes.
x = [i.to_bytes(1, 'big') for i in r.servo(True)]
#to write each element (One-by-one) of the list in our UDP message (turn on)
[clientSock.sendto( i , (r.ip, r.port)) for i in x]
#r.var = 0

time.sleep(5)# number of seconds


#make x = dataservooff in bytes.
x = [i.to_bytes(1, 'big') for i in r.servo(False)]
#to write each element (One-by-one) of the list in our UDP message (turn on)
[clientSock.sendto( i , (r.ip, r.port)) for i in x]
#r.var = 0

r.var<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup