Gripper control
Gripper installation:
- Adaptive gripper Insert the gripper into the pins on the atom, see the following figure for details:
- The electric gripper is plugged into the interface on the top, see the picture below:
Note: myCobot 280-m5 does not have an electric gripper, only myCobot 320-m5 has an electric gripper.
1 Adaptive gripper control
Supported devices: myCobot280, 320 && myPalletizer 260
SetGriper(int open)
Return value: None
Parameter description: Gripper switch status (0--off, 1--on)
Case: Due to delay, the first control of the gripper may not be successful, it is recommended to send it twice
for (int i = 0; i < 2; i++) {<br>
mycobot::MyCobot::I().SetGriper(1);<br>
mycobot::MyCobot::I().SleepSecond(3);<br>
mycobot::MyCobot::I().SetGriper(0);<br>
mycobot::MyCobot::I().SleepSecond(3);<br>
}<br>
Electric gripper control
Supported devices: myCobot320
SetElectricGriper(int open)
Return value: None
Parameter description: Gripper switch status (0--off, 1--on)
Case: Due to delay, the first control of the gripper may not be successful, it is recommended to send it twice
for (int i = 0; i < 2; i++) {<br>
mycobot::MyCobot::I().SetElectricGriper(1);<br>
mycobot::MyCobot::I().SleepSecond(1);<br>
mycobot::MyCobot::I().SetElectricGriper(0);<br>
mycobot::MyCobot::I().SleepSecond(1);<br>
}
Complete use case
int main(int argc, char* argv[])
try {
QCoreApplication a(argc, argv);
using namespace std::chrono_literals;
if (!mycobot::MyCobot::I().IsControllerConnected()) {
std::cerr << "Robot is not connected\n";
exit(EXIT_FAILURE);
}
std::cout << "Robot is connected\n";
mycobot::MyCobot::I().PowerOn();
mycobot::MyCobot::I().SleepSecond(1);//You need to wait for 1S to complete the previous action.
//Set io output, 2, 5, 26 are m5 output pins
mycobot::MyCobot::I().SetBasicOut(2, 1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetBasicOut(5, 1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetBasicOut(26, 1);
mycobot::MyCobot::I().SleepSecond(1);
//M5 input pins 35 and 36 will be delayed for the first time
/*for (int i = 0; i < 2; i++) {
std::cout << "35= " << mycobot::MyCobot::I().GetBasicIn(35) << std::endl;
mycobot::MyCobot::I().SleepSecond(1);
std::cout << "36= " << mycobot::MyCobot::I().GetBasicIn(36) << std::endl;
mycobot::MyCobot::I().SleepSecond(1);
}*/
//atom output pin 23 33
/*mycobot::MyCobot::I().SetDigitalOut(23, 1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetDigitalOut(33, 1);
mycobot::MyCobot::I().SleepSecond(1);*/
//Atom input pin 22 19 There will be a delay for the first time
/*for (int i = 0; i < 2; i++) {
std::cout << "22= " << mycobot::MyCobot::I().GetDigitalIn(22) << std::endl;
mycobot::MyCobot::I().SleepSecond(1);
std::cout << "19= " << mycobot::MyCobot::I().GetDigitalIn(19) << std::endl;
mycobot::MyCobot::I().SleepSecond(1);
}*/
//Adaptive gripper 1--open 0--close Sent twice due to delay in the first time
for (int i = 0; i < 2; i++) {
mycobot::MyCobot::I().SetGriper(1);
mycobot::MyCobot::I().SleepSecond(3);
mycobot::MyCobot::I().SetGriper(0);
mycobot::MyCobot::I().SleepSecond(3);
}
//Electric Gripper 1-On 0-Off Sent twice due to delay in first time
/*for (int i = 0; i < 2; i++) {
mycobot::MyCobot::I().SetElectricGriper(1);
mycobot::MyCobot::I().SleepSecond(1);
mycobot::MyCobot::I().SetElectricGriper(0);
mycobot::MyCobot::I().SleepSecond(1);
}*/
/*mycobot::MyCobot::I().StopRobot();
std::cout << "Robot is moving: " << mycobot::MyCobot::I().IsMoving() << "\n";
mycobot::Angles angles = mycobot::MyCobot::I().GetAngles();
std::this_thread::sleep_for(200ms);
mycobot::Coords coords = mycobot::MyCobot::I().GetCoords();
angles = mycobot::MyCobot::I().GetAngles();
std::cout << "[" << angles[mycobot::J1] << ", " << angles[mycobot::J2] << ", " << angles[mycobot::J3] << ", "
<< angles[mycobot::J4] << ", " << angles[mycobot::J5] << ", " << angles[mycobot::J6] << "]";
mycobot::Angles goal_angles = { 1, 0, 0, 0, 0, 0 };
mycobot::MyCobot::I().WriteAngles(goal_angles,180);
while (!mycobot::MyCobot::I().IsInPosition(goal_angles, false)) {
angles = mycobot::MyCobot::I().GetAngles();
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);
}
//mycobot::MyCobot::I().JogAngle(mycobot::Joint::J1, 1, 5);
std::this_thread::sleep_for(5000ms);
mycobot::MyCobot::I().StopRobot();*/
std::cout << "\n";
exit(EXIT_SUCCESS);
} catch (std::error_code&) {
std::cerr << "System error. Exiting.\n";
exit(EXIT_FAILURE);
} catch (...) {
std::cerr << "Unknown exception thrown. Exiting.\n";
exit(EXIT_FAILURE);
}