-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathrobot.py
More file actions
54 lines (41 loc) · 1.61 KB
/
robot.py
File metadata and controls
54 lines (41 loc) · 1.61 KB
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
import time
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import LaserScan
from nav_msgs.msg import Odometry
from geometry_msgs.msg import Twist
from rclpy.qos import QoSProfile, QoSReliabilityPolicy
class R2D2(Node):
def __init__(self):
super().__init__('R2D2')
qos_profile = QoSProfile(depth=10, reliability = QoSReliabilityPolicy.BEST_EFFORT)
self.laser = None
self.create_subscription(LaserScan, '/scan', self.listener_callback_laser, qos_profile)
self.pose = None
self.create_subscription(Odometry, '/odom', self.listener_callback_odom, qos_profile)
self.pub_cmd_vel = self.create_publisher(Twist, '/cmd_vel', 10)
def wait(self, max_seconds):
start = time.time()
count = 0
while count < max_seconds:
count = time.time() - start
rclpy.spin_once(self)
def listener_callback_laser(self, msg):
self.laser = msg.ranges
# self.get_logger().info(str(self.ranges))
def listener_callback_odom(self, msg):
self.pose = msg.pose.pose
# self.get_logger().info(str(self.pose))
def navigation(self):
try:
rclpy.spin_once(self)
self.navigation_start()
while(rclpy.ok):
rclpy.spin_once(self)
self.navigation_update()
except (KeyboardInterrupt):
pass
def navigation_start(self):
self.get_logger().info("Inicialize seu código aqui!")
def navigation_update(self):
self.get_logger().info("Aqui acontece o loop principal do seu código!")