Creating a Robot
Creating a Robot with Custom parts
First, we create the parts for our robot. This can be done as in the example, or you can import your own CAD-models. See Importing CAD file for an example of how to import a CAD-file.
The
MechanismBuilder
is our tool to create the robot. This is where we define our robot.We set the name and model name of the robot. The model name is what kind of robot it is, and name is the display name that will be shown in the browser.
We add the different links, and set which part is which link. We also have to define which link is the base link. A robot can only have one base link.
We then define the joints. This is where we connect our links to each other, i.e. the moving parts of the robot. After defining the joints, we have to set the joint limits. This is how much each joint can move, and is defined by a minimum and a maximum. For prismatic joints, the value is set in meters and for rotational joints the value is set in radians.
The base frame is the robots local origin. The home position is the default position of the robot. The joint mask specifies which joints that are active. 1 means active and 0 means inactive. Since we only have two joints in our robot, only the first to joints are active. The work range is the volume that the robot can access, defined by a rectangular parallelpiped box. It does not need to be the exact volume, but should be bigger than zero.
When we have defined our robot, we have to compile it. This gives us a
mechanism
that we can add to the station. Try this example by starting with an empty station, and then run the Add-In. A new robot will be created and added to the station. Go to the Layout browser and right click on the robot and select Mechanism Joint Jog. This will bring up the joint jog window where you can jog the robot to the wanted position.The last part we do is saving our robot as a RobotStudio library. This way, we can just import the library to a new station to get our robot.
Example
This example provides information on creating your own robot, with custom parts.
private static void CreateRobot()
{
Project.UndoContext.BeginUndoStep("Create A Robot");
try
{
Station station = Project.ActiveProject as Station;
// Create the base part for our robot.
Part basePart = new Part();
Body baseBody = Body.CreateSolidBox
(new Matrix4(new Vector3(0, 0, 0)), new Vector3(0.3, 0.3, 0.3));
basePart.Bodies.Add(baseBody);
// Create the first link.
Part linkPart_1 = new Part();
Body linkBody_1 = Body.CreateSolidCylinder
(new Matrix4(new Vector3(0, 0, 0)), 0.05, 0.5);
// Move the body to the right position.
linkBody_1.Transform.RX = Globals.DegToRad(-90);
linkBody_1.Transform.Translation = new Vector3(0.15, 0, 0.35);
// Add the body to the part.
linkPart_1.Bodies.Add(linkBody_1);
// Create the second link.
Part linkPart_2 = new Part();
Body linkBody_2_torus = Body.CreateSolidTorus
(new Matrix4(new Vector3(0, 0, 0)), 0.1, 0.05);
// Move the body to the right position.
linkBody_2_torus.Transform.RY = Globals.DegToRad(90);
linkBody_2_torus.Transform.RZ = Globals.DegToRad(90);
linkBody_2_torus.Transform.Translation = new Vector3(0.15, 0.5, 0.35);
Body linkBody_2_cone = Body.CreateSolidCone
(new Matrix4(new Vector3(0.15, 0.5, 0.45)), 0.03, 0.1);
// Add the bodies to the part.
linkPart_2.Bodies.Add(linkBody_2_torus);
linkPart_2.Bodies.Add(linkBody_2_cone);
// Start the mechanism builder.
MechanismBuilder mb = new MechanismBuilder(MechanismType.Robot);
// This is the model name and display name of our robot.
mb.ModelName = "My Robot";
mb.Name = "My Robot";
// Define the links in our robot.
mb.AddLink("Base", basePart);
mb.AddLink("Link1", linkPart_1);
mb.AddLink("Link2", linkPart_2);
// Define which link is the base link.
mb.BaseLink = "Base";
// Add two joint to our robot.
mb.AddJoint("Joint1", "Base", "Link1",
new Vector3(0, 0, 0), new Vector3(0, 1, 0), JointType.Prismatic, true);
mb.AddJoint("Joint2", "Link1", "Link2",
new Vector3(0.15, 0.5, 0.35), new Vector3(0.15, 0.6, 0.35),
JointType.Rotational, true);
// Set the joint limits.
mb.SetJointLimit("Joint1", -0.13, 0.2);
mb.SetJointLimit("Joint2", -System.Math.PI, System.Math.PI);
// Set the base fram of the robot.
mb.BaseFrame = Matrix4.Identity;
// Set the home position of the robot.
double[] homeJointPos = { 0, 0 };
mb.SetSyncJointPosition(homeJointPos);
// Set the calibration position of the robot.
Matrix4[] calPos = { Matrix4.Identity };
mb.SetCalibrationPosition(calPos);
// Define which joints that are active.
int[] jointMask = { 1, 1, 0, 0, 0, 0 };
mb.SetJointMask(jointMask);
// Compile the mechanism.
Mechanism mech = mb.CompileMechanism();
// Add the robot to the station.
station.GraphicComponents.Add(mech);
// Save a copy of the robot as a RobotStudio Library.
GraphicComponentLibrary gcl = mech.MoveDefinitionToLibrary();
string userProjPath = (string)Options.GetValue("RobotStudio", "Directories.UserProjects");
if (userProjPath != null)
{
gcl.SaveAs(userProjPath + "\\Libraries\\myRobot.rslib");
}
else
{
// If there is no UserprojPath, save it in user documents.
gcl.SaveAs(Path.Combine
(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "myRobot.rslib"));
}
// Close the library
gcl.Close();
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
Required Namespaces
ABB.
ABB.