Skip to content

Commit 3f3a5b3

Browse files
[SW-2238] Spot mixed api documentation (#632)
## Change Overview Added some guidance on using the mixed level API in the `spot_ros2_control` readme Also did a few AI Institute --> RAI Institute name changes ## Testing Done Please create a checklist of tests you plan to do and check off the ones that have been completed successfully. Ensure that ROS 2 tests use `domain_coordinator` to prevent port conflicts. Further guidance for testing can be found on the [ros utilities wiki](https://github.com/bdaiinstitute/ros_utilities/wiki/Testing-guidelines).
1 parent cc783b9 commit 3f3a5b3

2 files changed

Lines changed: 58 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The following packages are used to enable joint level control of Spot via ROS 2
9999
* [`spot_controllers`](spot_controllers): Holds some simple forwarding controller plugins useful for sending commands.
100100
101101
This package also pulls in the following packages as submodules:
102-
* [`ros_utilities`](https://github.com/bdaiinstitute/ros_utilities): The AI Institute's convenience wrappers around ROS 2.
102+
* [`ros_utilities`](https://github.com/bdaiinstitute/ros_utilities): The RAI Institute's convenience wrappers around ROS 2.
103103
* [`spot_wrapper`](https://github.com/bdaiinstitute/spot_wrapper): A Python wrapper around the Spot SDK, shared as a common entry point with Spot's ROS 1 repo.
104104
* [`spot_description`](https://github.com/bdaiinstitute/spot_description): contains the URDF of Spot and some simple launchfiles for visualization.
105105
@@ -171,7 +171,7 @@ pre-commit run --all-files
171171

172172
## Contributors
173173

174-
This project is a collaboration between the [Mobile Autonomous Systems & Cognitive Robotics Institute](https://maskor.fh-aachen.de/en/) (MASKOR) at [FH Aachen](https://www.fh-aachen.de/en/) and [The AI Institute](https://theaiinstitute.com/).
174+
This project is a collaboration between the [Mobile Autonomous Systems & Cognitive Robotics Institute](https://maskor.fh-aachen.de/en/) (MASKOR) at [FH Aachen](https://www.fh-aachen.de/en/) and the [RAI Institute](https://rai-inst.com/).
175175

176176
MASKOR contributors:
177177

@@ -181,7 +181,7 @@ MASKOR contributors:
181181
* Stefan Schiffer
182182
* Alexander Ferrein
183183

184-
AI Institute contributors:
184+
RAI Institute contributors:
185185

186186
* Jenny Barry
187187
* Daniel Gonzalez

spot_ros2_control/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,58 @@ This demo will repeatedly open and close the gripper, and after each motion, wil
115115
* `robot_controller`: This is the name of the robot controller that will be started when the launchfile is called. The default is the simple forward position controller. The name must match a controller in the `controllers_config` file.
116116
* `launch_rviz`: If you do not want rviz to be launched, add the argument `launch_rviz:=False`.
117117
* `auto_start`: If you do not want hardware interfaces and controllers to be activated on launch, add the argument `auto_start:=False`.
118+
119+
## Mixed Level API
120+
121+
It is possible to use both the joint level control and traditional high level control (as used by `spot_driver`). To do this in your script, you can still use the `spot_driver` services as usual such as the `claim`, `power_on`, `stand`, etc. services. To activate the joint level control activate the hardware interface, load and configure the controller(s), and activate the controller(s) using the corresponding services from `controller_manager_msgs`. We have provided forward joint and forward state controllers as examples in [`spot_controllers`](https://github.com/bdaiinstitute/spot_ros2/tree/main/spot_controllers) but other controllers can also be used. For safe and clean shutdown, remember to also deactivate and unload the controller(s) and deactivate the hardware interface at the end.
122+
123+
```python
124+
from controller_manager_msgs.srv import (
125+
ConfigureController,
126+
LoadController,
127+
SetHardwareComponentState,
128+
SwitchController,
129+
UnloadController,
130+
ListParameters,
131+
GetParameters,
132+
)
133+
```
134+
135+
More documentation can be found about these services [here](https://docs.ros.org/en/ros2_packages/humble/api/controller_manager_msgs/__service_definitions.html).
136+
137+
A subscriber can fetch the joint states and any other sensor/state broadcasted information, and you can use a publisher to update the commanded setpoints to send to the robot.
138+
139+
```python
140+
from sensor_msgs.msg import JointState
141+
142+
self._joint_states_subscription = self.node.create_subscription(JointState, self.robot_name + "/low_level/joint_states", 1)
143+
self._joint_position_command_publisher = self.node.create_publisher(Float64MultiArray, self.robot_name + "/forward_position_controller/commands", 1)
144+
self._joint_configuration = [ """Ordered list of joints"""] # Can be accessed through controller_manager_msgs services ListParameters and GetParameters
145+
146+
tf_prefix = self.robot_name
147+
# Get initial joint positions
148+
current_joint_states = unwrap_future(self._joint_states_subscription.latest_update, timeout_sec=5.0)
149+
initial_joint_positions = dict(
150+
zip(
151+
map(lambda name: name.removeprefix(tf_prefix), current_joint_states.name),
152+
current_joint_states.position,
153+
strict=True,
154+
)
155+
)
156+
157+
# Update joint setpoints
158+
joint_setpoints = {
159+
name: ( """values""" )
160+
for name in initial_joint_positions
161+
}
162+
# Convert into a Float64MultiArray compatible message
163+
data = list(joint_setpoints)
164+
for i, joint in enumerate(joints):
165+
if joint in joint_setpoints:
166+
data[i] = joint_setpoints[joint]
167+
# Send joint commands to command stream publisher
168+
self._joint_position_command_publisher.publish(Float64MultiArray(data=data))
169+
```
170+
171+
> [!IMPORTANT]
172+
> Before running your script, be sure to launch the driver with an additional `controllable` argument to start the driver in full controllable mode.

0 commit comments

Comments
 (0)