Skip to content

Commit 23c7287

Browse files
committed
adding velocityCommand in body.py; also make travel_params configurable
1 parent 877be9c commit 23c7287

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# functions related to moving the robot's arm (including gripper)
2+
import time
3+
import bosdyn.client.lease
4+
from bosdyn.api import arm_command_pb2, geometry_pb2, robot_command_pb2
5+
from bosdyn.client import math_helpers
6+
from bosdyn.client.robot_command import (RobotCommandBuilder, RobotCommandClient,
7+
block_until_arm_arrives, blocking_stand)
8+
from bosdyn.client.frame_helpers import GRAV_ALIGNED_BODY_FRAME_NAME, ODOM_FRAME_NAME, get_a_tform_b
9+
10+
def create_client(conn):
11+
return conn.ensure_client(RobotCommandClient.default_service_name)
12+
13+
def velocityCommand(conn, command_client, v_x, v_y, v_rot,
14+
cmd_duration=0.125, mobility_params=None):
15+
"""
16+
Send a velocity motion command to the robot.
17+
18+
Args:
19+
v_x: Velocity in the X direction in meters
20+
v_y: Velocity in the Y direction in meters
21+
v_rot: Angular velocity around the Z axis in radians
22+
cmd_duration: (optional) Time-to-live for the command in seconds. Default is 125ms (assuming 10Hz command rate).
23+
Returns:
24+
RobotCommandResponse, float (time taken)
25+
"""
26+
if mobility_params is None:
27+
mobility_params = RobotCommandBuilder.mobility_params()
28+
end_time = time.time() + cmd_duration
29+
synchro_velocity_command = RobotCommandBuilder.synchro_velocity_command(
30+
v_x=v_x, v_y=v_y, v_rot=v_rot, params=mobility_params)
31+
32+
with bosdyn.client.lease.LeaseKeepAlive(conn.lease_client, must_acquire=True):
33+
_start_time = time.time()
34+
command_id = command_client.robot_command(
35+
synchro_velocity_command, end_time_secs=end_time,
36+
timesync_endpoint=conn.timesync_endpoint)
37+
end_time = time.time() - _start_time
38+
return command_id, end_time

spot/ros_ws/src/rbd_spot_perception/src/rbd_spot_perception/graphnav.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ def listGraphWaypoints(graphnav_client):
341341
graph, localization_id) # THIS FUNCTION DOES THE PRINTING.
342342

343343

344-
def navigateTo(conn, graphnav_client, goal, sleep=0.5, tolerance=None, speed="medium"):
344+
def navigateTo(conn, graphnav_client, goal, sleep=0.5, tolerance=None,
345+
speed="medium", travel_params=None):
345346
"""
346347
Navigate to a pose in the seed frame (i.e. global pose).
347348
Calls the NavigateToAnchor service. Blocking call until
@@ -363,6 +364,7 @@ def navigateTo(conn, graphnav_client, goal, sleep=0.5, tolerance=None, speed="me
363364
the goal in x, y, z axes. Sets the 'goal_waypoint_rt_seed_ewrt_seed_tolerance'
364365
parameter. Applicable only for seed frame goals.
365366
speed (str): "medium", "slow", "fast", or "default".
367+
travel_params (TravelParams proto): Travel params for navigation. If provided, will override speed.
366368
probably don't need:
367369
+callback: function to be called per cycle+
368370
+callback_args+
@@ -393,15 +395,15 @@ def navigateTo(conn, graphnav_client, goal, sleep=0.5, tolerance=None, speed="me
393395
if tolerance is not None:
394396
goal_waypoint_rt_seed_ewrt_seed_tolerance = Vec3(x=tolerance[0], y=tolerance[1], z=tolerance[2])
395397

396-
travel_params = None
397-
if speed not in {"default", "medium", "slow", "fast"}:
398-
raise ValueError("Invalid speed for navigation:", speed)
399-
if speed == "slow":
400-
travel_params = graph_nav_pb2.TravelParams(velocity_limit=NAV_VELOCITY_LIMITS_SLOW)
401-
elif speed == "medium":
402-
travel_params = graph_nav_pb2.TravelParams(velocity_limit=NAV_VELOCITY_LIMITS_MEDIUM)
403-
elif speed == "fast":
404-
travel_params = graph_nav_pb2.TravelParams(velocity_limit=NAV_VELOCITY_LIMITS_FAST)
398+
if travel_params is None:
399+
if speed not in {"default", "medium", "slow", "fast"}:
400+
raise ValueError("Invalid speed for navigation:", speed)
401+
if speed == "slow":
402+
travel_params = graph_nav_pb2.TravelParams(velocity_limit=NAV_VELOCITY_LIMITS_SLOW)
403+
elif speed == "medium":
404+
travel_params = graph_nav_pb2.TravelParams(velocity_limit=NAV_VELOCITY_LIMITS_MEDIUM)
405+
elif speed == "fast":
406+
travel_params = graph_nav_pb2.TravelParams(velocity_limit=NAV_VELOCITY_LIMITS_FAST)
405407

406408
nav_to_cmd_id = None
407409
is_finished = False

spot/ros_ws/src/rbd_spot_robot/src/rbd_spot_robot/spot_sdk_conn.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ def lease(self):
7373
def clock_skew(self):
7474
return self.robot.time_sync.endpoint.clock_skew
7575

76+
@property
77+
def timesync_endpoint(self):
78+
return self.robot.time_sync.endpoint
79+
7680
def spot_time_to_local(self, spot_timestamp):
7781
"""
7882
Args:

0 commit comments

Comments
 (0)