Reads the current position of a robot and outputs it to the console.
#include "YMConnect.h"
void main()
{
StatusInfo status{};
auto c = YMConnect::OpenConnection("192.168.1.31", status);
PositionData positionData{};
status = c->ControlGroup->ReadPositionData(ControlGroupId::R1, CoordinateType::Pulse, 0, 0, positionData);
std::cout << positionData << std::endl;
YMConnect::CloseConnection(c);
}
#include "YMConnect.h"
void main()
{
StatusInfo status{};
//Open up the connection to the controller.
auto c = YMConnect::OpenConnection("192.168.1.31", status);
//This sets the active job to one called "Test" with the line number of 0.
status = c->Job->SetActiveJob("Test", 0);
//Turn on the servos.
status = c->ControlCommands->SetServos(SignalStatus::On);
//Start the job.
status = c->ControlCommands->StartJob();
//Remember to close the connection at the end of the program.
YMConnect::CloseConnection(c);
}
Read a position variable and output it to the console.
#include "YMConnect.h"
void main()
{
StatusInfo status{};
auto c = YMConnect::OpenConnection("192.168.1.31", status);
//Declare a RobotPositionVariableData.
RobotPositionVariableData robotPositionVariableData{};
//Read the position variable at index 1. Assign it to variable robotPositionVariableData;
status = c->Variables->RobotPositionVariable->Read(1, robotPositionVariableData);
std::cout << robotPositionVariableData << std::endl;
YMConnect::CloseConnection(c);
}
This can be used for files other than JBI files as well.
#include "YMConnect.h"
void main()
{
StatusInfo status{};
//Open up the connection to the controller.
auto c = YMConnect::OpenConnection("192.168.1.31", status);
//This saves the active job to a file called "TEST1.JBI" in the directory "C:\\Users\\Public\\Documents\\, true means it will overwrite the file if it already exists."
status = c->Files->SaveFromControllerToFile("TEST1.JBI", "C:\\Users\\Public\\Documents\\TEST1.JBI", true);
//Remember to close the connection at the end of the program.
YMConnect::CloseConnection(c);
}
Use the MotionManagerInterface to go between two points.
If you do not change each of the destination coordinates in this program to valid coordinates, it may cause undefined behavior.
#include "YMConnect.h"
void main()
{
//Open the connection
StatusInfo status;
auto c = YMConnect::OpenConnection("192.168.1.31", status);
//turn on the servos
status = c->ControlCommands->SetServos(SignalStatus::ON);
std::cout << status << std::endl;
//Initialize two PositionData structures
PositionData positionData;
PositionData positionData2;
//Set the PositionData structures CoordinateType to Robot coordinate.
positionData.coordinateType = CoordinateType::RobotCoordinate;
positionData2.coordinateType = CoordinateType::RobotCoordinate;
//Set the first destination coordinates.
positionData.axisData = { 0, 0, 0, 0, 0, 0, 0, 0 }; //Change these coordinates to valid ones for your robots configuration.
//Set the second destination coordinates.
positionData2.axisData = { 0, 0, 0, 0, 0, 0, 0, 0 }; //Change these coordinates to valid ones for your robots configuration.
//create the LinearMotion objects with the previously defined positions.
LinearMotion motion(ControlGroupId::R1, positionData, 60.0);
LinearMotion motion2(ControlGroupId::R1, positionData2, 60.0);
//Add the first motion to the trajectory
status = c->MotionManager->AddPointToTrajectory(motion);
std::cout << status << std::endl;
//Add the second motion.
status = c->MotionManager->AddPointToTrajectory(motion2);
std::cout << status << std::endl;
//start the motion.
status = c->MotionManager->MotionStart();
std::cout << status << std::endl;
//Output the progress to the destinations forever...
while (true)
{
std::cout << c->MotionManager->GetMotionTargetProgress(ControlGroupId::R1, status) << std::endl;
}
}