Repository navigation
Expand file tree
/
Copy pathteleplot_subscriber.py
More file actions
executable file
·76 lines (58 loc) · 2.36 KB
/
Copy pathteleplot_subscriber.py
File metadata and controls
executable file
·76 lines (58 loc) · 2.36 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
from __future__ import division, print_function
import rospy
from geometry_msgs.msg import Twist
from husky_msgs.msg import HuskyStatus
from nav_msgs.msg import Odometry
from rosgraph_msgs.msg import Clock
from sensor_msgs.msg import Imu, JointState, NavSatFix
import utils as u
from utils import PlotMode
class HuskySubscriber:
"""Process data from a rosbag and send it to Teleplot
This example was developed with the rosbags from the Enav Planetary Dataset
"""
def cmd_vel_cback(self, msg):
"""Commanded velocities of the Husky rover base"""
time = u.rostime_to_msecs(rospy.Time.now())
linear = msg.linear.x
angular = msg.angular.z
u.send_telemetry("lin_cmd", time, linear)
u.send_telemetry("ang_cmd", time, angular)
def gps_cback(self, msg):
"""GPS data"""
time = u.rostime_to_msecs(msg.header.stamp)
lat = msg.latitude
long = msg.longitude
alt = msg.altitude
u.send_telemetry("gps", lat, long, mode=PlotMode.XY)
u.send_telemetry("altitude", time, alt)
def odom_cback(self, msg):
"""Odometry data computed from Husky wheel encoders"""
time = u.rostime_to_msecs(msg.header.stamp)
linear = msg.twist.twist.linear.x
angular = msg.twist.twist.angular.z
u.send_telemetry("lin_odom", time, linear)
u.send_telemetry("ang_odom", time, angular)
def pose_cback(self, msg):
"""Pose estimates from VINS-Fusion"""
time = u.rostime_to_msecs(msg.header.stamp)
pose = msg.pose.pose
pose_x = pose.position.x
pose_y = pose.position.y
pose_z = pose.position.z
orient = msg.pose.pose.orientation
r, p, y = u.rpy_from_quaternion(orient)
u.send_telemetry("roll", time, r)
u.send_telemetry("pitch", time, p)
u.send_telemetry("yaw", time, y)
def teleplot_subscriber():
rospy.init_node("py_subscriber", anonymous=False)
husky_subs = HuskySubscriber()
rospy.Subscriber("husky_commanded_velocity", Twist, husky_subs.cmd_vel_cback)
rospy.Subscriber("husky_velocity_estimate", Odometry, husky_subs.odom_cback)
rospy.Subscriber("gps", NavSatFix, husky_subs.gps_cback)
rospy.Subscriber("global_odometry_utm", Odometry, husky_subs.pose_cback)
rospy.spin()
if __name__ == "__main__":
teleplot_subscriber()