pub_wirelesscontroller
Control the Unitree Go2 robot via wireless commands by transmitting linear and angular motion parameters, including pitch, yaw, and key inputs, directly to the MCP server for precise execution.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| duration | No | ||
| keys | Yes | ||
| linear_x | Yes | ||
| linear_y | Yes | ||
| pitch | Yes | ||
| yaw | Yes |
Input Schema (JSON Schema)
{
"properties": {
"duration": {
"default": 0,
"title": "Duration",
"type": "number"
},
"keys": {
"title": "Keys",
"type": "integer"
},
"linear_x": {
"title": "Linear X",
"type": "number"
},
"linear_y": {
"title": "Linear Y",
"type": "number"
},
"pitch": {
"title": "Pitch",
"type": "number"
},
"yaw": {
"title": "Yaw",
"type": "number"
}
},
"required": [
"linear_x",
"linear_y",
"yaw",
"pitch",
"keys"
],
"title": "pub_wirelesscontrollerArguments",
"type": "object"
}
Implementation Reference
- server.py:48-57 (handler)MCP tool handler for 'pub_wirelesscontroller'. Converts input velocities to normalized stick values (-1 to 1), publishes the WirelessController ROS2 message, and stops after.@mcp.tool() def pub_wirelesscontroller(linear_x: float, linear_y: float, yaw: float, pitch: float, keys: int, duration: float = 0): lx = convert_velocity_to_wirelesscontroller(linear_y) ly = convert_velocity_to_wirelesscontroller(linear_x) rx = convert_velocity_to_wirelesscontroller(-yaw) ry = convert_velocity_to_wirelesscontroller(pitch) result, msg = wirelesscontroller.publish(lx, ly, rx, ry, keys, duration) wirelesscontroller.stop() return result
- server.py:40-46 (helper)Helper function to clamp velocity to [-3.7, 3.7] and normalize to [-1.0, 1.0] for controller sticks.def convert_velocity_to_wirelesscontroller(velocity: float): if velocity > 3.7: velocity = 3.7 elif velocity < -3.7: velocity = -3.7 # -3.7 ~ 3.7 to -1.0 ~ 1.0 return velocity / 3.7
- msgs/wirelesscontroller.py:5-15 (schema)Class documentation defining the structure and semantics of the WirelessController ROS2 message fields used by the tool.class WirelessController: """ Publishes WirelessController messages using ros2 topic pub via subprocess. Message fields: - float32 lx : left stick x axis (-1 ~ 1) -> robot move left and right - float32 ly : left stick y axis (-1 ~ 1) -> robot move forward and backward - float32 rx : right stick x axis (-1 ~ 1) -> robot rotate left and right - float32 ry : right stick y axis (-1 ~ 1) -> robot rotate up and down - uint16 keys : button state """
- msgs/wirelesscontroller.py:29-40 (helper)Core publishing logic: constructs shell command for 'ros2 topic pub' subprocess to send the message with optional rate and duration.def publish(self, lx: float, ly: float, rx: float, ry: float, keys: int, duration: float = 0) -> tuple[bool, Any]: if self.rate > 0 and duration > 0: t = int(self.rate * duration) rate_opt = f"-r {self.rate} --times {t}" else: rate_opt = "-1" command = ( f"source {self.setup_sh_path} && " f"ros2 topic pub {self.topic} {self.msg_type} " f"'{{lx: {lx}, ly: {ly}, rx: {rx}, ry: {ry}, keys: {keys}}}' {rate_opt}" ) return self.execute(command)