9. Trajectory recurrence
9.1. Set TPD Trajectory Recording Parameters
1/**
2* @brief Set TPD trajectory recording parameters
3* @param [in] type Recording data type, 1-Joint position
4* @param [in] name Trajectory file name
5* @param [in] period_ms Data sampling period, fixed value 2ms or 4ms or 8ms
6* @param [in] di_choose DI selection, bit0~bit7 correspond to controller DI0~DI7, bit8~bit9 correspond to end DI0~DI1, 0-Not selected, 1-Selected
7* @param [in] do_choose DO selection, bit0~bit7 correspond to controller DO0~DO7, bit8~bit9 correspond to end DO0~DO1, 0-Not selected, 1-Selected
8* @return Error code
9*/
10errno_t SetTPDParam(int type, char name[30], int period_ms, uint16_t di_choose, uint16_t do_choose);
9.2. Start TPD Trajectory Recording
1/**
2* @brief Start TPD trajectory recording
3* @param [in] type Recording data type, 1-Joint position
4* @param [in] name Trajectory file name
5* @param [in] period_ms Data sampling period, fixed value 2ms or 4ms or 8ms
6* @param [in] di_choose DI selection, bit0~bit7 correspond to controller DI0~DI7, bit8~bit9 correspond to end DI0~DI1, 0-Not selected, 1-Selected
7* @param [in] do_choose DO selection, bit0~bit7 correspond to controller DO0~DO7, bit8~bit9 correspond to end DO0~DO1, 0-Not selected, 1-Selected
8* @return Error code
9*/
10errno_t SetTPDStart(int type, char name[30], int period_ms, uint16_t di_choose, uint16_t do_choose);
9.3. Stop TPD Trajectory Recording
1/**
2* @brief Stop TPD trajectory recording
3* @return Error code
4*/
5errno_t SetWebTPDStop();
9.4. Delete TPD Trajectory Recording
1/**
2* @brief Delete TPD trajectory recording
3* @param [in] name Trajectory file name
4* @return Error code
5*/
6errno_t SetTPDDelete(char name[30]);
9.5. TPD Trajectory Preload
1/**
2* @brief TPD trajectory preload
3* @param [in] name Trajectory file name
4* @return Error code
5*/
6errno_t LoadTPD(char name[30]);
9.6. TPD Trajectory Playback
1/**
2* @brief TPD trajectory playback
3* @param [in] name Trajectory file name
4* @param [in] blend 0-No smoothing, 1-Smoothing
5* @param [in] ovl Speed scaling percentage, range [0~100]
6* @return Error code
7*/
8errno_t MoveTPD(char name[30], uint8_t blend, float ovl);
9.7. Get TPD Start Pose
1/**
2 * @brief Get TPD start pose
3 * @param [in] name TPD file name, no file extension needed
4 * @return Error code
5 */
6errno_t GetTPDStartPose(char name[30], DescPose *desc_pose);
9.8. Move to TPD Trajectory Recording Start Point
1/**
2* @brief Move to TPD trajectory recording start point
3* @param [in] name Trajectory file name
4* @param [in] moveType Motion type; 0-PTP; 1-LIN
5* @param [in] ovl Speed scaling percentage, range [0~100]
6* @return Error code
7*/
8errno_t MoveToTPDStart(char name[30], uint8_t moveType, float ovl);
9.9. Robot TPD Trajectory Recording Code Example
1int TestTPD(void)
2{
3ROBOT_STATE_PKG pkg = {};
4FRRobot robot;
5robot.LoggerInit();
6robot.SetLoggerLevel(1);
7int rtn = robot.RPC("192.168.58.2");
8if (rtn != 0)
9{
10 return -1;
11}
12robot.SetReConnectParam(true, 30000, 500);
13int type = 1;
14char name[30] = "tpd2025";
15int period_ms = 4;
16uint16_t di_choose = 0;
17uint16_t do_choose = 0;
18robot.SetTPDParam(type, name, period_ms, di_choose, do_choose);
19robot.Mode(1);
20robot.Sleep(1000);
21robot.DragTeachSwitch(1);
22robot.SetTPDStart(type, name, period_ms, di_choose, do_choose);
23robot.Sleep(3000);
24robot.SetWebTPDStop();
25robot.DragTeachSwitch(0);
26robot.Sleep(1000);
27float ovl = 100.0;
28uint8_t blend = 0;
29DescPose start_pose = {};
30rtn = robot.LoadTPD(name);
31printf("LoadTPD rtn is: %d\n", rtn);
32robot.GetTPDStartPose(name, &start_pose);
33printf("start pose, xyz is: %f %f %f. rpy is: %f %f %f \n", start_pose.tran.x, start_pose.tran.y, start_pose.tran.z, start_pose.rpy.rx, start_pose.rpy.ry, start_pose.rpy.rz);
34rtn = robot.MoveToTPDStart(name, 0, 100);
35printf("MoveToTPDStart rtn is: %d\n", rtn);
36rtn = robot.MoveTPD(name, blend, ovl);
37printf("MoveTPD rtn is: %d\n", rtn);
38std::this_thread::sleep_for(std::chrono::milliseconds(5000));
39robot.SetTPDDelete(name);
40robot.CloseRPC();
41return 0;
42}
9.10. Robot TPD Trajectory Recording Code Example
1int TestTPD(void)
2{
3 ROBOT_STATE_PKG pkg = {};
4 FRRobot robot;
5 robot.LoggerInit();
6 robot.SetLoggerLevel(1);
7 int rtn = robot.RPC("192.168.58.2");
8 if (rtn != 0)
9 {
10 return -1;
11 }
12 robot.SetReConnectParam(true, 30000, 500);
13 int type = 1;
14 char name[30] = "tpd2025";
15 int period_ms = 4;
16 uint16_t di_choose = 0;
17 uint16_t do_choose = 0;
18 robot.SetTPDParam(type, name, period_ms, di_choose, do_choose);
19 robot.Mode(1);
20 robot.Sleep(1000);
21 robot.DragTeachSwitch(1);
22 robot.SetTPDStart(type, name, period_ms, di_choose, do_choose);
23 robot.Sleep(10000);
24 robot.SetWebTPDStop();
25 robot.DragTeachSwitch(0);
26 float ovl = 100.0;
27 uint8_t blend = 0;
28 DescPose start_pose = {};
29 rtn = robot.LoadTPD(name);
30 printf("LoadTPD rtn is: %d\n", rtn);
31 robot.GetTPDStartPose(name, &start_pose);
32 printf("start pose, xyz is: %f %f %f. rpy is: %f %f %f \n", start_pose.tran.x, start_pose.tran.y, start_pose.tran.z, start_pose.rpy.rx, start_pose.rpy.ry, start_pose.rpy.rz);
33 robot.MoveCart(&start_pose, 0, 0, 100, 100, ovl, -1, -1);
34 robot.Sleep(1000);
35 rtn = robot.MoveTPD(name, blend, ovl);
36 printf("MoveTPD rtn is: %d\n", rtn);
37 std::this_thread::sleep_for(std::chrono::milliseconds(5000));
38 robot.SetTPDDelete(name);
39 robot.CloseRPC();
40 return 0;
41}
9.11. Trajectory Preprocessing
1/**
2 * @brief Trajectory preprocessing
3 * @param [in] name Trajectory file name
4 * @param [in] ovl Speed scaling percentage, range [0~100]
5 * @param [in] opt 1-Control point, default is 1
6 * @return Error code
7 */
8errno_t LoadTrajectoryJ(char name[30], float ovl, int opt);
9.12. Trajectory Playback
1/**
2 * @brief Trajectory playback
3 * @return Error code
4 */
5errno_t MoveTrajectoryJ();
9.13. Get Trajectory Start Pose
1/**
2 * @brief Get trajectory start pose
3 * @param [in] name Trajectory file name
4 * @return Error code
5 */
6errno_t GetTrajectoryStartPose(char name[30], DescPose *desc_pose);
9.14. Get Trajectory Point Number
1/**
2 * @brief Get trajectory point number
3 * @return Error code
4 */
5errno_t GetTrajectoryPointNum(int *pnum);
9.15. Set Speed During Trajectory Execution
1/**
2* @brief Set speed during trajectory execution
3* @param [in] ovl Speed percentage [0-100.0]
4* @param [in] mode Mode; 0-speed reduction mode; 1-direct switching
5* @return Error code
6*/
7errno_t SetTrajectoryJSpeed(float ovl, int mode = 0);
9.16. Code Example for Setting Robot Speed During Trajectory Execution
1int TestSetTrajectoryJSpeed()
2{
3 ROBOT_STATE_PKG pkg = {};
4 FRRobot robot;
5 robot.LoggerInit();
6 robot.SetLoggerLevel(1);
7 robot.SetReConnectParam(true, 30000, 500);
8 int rtn = robot.RPC("192.168.58.2");
9 if (rtn != 0)
10 {
11 return -1;
12 }
13
14 rtn = robot.TrajectoryJUpLoad("D://zUP/trajHelix_aima_1.txt");
15 printf("Upload TrajectoryJ A %d\n", rtn);
16 char traj_file_name[90] = "/fruser/traj/trajHelix_aima_1.txt";
17 rtn = robot.LoadTrajectoryJ(traj_file_name, 100, 1);
18 printf("LoadTrajectoryJ %s, rtn is: %d\n", traj_file_name, rtn);
19 DescPose traj_start_pose;
20 memset(&traj_start_pose, 0, sizeof(DescPose));
21 rtn = robot.GetTrajectoryStartPose(traj_file_name, &traj_start_pose);
22 printf("GetTrajectoryStartPose is: %d\n", rtn);
23 printf("desc_pos:%f,%f,%f,%f,%f,%f\n", traj_start_pose.tran.x, traj_start_pose.tran.y, traj_start_pose.tran.z, traj_start_pose.rpy.rx, traj_start_pose.rpy.ry, traj_start_pose.rpy.rz);
24 std::this_thread::sleep_for(std::chrono::seconds(1));
25 robot.SetSpeed(50);
26 robot.MoveCart(&traj_start_pose, 0, 0, 100, 100, 100, -1, -1);
27 int traj_num = 0;
28 rtn = robot.GetTrajectoryPointNum(&traj_num);
29 printf("GetTrajectoryStartPose rtn is: %d, traj num is: %d\n", rtn, traj_num);
30 rtn = robot.MoveTrajectoryJ();
31 printf("MoveTrajectoryJ rtn is: %d\n", rtn);
32 robot.Sleep(1000);
33 robot.GetRobotRealTimeState(&pkg);
34 int trajspeedMode = 1;
35 while (pkg.motion_done == 0)
36 {
37 robot.GetRobotRealTimeState(&pkg);
38 rtn = robot.SetTrajectoryJSpeed(10.0, trajspeedMode);
39 printf("SetTrajectoryJSpeed is: %d\n", rtn);
40 robot.Sleep(1000);
41 rtn = robot.SetTrajectoryJSpeed(80.0, trajspeedMode);
42 printf("SetTrajectoryJSpeed is: %d\n", rtn);
43 robot.Sleep(1000);
44 }
45 robot.CloseRPC();
46 robot.Sleep(1000000);
47 return 0;
48}
9.17. Set Trajectory Running Force and Torque
1/**
2 * @brief Set trajectory running force and torque
3 * @param [in] ft Force and torque in three directions, unit N and Nm
4 * @return Error code
5 */
6errno_t SetTrajectoryJForceTorque(ForceTorque *ft);
9.18. Set Trajectory Running Force in X Direction
1/**
2 * @brief Set trajectory running force in X direction
3 * @param [in] fx Force in X direction, unit N
4 * @return Error code
5 */
6errno_t SetTrajectoryJForceFx(double fx);
9.19. Set Trajectory Running Force in Y Direction
1/**
2 * @brief Set trajectory running force in Y direction
3 * @param [in] fy Force in Y direction, unit N
4 * @return Error code
5 */
6errno_t SetTrajectoryJForceFy(double fy);
9.20. Set Trajectory Running Force in Z Direction
1/**
2 * @brief Set trajectory running force in Z direction
3 * @param [in] fz Force in X direction, unit N
4 * @return Error code
5 */
6errno_t SetTrajectoryJForceFz(double fz);
9.21. Set Trajectory Running Torque Around X Axis
1/**
2 * @brief Set trajectory running torque around X axis
3 * @param [in] tx Torque around X axis, unit Nm
4 * @return Error code
5 */
6errno_t SetTrajectoryJTorqueTx(double tx);
9.22. Set Trajectory Running Torque Around Y Axis
1/**
2 * @brief Set trajectory running torque around Y axis
3 * @param [in] ty Torque around Y axis, unit Nm
4 * @return Error code
5 */
6errno_t SetTrajectoryJTorqueTy(double ty);
9.23. Set Trajectory Running Torque Around Z Axis
1/**
2 * @brief Set trajectory running torque around Z axis
3 * @param [in] tz Torque around Z axis, unit Nm
4 * @return Error code
5 */
6errno_t SetTrajectoryJTorqueTz(double tz);
9.24. Upload Trajectory J File
New in version V3.7.7.
1/**
2 * @brief Upload trajectory J file
3 * @param [in] filePath Full path name of trajectory file to upload C://test/testJ.txt
4 * @return Error code
5 */
6 errno_t TrajectoryJUpLoad(const std::string& filePath);
9.25. Delete Trajectory J File
New in version V3.7.7.
1/**
2 * @brief Delete trajectory J file
3 * @param [in] fileName File name testJ.txt
4 * @return Error code
5 */
6 errno_t TrajectoryJDelete(const std::string& fileName);
9.26. Robot Trajectory J File Playback Code Example
1int TestTraj(void)
2{
3 ROBOT_STATE_PKG pkg = {};
4 FRRobot robot;
5 robot.LoggerInit();
6 robot.SetLoggerLevel(1);
7 int rtn = robot.RPC("192.168.58.2");
8 if (rtn != 0)
9 {
10 return -1;
11 }
12 robot.SetReConnectParam(true, 30000, 500);
13 rtn = robot.TrajectoryJUpLoad("D://zUP/traj1.txt");
14 printf("Upload TrajectoryJ A %d\n", rtn);
15 char traj_file_name[30] = "/fruser/traj/traj1.txt";
16 rtn = robot.LoadTrajectoryJ(traj_file_name, 100, 1);
17 printf("LoadTrajectoryJ %s, rtn is: %d\n", traj_file_name, rtn);
18 DescPose traj_start_pose;
19 memset(&traj_start_pose, 0, sizeof(DescPose));
20 rtn = robot.GetTrajectoryStartPose(traj_file_name, &traj_start_pose);
21 printf("GetTrajectoryStartPose is: %d\n", rtn);
22 printf("desc_pos:%f,%f,%f,%f,%f,%f\n", traj_start_pose.tran.x, traj_start_pose.tran.y, traj_start_pose.tran.z, traj_start_pose.rpy.rx, traj_start_pose.rpy.ry, traj_start_pose.rpy.rz);
23 std::this_thread::sleep_for(std::chrono::seconds(1));
24 robot.SetSpeed(50);
25 robot.MoveCart(&traj_start_pose, 0, 0, 100, 100, 100, -1, -1);
26 int traj_num = 0;
27 rtn = robot.GetTrajectoryPointNum(&traj_num);
28 printf("GetTrajectoryStartPose rtn is: %d, traj num is: %d\n", rtn, traj_num);
29 rtn = robot.SetTrajectoryJSpeed(50.0);
30 printf("SetTrajectoryJSpeed is: %d\n", rtn);
31 ForceTorque traj_force;
32 memset(&traj_force, 0, sizeof(ForceTorque));
33 traj_force.fx = 10;
34 rtn = robot.SetTrajectoryJForceTorque(&traj_force);
35 printf("SetTrajectoryJForceTorque rtn is: %d\n", rtn);
36 rtn = robot.SetTrajectoryJForceFx(10.0);
37 printf("SetTrajectoryJForceFx rtn is: %d\n", rtn);
38 rtn = robot.SetTrajectoryJForceFy(0.0);
39 printf("SetTrajectoryJForceFy rtn is: %d\n", rtn);
40 rtn = robot.SetTrajectoryJForceFz(0.0);
41 printf("SetTrajectoryJForceFz rtn is: %d\n", rtn);
42 rtn = robot.SetTrajectoryJTorqueTx(10.0);
43 printf("SetTrajectoryJTorqueTx rtn is: %d\n", rtn);
44 rtn = robot.SetTrajectoryJTorqueTy(10.0);
45 printf("SetTrajectoryJTorqueTy rtn is: %d\n", rtn);
46 rtn = robot.SetTrajectoryJTorqueTz(10.0);
47 printf("SetTrajectoryJTorqueTz rtn is: %d\n", rtn);
48 rtn = robot.MoveTrajectoryJ();
49 printf("MoveTrajectoryJ rtn is: %d\n", rtn);
50 robot.CloseRPC();
51 return 0;
52}
9.27. Trajectory Preprocessing (Trajectory Lookahead)
1/**
2 * @brief Trajectory preprocessing (Trajectory Lookahead)
3 * @param [in] name Trajectory file name
4 * @param [in] mode Sampling mode, 0-No sampling; 1-Equal data interval sampling; 2-Equal error limit sampling
5 * @param [in] errorLim Error limit, takes effect when using linear fitting
6 * @param [in] type Smoothing method, 0-Bezier smoothing
7 * @param [in] precision Smoothing precision, takes effect when using Bezier smoothing
8 * @param [in] vamx Set maximum speed, mm/s
9 * @param [in] amax Set maximum acceleration, mm/s2
10 * @param [in] jmax Set maximum jerk, mm/s3
11 * @param [in] flag Constant velocity lookahead switch; 0-Disable; 1-Enable
12 * @return Error code
13 */
14 errno_t LoadTrajectoryLA(char name[30], int mode, double errorLim, int type, double precision, double vamx, double amax, double jmax, int flag = 0);
9.28. Trajectory Playback (Trajectory Lookahead)
1/**
2* @brief Trajectory playback (Trajectory Lookahead)
3* @return Error code
4*/
5errno_t MoveTrajectoryLA();
9.29. Trajectory Playback (Trajectory Lookahead) Code Example
1int TestLoadTrajLA(void)
2{
3 ROBOT_STATE_PKG pkg = {};
4 FRRobot robot;
5 robot.LoggerInit();
6 robot.SetLoggerLevel(1);
7 int rtn = robot.RPC("192.168.58.2");
8 if (rtn != 0)
9 {
10 return -1;
11 }
12 robot.SetReConnectParam(true, 30000, 500);
13 rtn = robot.TrajectoryJUpLoad("D://zUP/traj.txt");
14 printf("Upload TrajectoryJ A %d\n", rtn);
15 char traj_file_name[30] = "/fruser/traj/traj.txt";
16 rtn = robot.LoadTrajectoryLA(traj_file_name, 1, 2, 0, 2, 100, 200, 1000);
17 printf("LoadTrajectoryLA %s, rtn is: %d\n", traj_file_name, rtn);
18 DescPose traj_start_pose;
19 memset(&traj_start_pose, 0, sizeof(DescPose));
20 rtn = robot.GetTrajectoryStartPose(traj_file_name, &traj_start_pose);
21 printf("GetTrajectoryStartPose is: %d\n", rtn);
22 printf("desc_pos:%f,%f,%f,%f,%f,%f\n", traj_start_pose.tran.x, traj_start_pose.tran.y, traj_start_pose.tran.z, traj_start_pose.rpy.rx, traj_start_pose.rpy.ry, traj_start_pose.rpy.rz);
23 std::this_thread::sleep_for(std::chrono::seconds(1));
24 robot.SetSpeed(50);
25 robot.MoveCart(&traj_start_pose, 0, 0, 100, 100, 100, -1, -1);
26 rtn = robot.MoveTrajectoryLA();
27 printf("MoveTrajectoryLA rtn is: %d\n", rtn);
28 robot.CloseRPC();
29 return 0;
30}