-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoy_remapper.py
executable file
·57 lines (36 loc) · 1.4 KB
/
joy_remapper.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#from matplotlib.backend_bases import LocationEvent
import rclpy
from rclpy.node import Node
import utm
from sensor_msgs.msg import Joy
from std_msgs.msg import Header
class Joy_Publisher(Node):
def __init__(self):
super().__init__('joy_publisher')
self.publisher_ = self.create_publisher(Joy, '/joy_teleop/joy', 10)
timer_period = 0.5 # seconds
# self.timer = self.create_timer(timer_period, self.timer_callback)
self.joy_subscription = self.create_subscription(Joy,'/joy_remapped',self.joy_callback,10)
self.joy_subscription # prevent unused variable warning
def joy_callback(self, data):
#print(data)
msg = Joy()
msg.header.stamp = Node.get_clock(self).now().to_msg()
msg.header.frame_id = "joy"
msg.axes = data.axes
msg.buttons = buttons=[0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0]
self.publisher_.publish(msg)
self.get_logger().info('Publishing: "%s"' % msg)
def main(args=None):
rclpy.init(args=args)
joy_publisher = Joy_Publisher()
rclpy.spin(joy_publisher)
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
joy_publisher.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()