Joint control

For serial multi-joint robots, joint control is the control of the variables of each joint of the robot arm. The goal is to make each joint of the robot arm reach the target position at a certain speed.

Single joint control

Send single joint angle

WriteAngle(Joint joint, double value, int speed = DefaultSpeed)
Return value: None
Parameter description: Parameter 1: Joint number (1-6) Parameter 2: Angle (-170°- 170°) Parameter 3: Speed ​​(0-100), default is 30
Example:
mycobot::MyCobot::I().WriteAngle(mycobot::Joint::J1, 10, 30);

Multi-joint control

Get all joint angles

GetAngles()
Return value: Angles type
Parameter description: None
Example:
mycobot::Angles angles= mycobot::MyCobot::I().GetAngles();

Send all joint angles

WriteAngles(const Angles& angles, int speed = DefaultSpeed)
Return value: None
Parameter description: Parameter 1: All angles (std::array, angle range -170°- 170°) Parameter 2: Speed ​​(0-100), default is 30
Example:

mycobot::Angles goal_angles = { 5, 5, 5, 5, 5, 5 };<br> mycobot::MyCobot::I().WriteAngles(goal_angles, 30);<br>

Complete use case

int main(int argc, char* argv[])
try {
QCoreApplication a(argc, argv); // Create a QCoreApplication object to support the Qt event loop

using namespace std::chrono_literals; // Import literals for time processing (such as 200ms)

// Check if the robot controller is connected
if (!mycobot::MyCobot::I().IsControllerConnected()) {
std::cerr << "Robot is not connected\n"; // If not connected, output error message
exit(EXIT_FAILURE); // Exit the program and return failure status
}

std::cout << "Robot is connected\n"; // Output successful connection information

mycobot::MyCobot::I().PowerOn(); // Power on and start the robot
mycobot::MyCobot::I().StopRobot(); // Stop all robot movements

// Check if the robot is moving and output the status
std::cout << "Robot is moving: " << mycobot::MyCobot::I().IsMoving() << "\n";

// Get the angles of each joint of the current robot
mycobot::Angles angles = mycobot::MyCobot::I().GetAngles();
std::this_thread::sleep_for(200ms); // Delay 200 milliseconds

// Get the position coordinates of the end of the current robot
mycobot::Coords coords = mycobot::MyCobot::I().GetCoords();

// Get the angles of each joint again
angles = mycobot::MyCobot::I().GetAngles();

// Output the angles of each joint
std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", "
<< angles[mycobot::J3] << ", " << angles[mycobot::J4] << ", "
<< angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]";

// Define a target angle array, all joints move to 5 degrees
mycobot::Angles goal_angles = { 5, 5, 5, 5, 5, 5 };
mycobot::MyCobot::I().WriteAngles(goal_angles); // Move the robot to the target angle

// Wait for the robot to move to the target position
while (!mycobot::MyCobot::I().IsInPosition(goal_angles, false)) {
angles = mycobot::MyCobot::I().GetAngles(); // Get the current angle
std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", "
<< angles[mycobot::J3] << ", " << angles[mycobot::J4] << ", "
<< angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]" << std::flush;
std::this_thread::sleep_for(200ms); // Delay 200 milliseconds for each loop
}

// Adjust the J1 joint angle, the increment is 1 degree, the speed is 5
mycobot::MyCobot::I().JogAngle(mycobot::Joint::J1, 1, 5);
std::this_thread::sleep_for(5000ms); // Delay for 5 seconds

mycobot::MyCobot::I().StopRobot(); // Stop all movements of the robot

std::cout << "\n"; // Output a newline character
exit(EXIT_SUCCESS); // Normal exit of the program

} catch (std::error_code&) {
// Capture the std::error_code exception and output the error message
std::cerr << "System error. Exiting.\n";
exit(EXIT_FAILURE); // Abnormal exit of the program
} catch (...) {
// Capture all other exceptions and output the error message
std::cerr << "Unknown exception thrown. Exiting.\n";
exit(EXIT_FAILURE); // Abnormal exit of the program
}

results matching ""

    No results matching ""