-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestsquare.py
55 lines (41 loc) · 1.67 KB
/
testsquare.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
from geometry_msgs.msg import Twist
from rclpy.node import Node
from rclpy.qos import QoSProfile
from nav_msgs.msg import Odometry
import rclpy
import numpy as np
class MinimalSubscriber(Node):
def __init__(self):
super().__init__('Minimal_Subscriber')
"""************************************************************
** Initialise variables
************************************************************"""
self.odom = Odometry()
"""************************************************************
** Initialise ROS publishers and subscribers
************************************************************"""
qos = QoSProfile(depth=10)
# Initialise publishers
self.cmd_vel_pub = self.create_publisher(Twist, 'cmd_vel', qos)
self.original_odom = self.create_publisher(Odometry, 'ori_odom', qos)
# Initialise subscribers
self.odom_sub = self.create_subscription(Odometry, 'odom', self.odom_callback, qos)
"""*******************************************************************************
** Callback functions and relevant functions
*******************************************************************************"""
def odom_callback(self, msg):
self.original_odom.publish(msg)
twist = Twist()
for i in range(4):
twist.linear.x = i+1.1
twist.angular.z = -1.1+i
print(twist)
self.cmd_vel_pub.publish(twist)
def main(args=None):
rclpy.init(args=args)
minimal_subscriber = MinimalSubscriber()
rclpy.spin(minimal_subscriber)
minimal_subscriber.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()