Examples and TestApi.cpp (RobotDriver)

main.cpp is a simple example for reading version information. The examples folder contains usage examples for various APIs, burn-in examples, and more.
This document explains the purpose of examples/TestApi.cpp and how each code block maps to RobotArm usage. It applies to MyCobotPro450 with Linux + TCP integration. For environment setup and build, see 6.4.1 and 6.4.2; for API semantics, see 6.4.7 API.


Important Notes (Read First)

  • TestApi.cpp is an integration demo script. It calls many APIs block by block and is not a production-ready safety program.
  • Do not compile and run the entire file blindly: it may trigger large movements, long JOG operations, drag-teaching recording, etc. Only test after ensuring a clear workspace, accessible emergency stop, and understanding each block.
  • Recommended usage: copy only required blocks into your own main, remove unrelated tests, and adjust parameters (IP, port, angles, coordinates, speed) according to your site.
  • Build note: in the current root CMakeLists.txt, examples/TestApi.cpp is commented out by default and is not included in the RobotDriver executable. If you want to use it as entry, uncomment it in SRC_SOURCES and comment out other example sources as needed, or add a separate add_executable for TestApi.cpp to avoid multiple main conflicts.

In source code, 1 in RobotArm robot(1, params) means TCP_COMM (consistent with include/Protocol.hpp).


Document Convention

The sections below map one-to-one to the comment blocks in TestApi.cpp (// ========== N.). Each section includes Purpose, Main APIs, and Usage Notes for selective reuse.


1. System Configuration and Version Information

  • Purpose: Read controller/model/end-effector/library versions before power-on, and verify communication/firmware information.
  • Main APIs: getSystemVersion, getModifyVersion, getRobotType, getAtomVersion, getToolModifyVersion, getLibVersion.
  • Usage Notes: No motion risk; version string format depends on firmware.

2. Power-On and Status Query

  • Purpose: Power on, then query power status, refresh mode, free-move mode, and zero-calibration first item.
  • Main APIs: powerOn, isPowerOn, getFreshMode, setFreeMoveMode, getFreeMoveMode, isInitCalibration.
  • Usage Notes: powerOff() and setFreshMode switching are commented in source—power-off may take seconds; after changing refresh mode, firmware may have a long internal delay (source comment example: around 6 s).

3. Motion Control Mode

  • Purpose: Read whether current mode is position or torque.
  • Main APIs: getControlMode; (optional) setControlMode.
  • Usage Notes: Confirm robot status and safe space before switching modes.

4. Joint Angle Control

  • Purpose: Read single/all joint angles; demonstrate difference between open-loop (setWaitArrival(false) + send command + manual usleep) and closed-loop (setWaitArrival(true) with sendAngles waiting for arrival).
  • Main APIs: getAngle, getAngles, setFreeMoveMode, setWaitArrival, getWaitArrival, sendAngle, sendAngles.
  • Usage Notes:
    • Usually turn off free-move mode before position commands (setFreeMoveMode(0) in example), otherwise firmware may not execute position commands.
    • Target angles and speed must follow the MyCobotPro450 ranges in Joint Control.

5. Coordinate Control

  • Purpose: Read current getCoords; show open-loop single-axis sendCoord; interrupt with stop.
  • Main APIs: getCoords, sendCoord, stop.
  • Usage Notes:
    • Source comments indicate invalid poses such as SendCoords({0,0,0,0,0,0}) may cause abnormal firmware POS_ARRIVED flooding. This is disabled in the demo; do not blindly use all-zero coordinates.
    • Coordinate and speed ranges are listed in Coordinate Control.

6. Motion State Control

  • Purpose: Query moving state; pause / isPaused / resume / stop; angle-mode isInPosition example.
  • Main APIs: isMoving, pause, isPaused, resume, stop, isInPosition.
  • Usage Notes: In isInPosition, second argument false means angle comparison. The example uses all-zero target; use real target and respect limits in practice.

7. Software Joint Limits

  • Purpose: Loop and print software min/max angle for each joint.
  • Main APIs: getJointMinAngle, getJointMaxAngle.
  • Usage Notes: Read-only, no motion.

8. Speed / Acceleration Parameters

  • Purpose: Read and sample-write max speed and max acceleration for angle/coordinate modes.
  • Main APIs: getMaxSpeed, setMaxSpeed, getMaxAcc, setMaxAcc.
  • Usage Notes: mode 0 for joint-angle related values, 1 for coordinate related values; valid numeric ranges are in 6.4.7. Improper settings may affect motion smoothness and safety.

9. Encoders

  • Purpose: Read six servo encoder integer values.
  • Main APIs: getServoEncoders.
  • Usage Notes: Parsing and units follow controller behavior.

10. JOG Mode

  • Purpose: Run jogAngle and jogCoord for a period, then stop with stop.
  • Main APIs: jogAngle, jogCoord, stop.
  • Usage Notes: JOG is continuous motion; always reserve a stop path or limit protection. Direction 0/1, speed 1~100.

11. Drag Teaching

  • Purpose: stop to settle → enable free-move → record with dragTeachSave → pause → disable free-move → playback dragTeachExecute → clear dragTeachClean.
  • Main APIs: stop, setFreeMoveMode, dragTeachSave, dragTeachPause, dragTeachExecute, dragTeachClean.
  • Usage Notes: Recommended recording duration ≤ 120 s; manual dragging must be done in a safe environment. If teaching is not needed, remove this whole block instead of running it as-is.

12. Exception Information (Source Comment Labels This as 13)

  • Purpose: Read motion errors and call clearErrorInfomation; print fields in getRobotStatusDetail (collision, motion state, limits, joint status, communication status).
  • Main APIs: getErrorInformation, clearErrorInfomation, getRobotStatusDetail.
  • Usage Notes: Keep method spelling as clearErrorInfomation per header. Error-code meanings are listed in 6.4.7. getMotorsRunErr is left commented in source and can be enabled if needed.

Summary

Customer goal Suggested blocks from TestApi
Read-only status/version Block 1
Power and mode Blocks 2, 3
Joint point-to-point Block 4 (choose open-loop or closed-loop as needed)
Coordinate point-to-point Block 5 (avoid invalid coordinates)
Pause/continue/stop Block 6
Limits and dynamic parameters Blocks 7, 8
Encoders Block 9
Jogging Block 10
Teaching Block 11 (optional)
Fault troubleshooting Block 12

Again: reuse by block, adjust IP/port and motion parameters, and validate in a safe environment.


← Previous | Back to C++ Guide

results matching ""

    No results matching ""