Skip to content

Commit ab2d2d4

Browse files
committed
Merge branch 'develop'
2 parents 623dc29 + 6e7a66c commit ab2d2d4

File tree

8 files changed

+680
-197
lines changed

8 files changed

+680
-197
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
*.sw*
22
*.pyc
3-
4-
debug*

nodes/debug_move_to_pose

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env python
2+
3+
from __future__ import print_function
4+
5+
import numpy as np
6+
import os
7+
import rospy
8+
import tf2_ros
9+
import types
10+
11+
from geometry_msgs.msg import Twist
12+
13+
import sys
14+
15+
sys.path.append(
16+
os.path.join(os.path.dirname(os.path.realpath(__file__)), '../src'))
17+
import robot_callbacks as rc
18+
19+
20+
def __SE2_to_SE3(pose):
21+
return np.matmul(rc.__SE3_from_translation(pose[0, 2], pose[1, 2]),
22+
rc.__SE3_from_yaw(rc.__yaw_from_SE2(pose)))
23+
24+
25+
class DummyController():
26+
27+
class DummyEvent():
28+
29+
def __init__(self):
30+
pass
31+
32+
def is_set(self):
33+
return False
34+
35+
class DummyInstance():
36+
37+
def __init__(self):
38+
pass
39+
40+
def is_collided(self):
41+
return False
42+
43+
def is_dirty(self):
44+
return False
45+
46+
def __init__(self):
47+
self.evt = DummyController.DummyEvent()
48+
self.instance = DummyController.DummyInstance()
49+
50+
self.config = {
51+
'task': {
52+
'name': 'ground_truth'
53+
},
54+
'robot': {
55+
'global_frame': 'map',
56+
'robot_frame': 'base_link'
57+
}
58+
}
59+
self.state = {'initial_pose': 0}
60+
61+
self.tf_buffer = tf2_ros.Buffer()
62+
self._tf_listener = tf2_ros.TransformListener(self.tf_buffer)
63+
64+
65+
if __name__ == '__main__':
66+
rospy.init_node("debug_move_to_pose")
67+
68+
p = rospy.Publisher('/cmd_vel', Twist, queue_size=100)
69+
d = DummyController()
70+
71+
# Wait for tf to exist (there's something really dodgy going on here...)
72+
t = None
73+
while not rospy.is_shutdown() and t is None:
74+
try:
75+
t = d.tf_buffer.lookup_transform('map', 'base_link',
76+
rospy.Time.now(),
77+
rospy.Duration(1.0))
78+
except Exception as e:
79+
pass
80+
81+
while not rospy.is_shutdown():
82+
c = rc.__SE3_to_SE2(rc._current_pose(d))
83+
84+
# Get goal from terminal
85+
goal_xyt = None
86+
while goal_xyt is None:
87+
print("Relative goal (format: x,y,th): ", end='')
88+
g = raw_input().split(',')
89+
if len(g) == 3:
90+
goal_xyt = []
91+
for x in g:
92+
try:
93+
goal_xyt.append(float(x))
94+
except:
95+
goal_xyt = None
96+
break
97+
goal_rel = rc.__SE3_to_SE2(
98+
np.matmul(rc.__SE3_from_translation(goal_xyt[0], goal_xyt[1]),
99+
rc.__SE3_from_yaw(goal_xyt[2])))
100+
goal_abs = np.matmul(c, goal_rel)
101+
102+
# Print some information about the goal
103+
ct = rc.__SE2_to_xyt(c)
104+
grt = rc.__SE2_to_xyt(goal_rel)
105+
gat = rc.__SE2_to_xyt(goal_abs)
106+
print(
107+
"Going from:\t(%f,%f,%f)\n\tto\t(%f,%f,%f)\n\tdelta\t(%f,%f,%f)" %
108+
(ct[0], ct[1], ct[2], gat[0], gat[1], gat[2], grt[0], grt[1],
109+
grt[2]))
110+
111+
# Try and move to the goal
112+
rc._move_to_pose(__SE2_to_SE3(goal_abs), p, d)

nodes/noisify_odom

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env python
2+
#
3+
# This node takes a ground truth pose publishing system and converts it to the
4+
# noisy "odom -> base_link" + "map -> odom" corrections when localisation
5+
# approach typical in robotics.
6+
#
7+
# We assume that "map -> odom" is not currently defined, but is instead
8+
# provided by the "start_pose" param. The provided "odom -> base_link" is then
9+
# pulled from the odometry on "in_topic_odom".
10+
#
11+
# The "map -> base_link" transform is left unchanged, but it now consists of a
12+
# noisy "odom -> base_link" link plus ground truth "map -> odom" localisation
13+
# link.
14+
#
15+
# Noise model is basic zero-mean Gaussian noise on velocity, but scaled by the
16+
# velocity. This leads to desirable results like 0 velocity having no noise /
17+
# drift, and is tolerable within our velocity limits. May look at this making
18+
# something more mature in the future. Current:
19+
# Linear vel noise = N(0, linear_vel * noise_linear)
20+
# Angular vel noise = N(0, angular_vel * noise_angular)
21+
22+
import benchbot_spatial as sp
23+
import numpy as np
24+
import rospy
25+
import threading
26+
import tf2_ros
27+
import transforms3d as t3
28+
from geometry_msgs.msg import (Point, Pose, Quaternion, Transform,
29+
TransformStamped, Twist, Vector3)
30+
from nav_msgs.msg import Odometry
31+
from std_msgs.msg import String
32+
33+
34+
def _noisy(std_dev):
35+
return std_dev * np.random.randn()
36+
37+
38+
def _SE3_to_pose_msg(pose):
39+
return Pose(
40+
position=Point(*pose[0:3, 3]),
41+
orientation=Quaternion(
42+
*np.roll(t3.quaternions.mat2quat(pose[0:3, 0:3]), -1)),
43+
)
44+
45+
46+
def _SE3_to_tf_msg(pose):
47+
return Transform(
48+
translation=Vector3(*pose[0:3, 3]),
49+
rotation=Quaternion(*np.roll(t3.quaternions.mat2quat(pose[0:3,
50+
0:3]), -1)),
51+
)
52+
53+
54+
class PoseNoisifier(object):
55+
56+
def __init__(self):
57+
self.in_topic_odom = rospy.get_param("in_topic_odom", "/odom_raw")
58+
self.in_topic_start_pose = rospy.get_param("in_topic_start_pose",
59+
"/odom_start_pose")
60+
self.in_topic_vel = rospy.get_param("in_topic_vel", "/cmd_vel")
61+
62+
self.out_topic_odom = rospy.get_param("out_topic_odom", "/odom")
63+
self.out_frame_map = rospy.get_param("out_frame_map", "map")
64+
self.out_frame_odom = rospy.get_param("out_frame_odom", "odom")
65+
self.out_frame_robot = rospy.get_param("out_frame_robot", "base_link")
66+
67+
self.noise_angular = rospy.get_param("noise_angular", 0.1)
68+
self.noise_linear = rospy.get_param("noise_linear", 0.1)
69+
70+
self._lock = threading.Lock()
71+
72+
self._start_pose = None
73+
74+
self._accumulated_error = np.eye(4)
75+
self._last_vel = Twist()
76+
77+
self._tf = tf2_ros.TransformBroadcaster()
78+
79+
self._pub_odom = rospy.Publisher(self.out_topic_odom,
80+
Odometry,
81+
queue_size=1)
82+
self._sub_odom = rospy.Subscriber(self.in_topic_odom, Odometry,
83+
self.pub)
84+
self._sub_start_pose = rospy.Subscriber(self.in_topic_start_pose,
85+
String, self.update_start_pose)
86+
self._sub_vel = rospy.Subscriber(self.in_topic_vel, Twist,
87+
self.update_vel)
88+
89+
def pub(self, odom_msg):
90+
with self._lock:
91+
# Bail if we don't have valid data to work with
92+
if self._start_pose is None:
93+
return
94+
95+
# Translate our clean odom into a noisy odom
96+
noisy_odom = np.matmul(self._accumulated_error,
97+
sp.pose_msg_to_SE3(odom_msg.pose))
98+
99+
# Figure out "localisation" transform from map to odom frame
100+
localisation = np.matmul(self._start_pose,
101+
np.linalg.inv(self._accumulated_error))
102+
103+
# Publish our messages
104+
o = Odometry()
105+
o.header.stamp = odom_msg.header.stamp
106+
o.header.frame_id = self.out_frame_odom
107+
o.child_frame_id = self.out_frame_robot
108+
o.pose.pose = _SE3_to_pose_msg(noisy_odom)
109+
o.pose.covariance = odom_msg.pose.covariance
110+
o.twist = self._last_vel
111+
self._pub_odom.publish(o)
112+
113+
t = TransformStamped()
114+
t.header.stamp = odom_msg.header.stamp
115+
t.header.frame_id = self.out_frame_map
116+
t.child_frame_id = self.out_frame_odom
117+
t.transform = _SE3_to_tf_msg(localisation)
118+
self._tf.sendTransform(t)
119+
120+
t = TransformStamped()
121+
t.header.stamp = odom_msg.header.stamp
122+
t.header.frame_id = self.out_frame_odom
123+
t.child_frame_id = self.out_frame_robot
124+
t.transform = _SE3_to_tf_msg(noisy_odom)
125+
self._tf.sendTransform(t)
126+
127+
# Update accumulated noise
128+
self._accumulated_error = np.matmul(
129+
self._accumulated_error,
130+
np.matmul(
131+
sp.SE3_from_translation(self._last_vel.linear.x *
132+
_noisy(self.noise_linear)),
133+
sp.SE3_from_yaw(self._last_vel.angular.z *
134+
_noisy(self.noise_angular))),
135+
)
136+
137+
def update_start_pose(self, start_pose_msg):
138+
with self._lock:
139+
self._accumulated_error = np.eye(4)
140+
self._start_pose = sp.wxyzXYZ_to_SE3(*np.array([
141+
float(x.strip()) for x in start_pose_msg.data.replace(
142+
'[', '').replace(']', '').split(',')
143+
]))
144+
145+
def update_vel(self, vel_msg):
146+
with self._lock:
147+
self._last_vel = vel_msg
148+
149+
150+
if __name__ == '__main__':
151+
rospy.init_node("noisify_odom")
152+
153+
pn = PoseNoisifier()
154+
155+
rospy.spin()

scripts/pull_config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
# Pulls an existing config into currently running controller
4+
curl -s benchbot_supervisor:10000/config/ | \
5+
curl -d @- -H 'Content-Type: application/json' benchbot_robot:10000/configure

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from distutils.core import setup
44
from catkin_pkg.python_setup import generate_distutils_setup
55

6-
d = generate_distutils_setup(packages=['benchbot_robot_controller'],
7-
package_dir={'': 'src'})
6+
d = generate_distutils_setup(
7+
packages=['benchbot_robot_controller', 'benchbot_spatial'],
8+
package_dir={'': 'src'})
89

910
setup(**d)

0 commit comments

Comments
 (0)