source: ETALON/positioning_systems/WAGO/Python_control/wago_communication.py @ 602

Last change on this file since 602 was 602, checked in by malovyts, 8 years ago

added the python control programms and commands list

File size: 2.5 KB
Line 
1def command(message):
2        import socket
3        HOST = '10.0.1.161'    # The remote host
4        PORT = 30000              # The same port as used by the server
5        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
6        s.connect((HOST, PORT))
7        s.sendall(message)
8        data = s.recv(4096)
9        s.close()
10        return data.split('\x00')[0]
11def wago_hello(): # enable motor
12        answ = command('hello')
13        return answ
14def motor_enable(motorN): # enable motor
15        answ = command(str(motorN)+'CE'+str(0).zfill(9))
16        return answ
17def motor_disable(motorN): # disable motor
18        answ = command(str(motorN)+'CD'+str(0).zfill(9))
19        return answ
20def motor_reset(motorN): # reset motor
21        answ = command(str(motorN)+'CR'+str(0).zfill(9))
22        return answ
23def motor_absolute(motorN): # move to absolute position
24        answ = command(str(motorN)+'GA'+str(0).zfill(9))
25        return answ
26def motor_relative(motorN): # move to relative position
27        answ = command(str(motorN)+'GR'+str(0).zfill(9))
28        return answ
29def motor_stop(motorN): # stop the motor
30        answ = command(str(motorN)+'GS'+str(0).zfill(9))
31        return answ
32def motor_start(motorN): # start the motor
33        answ = command(str(motorN)+'GG'+str(0).zfill(9))
34        return answ
35def motor_set(motorN, parameter, value): # set the parameters
36        par_letter=''
37        if(parameter=='accel'):
38                par_letter='A'
39        if(parameter=='decel'):
40                par_letter='D'
41        if(parameter=='velo'):
42                par_letter='V'
43        if(parameter=='tar_pos'):
44                if(value>=0):
45                        par_letter='P'
46                else:
47                        par_letter='p'
48                        value=-value
49        if(parameter=='curr_pos'):
50                if(value>=0):
51                        par_letter='C'
52                else:
53                        par_letter='c' 
54                        value = -value;
55        answ = command(str(motorN)+'S'+par_letter+str(value).zfill(9))
56        return answ
57def motor_get(motorN, parameter): # get the parameters
58        par_letter=''
59        if(parameter=='accel'):
60                par_letter='A'
61        if(parameter=='decel'):
62                par_letter='D'
63        if(parameter=='velo'):
64                par_letter='V'
65        if(parameter=='curr_pos'):
66                par_letter='P'
67        if(parameter=='curr_speed'):
68                par_letter='C'
69        if(parameter=='status'):
70                par_letter='S'
71        if(parameter=='refer'):
72                par_letter='R'
73        answ = command(str(motorN)+'Q'+par_letter+str(0).zfill(9))
74        return answ
75       
76def motor_move_absolute(motorN, tar_position, velocity):
77        motor_absolute(motorN)
78        motor_set(motorN, 'tar_pos', tar_position)
79        motor_set(motorN, 'velo', velocity)
80        motor_start(motorN)
81        return
82def motor_move_relative(motorN, tar_position, velocity): 
83        motor_relative(motorN)
84        motor_set(motorN, 'tar_pos', tar_position)
85        motor_set(motorN, 'velo', velocity)
86        motor_start(motorN)
Note: See TracBrowser for help on using the repository browser.