Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added position_cmd example (used for Fresh) code and explanation to readme #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions examples/python/formant_module/agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,17 @@ Examples:

## Handling commands

Use the `register_command_request_callback` and `send_command_response` methods to handle commands sent from the Formant application on your device. Refer to the examples for usage.
Use the `register_command_request_callback` and `send_command_response` methods to handle commands sent from the Formant application on your device. Refer to the examples for further usage.

Examples:

- [Handling commands](./handle_commands.py)
- [Handling commands](./handle_commands.py) : Outlines how to use the specific command type "get_file", which is a built-in command in the Formant UI.
- [Create PoseStamped msg from commands](./position_cmd.py): Outlines the basic idea of how to receive a command from the Formant UI and convert this command into a PoseStamped position for the robot. The code accepts a command with parameters (x,y,theta) from the Formant platform, unpacks the parameters to create a PoseStamped message which prints in the agent logs. To set up a command, go to Settings > Commands > Add Command. The script looks for "send_to_position" string from the command (as shown in the second screenshot below) and uses the parameters to accept x,y and theta.

<img src="./images/create_command.png" width="1100" height="750" class="center"/>
<img src="./images/configure_command.png" width="1100" height="750" class="center"/>



## Reading application configuration

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions examples/python/formant_module/agent/position_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import time
from geometry_msgs.msg import PoseStamped
from scipy.spatial.transform import Rotation

from formant.sdk.agent.v1 import Client as FormantClient


class FormantPositionCommander:
def __init__(self):
self._fclient = FormantClient(ignore_unavailable=True, ignore_throttled=True)
self._setup_position_command_handler()

def _setup_position_command_handler(self):
self._fclient.register_command_request_callback(
self._send_pose, command_filter=["send_to_position"]
)

def _send_pose(self, request):
print("Parameters sent from command: %s" % request.text)
try:
position_data = request.text.split(",")
x_pos = float(position_data[0])
y_pos = float(position_data[1])
theta = float(position_data[2])
goal_position = PoseStamped()
goal_position.pose.position.x = float(position_data[0])
goal_position.pose.position.y = float(position_data[1])
rot = Rotation.from_euler(
"xyz", [0, 0, float(position_data[2])], degrees=True
)
rot_quat = rot.as_quat()
goal_position.pose.orientation.x = rot_quat[0]
goal_position.pose.orientation.y = rot_quat[1]
goal_position.pose.orientation.z = rot_quat[2]
goal_position.pose.orientation.w = rot_quat[3]
print("Goal position: %s" % goal_position)
except Exception as e:
print(
"Ensure you send command with x, y, and theta as comma separated values."
)
print("Data sent: %s" % request.text)


if __name__ == "__main__":
FPC = FormantPositionCommander()
while True:
time.sleep(1)
4 changes: 3 additions & 1 deletion examples/python/formant_module/agent/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
formant
formant
scipy
rospy