Skip to content

Commit 623dc29

Browse files
committed
Merge branch 'develop'
2 parents 7b27435 + adbf6a7 commit 623dc29

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/benchbot_robot_controller.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _to_simple_dict(data):
7575

7676
class ControllerInstance(object):
7777

78-
def __init__(self, config_robot, config_env, ros_subs):
78+
def __init__(self, config_robot, config_env, ros_subs, events=None):
7979
self.config_robot = config_robot
8080
self.config_env = config_env
8181

@@ -84,6 +84,7 @@ def __init__(self, config_robot, config_env, ros_subs):
8484
self._cmds = None
8585
self._processes = None
8686
self._log_files = None
87+
self._events = events
8788

8889
def _replace_variables(self, text):
8990
for k, v in VARIABLES.items():
@@ -161,7 +162,8 @@ def start(self):
161162
# Wait until we move into a running state
162163
start_time = time.time()
163164
while not self.is_running():
164-
time.sleep(0.25)
165+
if self._events and self._events.wait(0.25):
166+
return False
165167
if not self.health_check(check_running=False):
166168
return False
167169
elif (time.time() - start_time > TIMEOUT_STARTUP and
@@ -189,9 +191,10 @@ def start_logging(self):
189191
]
190192

191193
def stop(self):
192-
if not self.is_running():
193-
print("Controller Instance is not running. Skipping stop.")
194-
return False
194+
# We could be in the process of starting, so this check is inappropriate
195+
# if not self.is_running():
196+
# print("Controller Instance is not running. Skipping stop.")
197+
# return False
195198

196199
# Stop all of the open processes & logging
197200
for p in self._processes:
@@ -225,7 +228,6 @@ def __init__(self, port=10000, auto_start=True):
225228
self.robot_address = 'http://0.0.0.0:' + str(port)
226229

227230
self._auto_start = auto_start
228-
229231
self.config = None
230232
self.config_valid = False
231233

@@ -236,6 +238,10 @@ def __init__(self, port=10000, auto_start=True):
236238

237239
self.instance = None
238240

241+
self.evt = event.Event()
242+
for s in [signal.SIGINT, signal.SIGQUIT, signal.SIGTERM]:
243+
signal.signal(s, lambda n, frame: self.evt.set())
244+
239245
self.wipe()
240246

241247
@staticmethod
@@ -468,18 +474,14 @@ def __selected_env():
468474
# Configure our server
469475
robot_server = pywsgi.WSGIServer(
470476
re.split('http[s]?://', self.robot_address)[-1], robot_flask)
471-
evt = event.Event()
472-
signal.signal(signal.SIGINT, evt.set)
473-
signal.signal(signal.SIGQUIT, evt.set)
474-
signal.signal(signal.SIGTERM, evt.set)
475477

476478
# Run the server & start the real robot controller
477479
robot_server.start()
478480
print("\nRobot controller is now available @ '%s' ..." %
479481
self.robot_address)
480482
print("Waiting to receive valid config data...")
481483
while not self.config_valid:
482-
if evt.wait(0.1):
484+
if self.evt.wait(0.1):
483485
break
484486

485487
if self._auto_start and self.config_valid:
@@ -491,7 +493,7 @@ def __selected_env():
491493

492494
# Wait until we get an exit signal or crash, then shut down gracefully
493495
while self.instance.health_check():
494-
if evt.wait(0.1):
496+
if self.evt.wait(0.1):
495497
break
496498
print("\nShutting down the real robot ROS stack & exiting ...")
497499
robot_server.stop()
@@ -543,7 +545,8 @@ def start(self):
543545
c['ros']
544546
for c in self.connections.values()
545547
if c['type'] == CONN_ROS_TO_API and c['ros'] != None
546-
])
548+
],
549+
events=self.evt)
547550
self.instance.start()
548551

549552
def stop(self):

src/robot_callbacks.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414

1515
_MOVE_ANGLE_K = 3
1616

17-
_MOVE_POSE_K_RHO = 0.75
17+
_MOVE_POSE_K_RHO = 1
1818
_MOVE_POSE_K_ALPHA = 4
1919
_MOVE_POSE_K_BETA = -1.5
2020

21-
_MOVE_LINEAR_LIMITS = [-0.2, 0.5]
22-
_MOVE_ANGULAR_LIMIT = 0.3
21+
_MOVE_LINEAR_LIMITS = [-0.4, 0.8]
22+
_MOVE_ANGULAR_LIMIT = 0.5
2323

2424

2525
def __quat_from_SE3(pose):
@@ -127,8 +127,9 @@ def _move_to_angle(goal, publisher, controller):
127127
gamma = None
128128
vel_msg = Twist()
129129
hz_rate = rospy.Rate(_MOVE_HZ)
130-
while not controller.instance.is_collided() and (
131-
gamma is None or np.abs(gamma) > _MOVE_TOL_YAW):
130+
while (not controller.evt.is_set() and
131+
not controller.instance.is_collided() and
132+
(gamma is None or np.abs(gamma) > _MOVE_TOL_YAW)):
132133
# Get latest orientation error
133134
current = __SE3_to_SE2(_current_pose(controller))
134135
gamma = __yaw_from_SE2(np.matmul(np.linalg.inv(current), g))
@@ -155,8 +156,9 @@ def _move_to_pose(goal, publisher, controller):
155156
rho = None
156157
vel_msg = Twist()
157158
hz_rate = rospy.Rate(_MOVE_HZ)
158-
while not controller.instance.is_collided() and (rho is None or
159-
rho > _MOVE_TOL_DIST):
159+
while (not controller.evt.is_set() and
160+
not controller.instance.is_collided() and
161+
(rho is None or rho > _MOVE_TOL_DIST)):
160162
# Get latest position error
161163
current = __SE3_to_SE2(_current_pose(controller))
162164
error = np.matmul(np.linalg.inv(current), g)

0 commit comments

Comments
 (0)