-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot_using_ros.py
64 lines (57 loc) · 2.18 KB
/
robot_using_ros.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from robot import *
from geometry_msgs.msg import Twist
from nav_msgs.msg import Odometry
class RobotUsingRos(Robot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.controlloer_publisher = None
def __exit__(self, *args):
print("Cleaning up...")
self.stop_event.set()
self.pump_stop_event.set()
GPIO.output(PUMP_CTRL_PIN, 0)
GPIO.cleanup()
if self.controller:
self.stop()
self.controller.terminate()
if self.controlloer_publisher:
self.controlloer_publisher.unregister()
if self.vision_subscriber:
self.vision_subscriber.unregister()
if self.wall_subscriber:
self.wall_subscriber.unregister()
if self.vision_process:
self.vision_process.terminate()
# self.video_capture.release()
# cv.destroyAllWindows()
if self.motion_process:
self.motion_process.terminate()
if self.auditory_process:
self.auditory_process.terminate()
# no need to clean up olfactory
self.server.shutdown()
self.server.server_close()
print("Done.")
def setup_controller(self):
if self.controller is None:
self.controller = subprocess.Popen(("roslaunch", "lingao_bringup", "bringup.launch"))
self.controlPanel.controllerButton.setText("Disconnect")
self.controlPanel.setControlButtonsEnabled(True)
self.controlloer_publisher = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
else:
self.controller.terminate()
self.controller = None
self.controlloer_publisher.unregister()
self.controlloer_publisher = None
self.controlPanel.controllerButton.setText("Connect")
self.controlPanel.setControlButtonsEnabled(False)
def set_speed(self, x, z):
vel_msg = Twist()
vel_msg.linear.x = x
vel_msg.angular.z = z
self.controlloer_publisher.publish(vel_msg)
if __name__ == '__main__':
with RobotUsingRos() as robot:
robot.exec()