This example shows you how to connect to the KINOVA® Gen3 7-DoF Ultralightweight Robot arm with with Simulink using Robot Operating System (ROS). This includes ROS message Subscribe and Publish blocks to get feedback from the robot and then send commands to the robot to reach a particular cartesian configuration.
Robotics System Toolbox™
KINOVA® Gen3 Robot
Robotics System Toolbox™ Support Package for Manipulators enables you to control manipulators using MATLAB and Simulink. This support package utilizes ROS packages provided by robot manufacturers to acquire various sensor data, simulate robot models, and control the robot. You can prototype algorithms and perform simulations of these robots using rigid body tree models from Robotics System Toolbox™ or Simscape™ Multibody™ robot models. This support package also allows you to connect with the robot hardware to test and validate your algorithms.
In this example
/my_gen3/base_feedback/ ROS message is used to get current cartesian configuration of KINOVA Gen3 robot. Then
/my_gen3/base/play_cartesian_trajectory custom ROS service is used to send commands to a robot to follow a desired joint configuration.
If you are new to Simulink, watch the Simulink Quick Start.
Perform the initial Setup and Configuration of the support package using Hardware Setup screens and select ROS interface in step 2.
Refer to Connect to the KINOVA Gen3 Robot and Initiate Required ROS Nodes to Control the Robot for information on the communication interface between MATLAB and the robot. Execute the steps to initiate required ROS nodes.
To open the example model, run the following command at MATLAB command prompt:
The model consists of a ROS Subscriber block which is configured for
/my_gen3/joint_states ROS topic. As explained in the Github page of Kinova Robotics, the first part of the ROS topic, 'my_gen3' might be different based on the robot name set during the roslaunch command. From the received message, information about the current cartesian pose is extracted and displayed on various Display blocks. These values can be used as a reference while providing the cartesian setpoint to the robot. Further, user specified cartesian setpoint is given to the Send Desired Pose subsystem.
This subsystem consists of three different blocks. The Blank ROS message block , first from the left, is configured to create a blank message for
kortex_driver/PlayCartesianTrajectoryRequest ROS service request. The MATLAB function block, packCartesianTraj assigns various values such as desired cartesian configuration, type of constraint, and maximum velocity to blank message fields. The call service block is configured for
/my_gen3/base/play_cartesian_trajectory service and for sending commands to robot to reach the desired cartesian configuration.
Note: Ensure that the E-STOP is close to you to stop the movement of robot, as the robot moves according to the specified cartesian setpoint.
After launching required ROS nodes and connecting to the ROS network, click Simulate on the Simulink toolbar and then click Run. The robot will not move from the current position at the start as there is no change in the joint angle offset. The 'Move Robot manual switch is initially connected to a ground, so the Send Desired Pose subsystem will not trigger. Now, change the desired cartesian pose and then change the state of 'Move Robot' manual switch. This triggers the Send Desired Pose subsystem and the robot moves to the desired cartesian configuration.