-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudp_server_dict.py
59 lines (47 loc) · 1.65 KB
/
udp_server_dict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import rospy
from geometry_msgs.msg import Twist
from sensor_msgs.msg import Joy
from ackermann_msgs.msg import AckermannDriveStamped
from std_msgs.msg import Bool
import socket
import pickle
# sudo apt-get install ros-kinetic-teleop-twist-joy
#rostopic echo /joy
#roslaunch teleop_twist_joy teleop.launch
# Author: SEUNGIL HAN
# E-mail: robotics@kaist.ac.kr
# This ROS Node converts Joystick inputs from the joy node
# into commands for Widnow PC with UDP communication
# Receives joystick messages (subscribed to Joy topic)
# then converts the joysick inputs into Twist commands
# axis 4 aka right stick vertical controls linear speed
# axis 0 aka left stick horizonal controls angular speed
UDP_IP = "127.0.0.1" # write your Client IP Address local is 127.0.0.1
UDP_PORT = 5005 #port number
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
def callback(data):
# print(type(sock))
twist = Twist()
# vertical left stick axis = linear rate
twist.linear.x = 1*data.axes[4]
# horizontal left stick axis = turn rate
twist.angular.z = -1*data.axes[0]
command = {"longitudinal_cntrl_shock_level": twist.linear.x,
"lateral_cntrl_shock_level": twist.angular.z
}
MESSAGE = pickle.dumps(command)
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
pub.publish(twist)
# print(twist.linear.x)
# print(twist.angular.z)
# Intializes everything
def start():
rospy.init_node('Joy2WindowPC')
global pub
pub = rospy.Publisher('turtle1/cmd_vel', Twist, queue_size=1)
rospy.Subscriber("joy", Joy, callback)
rospy.spin()
if __name__ == '__main__':
start()
sock.close()