This chapter describes the demo package and the code used as a C++ programming example, showing how to program robot scripts (TM Robot Expressions) through the TM ROS driver connection.
demo_send_script:
In this demo code, it shows how to send a Listen node script to control the TM Robot.
The user can use a service named "send_script" to send the script.
"id" → The transaction number expressed in any alphanumeric 1 characters.
"script" → the script that the user wants to send.
"ok" → the correctness of the script.
1 If a non-alphanumeric byte is encountered, a CPERR 04 error is reported. When used as a communication packet response, it is a transaction number and identifies which group of commands to respond.demo_ask_item:
In this demo code, the user can use this service to send TMSVR 2 cmd.
2 For more detailed information, please refer to defined protocol: TM Expression Editor Manual(2.12 rev1.00) (Chapter14.6 TMSVR)demo_ask_sta:
In this demo code, the user can use this service to send TMSTA 3 cmd.
3 For more detailed information, please refer to defined protocol (Chapter11.5 TMSTA)demo_connect_tm:
In this demo code, the user can set the connection type.demo_set_event:
In this demo code, six event types can be selected.
func → TAG, WAIT_TAG, STOP, PAUSE, RESUME and EXIT
arg0 → if func is TAG or WAIT_TAG, arg0 is the tag number
arg1 → if func is TAG or WAIT_TAG, arg1 is timeout in msdemo_set_io:
In this demo code, the user should set the module, type, pin, and state. 4
module → MODULE_CONTROLBOX or MODULE_ENDEFFECTOR
type → TYPE_DIGITAL_IN, TYPE_DIGITAL_OUT, TYPE_INSTANT_DO, TYPE_ANALOG_IN, TYPE_ANALOG_OUT, TYPE_INSTANT_AO
pin → pin number
state → STATE_OFF or STATE_ON value, or other value (if type expressed in a specific control module)
4 For more detailed information, please refer to defined protocol (Chapter10.5 IO)demo_set_positions:
In this demo code, the user should pay attention to the parameter definition of the data format setting 5 and the parameter unit to be operated.
motion_type → PTP_J , PTP_T , LINE_T
positions → motion target position: If expressed in Cartesian coordinate (unit: m), if expressed in joint angles (unit: rad)
velocity → motion velocity: if expressed in Cartesian coordinate (unit: m/s) 6, if expressed in joint velocity (unit: rad/s, and the maximum value is limited to π ) 6
acc_time → time to reach maximum speed (unit: ms)
blend_percentage → blending value: expressed as a percentage (unit: %, and the minimum value of 0 means no blending)
fine_goal → precise position mode: If activated, the amount of error in the final position will converge more, but it will take a few more milliseconds.
5 For more detailed information, please refer to defined protocol (Chapter12 PTP, Line)
6 The unit of the parameters are different, the user can find the conversion in the program of TM ROS driver.demo_write_item:
In this demo code, the user can use this service to send TMSVR 7 cmd.
7 For more detailed information, please refer to defined protocol (Chapter14.3 svr_write())demo_leave_listen_node:
In this demo code, the user can use send_script service sending a script to leave the Listen node.
💡 If the user has sent the demo_leave_listen_node script to leave the Listen node, and you want to run the TM Robot again, please remember that the Listen task project should be resumed to run. You can press the Stop Button on the Robot Stick and then press the Play/Pause Button to resume operation.
- To use this package, make sure your ROS PC is installed correctly.
- The user has successfully configured the network settings of the TM Robot and the user's PC in the same subnet. In other words, users have been able to ping the remote system on the same subnet successfully.
💡 Tip: For example, set the user computer IP address and remote TM Robot to 192.168.10.30 and 192.168.10.2 (Netmask: 255.255.255.0). Users can ping the remote IP address 192.168.10.2, by typing "ping 192.168.10.2".
- The user already knows how to use TMflow 2 programming, especially to configure TM ROS Ethernet Slave "Data Table Setting" and the Listen nodes programming through a flow project. In other words, the user has created and completed the Listen task with the TM ROS setting of a TMflow software process project.
💡 Tip: The user can refer to the chapter introduced in the main text: 3. TM ROS driver usage and installation for quick and easy setup or refer to the Software Manual TMflow for details.
- Remember to press the Play/Pause (►) button on the Robot Stick to start running this Listen task project under auto Mode.
💡 Tip: If under Manual Mode, it requires the trigger of the Enabling Switch function. Therefore, the user needs to press and hold the Enabling Switch button slightly and continuously to press the Play/Pause (►) button to run the operation. The user can select to suspend Enabling Switch on the UI of TMflow ⇒ Configuration ⇒ Safety, and the triggering effect of Enabling Switch will be disabled. For details of the Enabling Switch function, refer to the relevant contents in the Safety Manual or the Software Manual TMflow.
- Type to create a root workspace directory by starting a terminal: For example,
tm2_ws
orcatkin_ws
, then type to change the current directory into the workspace directory path.
mkdir ~/tm2_ws
cd ~/tm2_ws
- Clone the TM driver of the git repository into the current directory by typing
git clone https://github.com/TechmanRobotInc/tm2_ros2.git
- After the download done, rename the download folder
tm2_ros2
(ortm2_ros2-master
) tosrc
by typing
mv tm2_ros2 src
(or right-click on the download folder, select "Rename...")- At the workspace directory to build the download packages and source 'setup.bash' in this workspace to make the workspace visible to ROS.
Note: Do you setsource /opt/ros/foxy/setup.bash
ready? Make sure to obtain the correct setup file according to your workspace hierarchy, and then type the following below to compile.
colcon build
source ./install/setup.bash
- In a new terminal: Source setup.bash in the workspace path, connect to TM Robot with ROS_DOMAIN_ID and type the specific demo node function that the user wants to study for applications. For example: the user select to run demo_set_io, the user can type
source ./install/setup.bash
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export ROS_DOMAIN_ID=<ROS_DOMAIN_ID>
The <ROS_DOMAIN_ID> value of this setting must be the same as the value of TM Flow.
ros2 run demo demo_set_io
⚠️ [CAUTION] Some demos will let the TM Robot move, please be careful.
For example: (select to run demo_set_io)
Assume the domain ID is set to 30 and the embedded TM ROS driver is successfully enabled on Tmflow 2. If the user has successfully built the specific code (tm2_ros2) before, now the user only needs to open a new terminal, and set the path to the TM driver workspace
cd ~/tm2_ws
, then type the following command to run demo_set_io.$ cd <workspace> {workspace}$ source /opt/ros/foxy/setup.bash {workspace}$ export RMW_IMPLEMENTATION=rmw_fastrtps_cpp {workspace}$ export ROS_DOMAIN_ID=30 {workspace}$ source ./install/setup.bash {workspace}$ ros2 run demo demo_set_io
Note: When you have finished, press CTRL + C in all terminal windows to shut everything down.