generated from chicagoedt/templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Navigation_node_v2.py
81 lines (59 loc) · 2.18 KB
/
Navigation_node_v2.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from robot_interfaces.srv import ActCommand, Commands
from robot_interfaces.msg import MotorsVel, LinActPos, GuiGraphInput
from std_msgs.msg import UInt8
from sensor_msgs.msg import Joy
import numpy as np
import time
class NavigationNode(Node):
def __init__(self):
super().__init__("Navigation_node")
# Establish publishers and listeners
self.publisher_command = self.create_publisher(Bool,'digging_command',10)
self.command_pub_ = self.create_publisher(MotorsVel,'motor_vel',self.motor_callback,10)
self.navigation_cmd_sub = self.create_subscription(UInt8,'nav_command',self.navigation,10)
self.get_logger().info("Navigation algorithms node activated")
self.timer_ = self.create_timer(0.1,self.main_algorithm)
self.command = ''
def navigation(self,msg):
cmd = msg.data
if cmd == 0:
self.command = 'stop'
if cmd == 1:
self.command = 'turn_right'
if cmd == 2:
self.command = 'turn_left'
if cmd == 3:
self.command = 'forward'
def main_algorithm(self):
done = Bool()
inprogress = Bool()
command = String()
## Select command to act
# self.command == "restpos" ?
# true ==>
if self.command == "stop":
motors_vel = [0.0,0.0]
self.motor_vel_callback(motors_vel)
elif self.command == "turn_right":
motors_vel = []
self.motor_vel_callback(motors_vel)
elif self.command == "turn_left":
motors_vel = []
self.motor_vel_callback(motors_vel)
elif self.command == "forward":
motors_vel = []
self.motor_vel_callback(motors_vel)
def motor_vel_callback(self,motors_vel):
request_motor = MotorsVel()
request_motor.rl_motor = motors_vel
self.command_pub_.publish(request_motor)
def main(args=None):
rclpy.init(args=args)
node = AutCommandNode()
rclpy.spin(node)
rclpy.shutdown()
if __name__== "__main__":
main()