-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudp_send_carmaker.py
50 lines (40 loc) · 1.48 KB
/
udp_send_carmaker.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
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
import struct
# 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 = 60001 #port number
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
def VehCommandCallback(data):
# print(type(sock))
acceleration=data.drive.acceleration
steering_angle = data.drive.steering_angle
command=struct.pack('=Bddib', 255,steering_angle,acceleration,1,0)
upcommand= struct.unpack('=Bddib',command)
# MESSAGE = pickle.dumps(command)
sock.sendto(command, (UDP_IP, UDP_PORT))
print(upcommand)
# Intializes everything
def start():
rospy.init_node('UdoSendToCarmaker')
rospy.Subscriber("/Ackermann/command/joy", AckermannDriveStamped, VehCommandCallback)
rospy.spin()
if __name__ == '__main__':
start()
sock.close()