Setting Robot JointValues
This example provides information on setting the joint values of a robot. This example uses the IRB140, which has six joints. The joints of a robot can be either rotational or prismatic. So when we set our joint values we do not really know (yes we do, but pretend we don't) what kind of joint type we are trying to set. So we do a check for each of the joints, and if it is a rotational joint, we convert our value from degrees to radians, and if it is a prismatic joint, we convert it from milimeters to meters. We also print some information in the logger about the joint types and if we successfully set the joint values or not.
Use this information to set the robot joint values:
Get the robot and joint types.
Define the values for joints.
Assign joint value to robot joint values.
Print whether joint values have been set.
Solution
Get the robot and joint types.
// Get the robot. Mechanism mech = station.ActiveTask.Mechanism; // Get the joint types. JointType[] jointTypes = mech.GetJointTypes();
Define the values for joints.
// Define the values of the joints. double[] jointVal = new double[6]; jointVal[0] = 100.00; jointVal[1] = 80; jointVal[2] = 45; jointVal[3] = -150; jointVal[4] = 30.00; jointVal[5] = 300;
Assign joint value to robot joint values.
// Do this for each joint for (int i = 0; i < jointVal.Length; i++) { // If the joint is rotational if (jointTypes[i] == JointType.Rotational) { // Convert from degrees to radians. Print a message in the logger. jointVal[i] = Globals.DegToRad(jointVal[i]); Logger.AddMessage(new LogMessage("Joint " + i + 1 + " is rotational!")); } // If the joint is prismatic else if (jointTypes[i] == JointType.Prismatic) { // Convert from milimeter to meter. Print a message in the logger. jointVal[i] /= 1000; Logger.AddMessage(new LogMessage("Joint " + i + 1 + " is prismatic!")); } }
Print whether joint values have been set.
// If the values are not out of reach, set the joint values. // Print a message in the logger with the result. if (mech.SetJointValues(jointVal, false)) Logger.AddMessage(new LogMessage("SetJointValues success!")); else Logger.AddMessage(new LogMessage("SetJointValues failed!"));
Example
This example provides information on setting the robot joint values.
private static void SetRobotJointValues()
{
Project.UndoContext.BeginUndoStep("Set Robot Joint Values");
try
{
// This example needs an IRB140 to work!
Station station = Project.ActiveProject as Station;
// Get the robot.
Mechanism mech = station.ActiveTask.Mechanism;
// Get the joint types.
JointType[] jointTypes = mech.GetJointTypes();
// Define the values of the joints.
double[] jointVal = new double[6];
jointVal[0] = 100.00;
jointVal[1] = 80;
jointVal[2] = 45;
jointVal[3] = -150;
jointVal[4] = 30.00;
jointVal[5] = 300;
// Do this for each joint
for (int i = 0; i < jointVal.Length; i++)
{
// If the joint is rotational
if (jointTypes[i] == JointType.Rotational)
{
// Convert from degrees to radians. Print a message in the logger.
jointVal[i] = Globals.DegToRad(jointVal[i]);
Logger.AddMessage(new LogMessage("Joint " + i + 1 + " is rotational!"));
}
// If the joint is prismatic
else if (jointTypes[i] == JointType.Prismatic)
{
// Convert from milimeter to meter. Print a message in the logger.
jointVal[i] /= 1000;
Logger.AddMessage(new LogMessage("Joint " + i + 1 + " is prismatic!"));
}
}
// If the values are not out of reach, set the joint values.
// Print a message in the logger with the result.
if (mech.SetJointValues(jointVal, false))
Logger.AddMessage(new LogMessage("SetJointValues success!"));
else
Logger.AddMessage(new LogMessage("SetJointValues failed!"));
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
Required Namespaces
ABB.
ABB.