GDK ROS2 Humble Usage Guide¶
Genie 02 uses a high-performance DDS and does not send ROS2 messages by default. To use ROS2, you need to start GDK's ROS2 forwarding node. When GDK is deployed, it also installs custom ROS messages; once you build GDK's custom messages, you can use ROS2 to receive/send GDK's messages.
Starting the forwarding node to get messages¶
Viewing messages (using the motion control node as an example)¶
Start the controller's ROS forwarding node¶
source ~/.cache/agibot/app/gdk/scripts/ros_env.sh gdk_controller
ros2 launch gdk_controller controller.launch.py
Declare the ROS environment variables¶
Open a new terminal and declare the environment variables in it
View the node's messages¶
ros2 topic list # View all current topics
ros2 topic echo /hal/joint_state # Read the topic data
ros2 topic hz /hal/joint_state # Read the publish rate
Writing a program (using joint control as an example)¶
Include the genie_msg message headers you need¶
Create a subscriber for the /hal/joint_state message to get all of the robot's current joint names, joint angles, speeds, and other information¶
sub_joint_ = this->create_subscription<genie_msgs::msg::JointState>(
"/hal/joint_state",
10,
std::bind(&ControlExampleNode::joint_state_callback, this, std::placeholders::_1)
);
Create a publisher for the /MotionControlService/JointPosition/request message¶
pub_joint_position_ = create_publisher<genie_msgs::msg::JointPositionRequst>("/MotionControlService/JointPosition/request", 10);
Setting the uuid¶
GDK's control commands require a uuid to be set as a unique identifier; you can create a uuid using the method below:
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
inline std::string generate_uuid_boost()
{
boost::uuids::random_generator gen;
return boost::uuids::to_string(gen());
}
Set the control command and publish it to control the corresponding joint¶
genie_msgs::msg::JointPositionRequst request;
request.lifetime = 1.0;
request.joint_names = joint_names_;
request.joint_positions = target_positions;
request.joint_velocities = {velocity_};
request.uuid = generate_uuid_boost();
pub_joint_position_->publish(request);