io control

There are pins on the M5Stack-basic at the bottom of the robot and the Atom at the end. You can use io control to set the high and low levels of the pins and control tools such as pumps. For the input and output pin numbers of each robot type, please see the following description table:

Description table of the input and output pins of the bottom M5Stack-basic:

Robot model Input pin number Output pin number
myCobot 280-M5 35, 36 2, 5, 26
myCobot 320-M5 35, 36 5, 15

Terminal Atom input and output pin description table:

Robot model Input pin number Output pin number
myCobot 280-M5 19, 22 23, 33
myCobot 320-M5 None None

basic io control (m5)

Set the output io high and low levels

SetBasicOut(int pin_number, int pin_signal)
Return value: None
Parameter description: Parameter 1: Pin number (basic output pin number), Parameter 2: Status (0--low level, 1--high level)
Example:
mycobot::MyCobot::I().SetBasicOut(2, 1);

Get input io status

GetBasicIn(int pin_number)
Return value: pin status (0--low level, 1--high level)
Parameter description: pin number (basic input pin number)
Example: Set output pin 2 to high level
mycobot::MyCobot::I().GetBasicIn(35);

Atom io control

Note: 320m5 does not have atom io, so this module API is not needed

Set the output io high and low levels

SetDigitalOut(int pin_number, int pin_signal)
Return value: None
Parameter description: Parameter 1: pin number (atom output pin number), parameter 2: state (0--low level, 1--high level)
Case:
mycobot::MyCobot::I().SetDigitalOut(23, 1);

Get input io status

GetDigitalIn(int pin_number)
Return value: pin status (0--low level, 1--high level)
Parameter description: pin number (atom input pin number)
Example:
mycobot::MyCobot::I().GetDigitalIn(19);

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; // Introduce time unit literals (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 actions of the robot

// 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 per loop
}

// Adjust the J1 joint angle in 1 degree increments and a speed of 5
mycobot::MyCobot::I().JogAngle(mycobot::Joint::J1, 1, 5);
std::this_thread::sleep_for(5000ms); // Delay 5 seconds

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

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

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

results matching ""

    No results matching ""