9. Riproduzione Traiettoria Robot
9.1. Impostare i parametri di registrazione traiettoria TPD
1/**
2* @brief Imposta i parametri di registrazione traiettoria TPD
3* @param [in] type Tipo dati registrazione, 1-Posizione giunti
4* @param [in] name Nome file traiettoria
5* @param [in] period_ms Periodo campionamento dati, valore fisso 2ms o 4ms o 8ms
6* @param [in] di_choose Selezione DI, bit0~bit7 corrisponde a control box DI0~DI7, bit8~bit9 corrisponde a terminale DI0~DI1, 0-Non selezionato, 1-Selezionato
7* @param [in] do_choose Selezione DO, bit0~bit7 corrisponde a control box DO0~DO7, bit8~bit9 corrisponde a terminale DO0~DO1, 0-Non selezionato, 1-Selezionato
8* @return Codice di errore
9*/
10errno_t SetTPDParam(int type, char name[30], int period_ms, uint16_t di_choose, uint16_t do_choose);
9.2. Iniziare la registrazione traiettoria TPD
1/**
2* @brief Inizia la registrazione traiettoria TPD
3* @param [in] type Tipo dati registrazione, 1-Posizione giunti
4* @param [in] name Nome file traiettoria
5* @param [in] period_ms Periodo campionamento dati, valore fisso 2ms o 4ms o 8ms
6* @param [in] di_choose Selezione DI, bit0~bit7 corrisponde a control box DI0~DI7, bit8~bit9 corrisponde a terminale DI0~DI1, 0-Non selezionato, 1-Selezionato
7* @param [in] do_choose Selezione DO, bit0~bit7 corrisponde a control box DO0~DO7, bit8~bit9 corrisponde a terminale DO0~DO1, 0-Non selezionato, 1-Selezionato
8* @return Codice di errore
9*/
10errno_t SetTPDStart(int type, char name[30], int period_ms, uint16_t di_choose, uint16_t do_choose);
9.3. Fermare la registrazione traiettoria TPD
1/**
2* @brief Ferma la registrazione traiettoria TPD
3* @return Codice di errore
4*/
5errno_t SetWebTPDStop();
9.4. Eliminare la registrazione traiettoria TPD
1/**
2* @brief Elimina la registrazione traiettoria TPD
3* @param [in] name Nome file traiettoria
4* @return Codice di errore
5*/
6errno_t SetTPDDelete(char name[30]);
9.5. Precaricamento traiettoria TPD
1/**
2* @brief Precaricamento traiettoria TPD
3* @param [in] name Nome file traiettoria
4* @return Codice di errore
5*/
6errno_t LoadTPD(char name[30]);
9.6. Riproduzione traiettoria TPD
1/**
2* @brief Riproduzione traiettoria TPD
3* @param [in] name Nome file traiettoria
4* @param [in] blend 0-Non smoothing, 1-Smoothing
5* @param [in] ovl Percentuale scala velocità, intervallo [0~100]
6* @return Codice di errore
7*/
8errno_t MoveTPD(char name[30], uint8_t blend, float ovl);
9.7. Ottenere la posa iniziale TPD
1/**
2 * @brief Ottiene la posa iniziale TPD
3 * @param [in] name Nome file TPD, non necessita estensione file
4 * @return Codice di errore
5 */
6errno_t GetTPDStartPose(char name[30], DescPose *desc_pose);
9.8. Spostarsi al Punto di Inizio della Registrazione della Traiettoria TPD
1/**
2* @brief Spostarsi al punto di inizio della registrazione della traiettoria TPD
3* @param [in] name Nome del file di traiettoria
4* @param [in] moveType Tipo di movimento; 0-PTP; 1-LIN
5* @param [in] ovl Percentuale di scala della velocità, intervallo [0~100]
6* @return Codice di errore
7*/
8errno_t MoveToTPDStart(char name[30], uint8_t moveType, float ovl);
9.9. Esempio di Codice per la Registrazione della Traiettoria TPD del Robot
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. Esempio di codice per registrazione traiettoria TPD robot
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. Pre-elaborazione traiettoria
1/**
2 * @brief Pre-elaborazione traiettoria
3 * @param [in] name Nome file traiettoria
4 * @param [in] ovl Percentuale scala velocità, intervallo [0~100]
5 * @param [in] opt 1-Punto di controllo, predefinito 1
6 * @return Codice di errore
7 */
8errno_t LoadTrajectoryJ(char name[30], float ovl, int opt);
9.12. Riproduzione traiettoria
1/**
2 * @brief Riproduzione traiettoria
3 * @return Codice di errore
4 */
5errno_t MoveTrajectoryJ();
9.13. Ottenere la posa iniziale della traiettoria
1/**
2 * @brief Ottiene la posa iniziale della traiettoria
3 * @param [in] name Nome file traiettoria
4 * @return Codice di errore
5 */
6errno_t GetTrajectoryStartPose(char name[30], DescPose *desc_pose);
9.14. Ottenere il numero di punti della traiettoria
1/**
2 * @brief Ottiene il numero di punti della traiettoria
3 * @return Codice di errore
4 */
5errno_t GetTrajectoryPointNum(int *pnum);
9.15. Impostare la Velocità Durante l’Esecuzione della Traiettoria
1/**
2* @brief Impostare la velocità durante l'esecuzione della traiettoria
3* @param [in] ovl Percentuale di velocità [0-100.0]
4* @param [in] mode Modalità; 0-modalità di riduzione della velocità; 1-commutazione diretta
5* @return Codice di errore
6*/
7errno_t SetTrajectoryJSpeed(float ovl, int mode = 0);
9.16. Esempio di Codice per Impostare la Velocità del Robot Durante l’Esecuzione della Traiettoria
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. Impostare forza e coppia durante la riproduzione della traiettoria
1/**
2 * @brief Imposta forza e coppia durante la riproduzione della traiettoria
3 * @param [in] ft Forza e coppia in tre direzioni, unità N e Nm
4 * @return Codice di errore
5 */
6errno_t SetTrajectoryJForceTorque(ForceTorque *ft);
9.18. Impostare la forza lungo la direzione x durante la riproduzione della traiettoria
1/**
2 * @brief Imposta la forza lungo la direzione x durante la riproduzione della traiettoria
3 * @param [in] fx Forza lungo direzione x, unità N
4 * @return Codice di errore
5 */
6errno_t SetTrajectoryJForceFx(double fx);
9.19. Impostare la forza lungo la direzione y durante la riproduzione della traiettoria
1/**
2 * @brief Imposta la forza lungo la direzione y durante la riproduzione della traiettoria
3 * @param [in] fy Forza lungo direzione y, unità N
4 * @return Codice di errore
5 */
6errno_t SetTrajectoryJForceFy(double fy);
9.20. Impostare la forza lungo la direzione z durante la riproduzione della traiettoria
1/**
2 * @brief Imposta la forza lungo la direzione z durante la riproduzione della traiettoria
3 * @param [in] fz Forza lungo direzione x, unità N
4 * @return Codice di errore
5 */
6errno_t SetTrajectoryJForceFz(double fz);
9.21. Impostare la coppia attorno all’asse x durante la riproduzione della traiettoria
1/**
2 * @brief Imposta la coppia attorno all'asse x durante la riproduzione della traiettoria
3 * @param [in] tx Coppia attorno asse x, unità Nm
4 * @return Codice di errore
5 */
6errno_t SetTrajectoryJTorqueTx(double tx);
9.22. Impostare la coppia attorno all’asse y durante la riproduzione della traiettoria
1/**
2 * @brief Imposta la coppia attorno all'asse y durante la riproduzione della traiettoria
3 * @param [in] ty Coppia attorno asse y, unità Nm
4 * @return Codice di errore
5 */
6errno_t SetTrajectoryJTorqueTy(double ty);
9.23. Impostare la coppia attorno all’asse z durante la riproduzione della traiettoria
1/**
2 * @brief Imposta la coppia attorno all'asse z durante la riproduzione della traiettoria
3 * @param [in] tz Coppia attorno asse z, unità Nm
4 * @return Codice di errore
5 */
6errno_t SetTrajectoryJTorqueTz(double tz);
9.24. Caricare file traiettoria J
Nuovo nella versione V3.7.7.
1/**
2 * @brief Carica file traiettoria J
3 * @param [in] filePath Nome percorso completo file traiettoria da caricare C://test/testJ.txt
4 * @return Codice di errore
5 */
6errno_t TrajectoryJUpLoad(const std::string& filePath);
9.25. Eliminare file traiettoria J
Nuovo nella versione V3.7.7.
1/**
2 * @brief Elimina file traiettoria J
3 * @param [in] fileName Nome file testJ.txt
4 * @return Codice di errore
5 */
6errno_t TrajectoryJDelete(const std::string& fileName);
9.26. Esempio di codice per riproduzione file traiettoria J robot
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. Pre-elaborazione traiettoria (traiettoria lookahead)
1/**
2 * @brief Pre-elaborazione traiettoria (traiettoria lookahead)
3 * @param [in] name Nome file traiettoria
4 * @param [in] mode Modalità campionamento, 0-Non campionare; 1-Campionamento a intervalli dati uguali; 2-Campionamento con limite errore uguale
5 * @param [in] errorLim Limite errore, efficace quando si usa interpolazione lineare
6 * @param [in] type Metodo smoothing, 0-Smoothing Bezier
7 * @param [in] precision Precisione smoothing, efficace quando si usa smoothing Bezier
8 * @param [in] vamx Velocità massima impostata, mm/s
9 * @param [in] amax Accelerazione massima impostata, mm/s2
10 * @param [in] jmax Jerk massimo impostato, mm/s3
11 * @param [in] flag Interruttore lookahead velocità costante 0-Non attivare; 1-Attivare
12 * @return Codice di errore
13 */
14errno_t LoadTrajectoryLA(char name[30], int mode, double errorLim, int type, double precision, double vamx, double amax, double jmax, int flag = 0);
9.28. Riproduzione traiettoria (traiettoria lookahead)
1/**
2* @brief Riproduzione traiettoria (traiettoria lookahead)
3* @return Codice di errore
4*/
5errno_t MoveTrajectoryLA();
9.29. Esempio di codice per riproduzione traiettoria (traiettoria lookahead)
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}