Joint Control (RobotArm)
Joint control for a robotic arm means sending target angles to each joint or reading current angles, and moving under a given speed constraint until reaching the target. This document is based on RobotArm (include/RobotArm.hpp), for MyCobotPro450, with Linux + TCP communication (see Environment Setup and Build).
All interfaces below follow the same format: Function, Return Value, Parameter Description, and Range. For the full API index, see API Reference.
Joint Angle Ranges (°)
| Joint id | Angle range |
|---|---|
| 1 | -162 ~ 162 |
| 2 | -125 ~ 125 |
| 3 | -154 ~ 154 |
| 4 | -162 ~ 162 |
| 5 | -162 ~ 162 |
| 6 | -165 ~ 165 |
Speed sp / speed: 1 ~ 100 (same throughout this document).
Single Joint
int sendAngle(uint8_t joint, float angle, uint8_t sp)
- Function: Sends a target angle to the specified joint.
- Return Value: Usually
1when communication and command succeed; usually-1on failure (controller behavior prevails). - Parameter Description:
jointjoint index;angletarget angle (°);spspeed level. - Range:
joint: 1 ~ 6;angle: see table above;sp: 1 ~ 100.
Multiple Joints
float getAngle(uint8_t joint)
- Function: Reads the current angle of one joint.
- Return Value: Floating-point angle (°); may return sentinel values on abnormal conditions (per integration behavior).
- Parameter Description:
joint. - Range:
joint: 1 ~ 6.
Angles getAngles()
- Function: Reads current angles of all six joints at once.
- Return Value:
Angles(std::array<float, 6>), indices 0 ~ 5 correspond to J1 ~ J6. - Parameter Description: None.
- Range: None.
int sendAngles(Angles angles, uint8_t sp)
- Function: Sends target angles for all six joints in one command.
- Return Value: Usually
1on success,-1on failure. - Parameter Description:
anglessix target angles;spspeed level. - Range: Each element follows the corresponding joint range in the table above;
sp: 1 ~ 100.
float getJointMinAngle(uint8_t joint) / float getJointMaxAngle(uint8_t joint)
- Function: Reads software joint limits (min/max angle).
- Return Value: Floating-point value (°).
- Parameter Description:
joint. - Range:
joint: 1 ~ 6.
JOG and Auxiliary
int jogAngle(uint8_t joint, uint8_t direction, uint8_t speed)
- Function: Continuously rotates the specified joint in one direction until a limit is reached or
stop()is called. - Return Value: Usually
1on success,-1on failure. - Parameter Description:
joint;direction;speed. - Range:
joint: 1 ~ 6;direction: 0 negative, 1 positive;speed: 1 ~ 100.
int setFreeMoveMode(bool state) / int getFreeMoveMode()
- Function: Enables/disables free-move mode (for manual guiding), or queries current status.
- Return Value: Set function usually returns
1on success; query returns0off,1on,-1on failure. - Parameter Description:
state,false/true. - Range: Boolean mapping to 0 / 1.
int setMotorEnabled(uint8_t joint, bool state) / int servoRestore(uint8_t joint)
- Function: Enables/disables one joint motor, or clears joint abnormality (restore command).
- Return Value: Usually
1on success,-1on failure. - Parameter Description:
joint;setMotorEnabledalso requiresstate(falsedisable torque,trueenable torque). - Range:
joint: 1 ~ 6 or 254 (all joints).
In-Position and Closed-Loop (Used with Joint Commands)
int isInPosition(Angles angle_coords, bool mode)
- Function: Checks whether the robot has reached the given 6-axis target.
- Return Value:
1reached;0not reached;-1abnormal or no valid response. - Parameter Description:
angle_coordssix target values;modedata type flag. - Range: For joint-angle checks, use
mode == false; angles follow the joint-angle table in this chapter.
void setWaitArrival(bool enable) / bool getWaitArrival() const / bool waitPosArrived(int timeout_ms = 30000)
- Function: Sets whether motion commands wait for arrival before returning; queries this switch; or blocks until arrival feedback.
- Return Value:
setWaitArrivalhas no return value;getWaitArrivalreturnsbool;waitPosArrivedistruewhen arrived andfalseon timeout. - Parameter Description:
enable;timeout_mstimeout (ms). - Range:
timeout_ms> 0, default 30000.
Drag Teaching
int dragTeachSave() / int dragTeachPause() / int dragTeachExecute() / int dragTeachClean()
- Function: Start drag trajectory recording; pause recording; execute the recorded trajectory once; clear sampled points.
- Return Value: Usually
1on success,-1on failure. - Parameter Description: None.
- Range: Recommended single recording duration ≤ 120 s.
Example (Excerpt)
The following example assumes TCP connectivity to the robot-side service is already available. It only demonstrates joint-related calls. Add error handling and thread-safety logic according to your project requirements.
#include "RobotArm.hpp"
#include "config.hpp"
#include <iostream>
#include <thread>
#include <chrono>
using namespace std::chrono_literals;
int main() {
Param p;
p.ip_serial = "192.168.0.232";
p.port_baud = 4500;
RobotArm arm(TCP_COMM, p);
if (arm.powerOn() != 1) {
std::cerr << "powerOn failed\n";
return 1;
}
Angles cur = arm.getAngles();
std::cout << "J1=" << cur[0] << " ...\n";
Angles goal = {5.f, 5.f, 5.f, -5.f, 5.f, 5.f};
if (arm.sendAngles(goal, 30) != 1) {
std::cerr << "sendAngles failed\n";
}
while (arm.isInPosition(goal, false) != 1) {
cur = arm.getAngles();
std::cout << "J1=" << cur[0] << "\n";
std::this_thread::sleep_for(200ms);
}
arm.jogAngle(1, 1, 30);
std::this_thread::sleep_for(2s);
arm.stop();
arm.powerOff();
return 0;
}