Move a robot from a PC in C# and Python
Move Fanuc, Yaskawa, Universal Robots, ABB and Stäubli robots to a Cartesian target with one code: what each controller needs before a move, safety, C# and Python examples.
This article shows how to move a Fanuc, Yaskawa, Universal Robots, ABB or Stäubli robot from a PC to a Cartesian target, with one code in C# or Python. The code of the move does not change from one brand to another. What changes is what each controller needs before it accepts a move from the network: the table at the end gives it.
Prerequisites
- UnderAutomation.Robotics in your project. See Get started with .NET or Get started with Python.
- The connection settings of each controller. See Connect to your robot.
- The license of each brand you connect, or the 30 day trial. See Licensing.
- The servo power on, see State, and the mode that accepts a move from the network on each controller. See the table at the end.
- The route of the moves enabled when it is marked (manual) in the table below. Until then, a move throws
RouteUnavailableException, and its message says what to enable.
Safety
The moves move the robot. A robot is dangerous machinery. Test your code on a simulator or an emulator first, then on the real robot with low speeds and a person at the emergency stop. The safety of the controller applies as for any remote command. StopMotion does not replace the emergency stop. The SDK does not replace a safety system: see the Legal notice.
Brand support
Each cell gives the protocol that the method uses on this brand, in the default order. The table is generated from the route data of the library. "Not available" means that the brand has no route for the method: the call throws FeatureNotSupportedException, and IsAvailable returns false before the call. (manual) marks a route that you enable yourself in the connection parameters.
| Method | Fanuc | Yaskawa | Universal Robots | ABB | Stäubli |
|---|---|---|---|---|---|
| Motion.MoveJoint | RMI (manual) | Not available | Primary Interface (Script), Interpreter Mode (manual) | Robot Web Services | SOAP |
| Motion.MoveJointToPose | RMI (manual) | High Speed Ethernet Server, Ethernet Server | Primary Interface (Script), Interpreter Mode (manual) | Robot Web Services | SOAP |
| Motion.MoveLinear | RMI (manual) | High Speed Ethernet Server, Ethernet Server | Primary Interface (Script), Interpreter Mode (manual) | Robot Web Services | SOAP |
| Motion.MoveLinearToJoints | RMI (manual) | Not available | Primary Interface (Script), Interpreter Mode (manual) | Robot Web Services | SOAP |
| Motion.StopMotion | RMI (manual) | High Speed Ethernet Server, Ethernet Server | Primary Interface (Script), Dashboard Server | Robot Web Services | SOAP |
| Motion.WaitForMotionEnd | RMI (manual) | High Speed Ethernet Server, Ethernet Server | Dashboard Server, Primary Interface (Primary) | Robot Web Services | Not available |
| Methods of this article | 6 of 6 | 4 of 6 | 6 of 6 | 6 of 6 | 5 of 6 |
Example
Move each robot of a cell to a Cartesian target
The example connects to the controllers of a cell one after the other. It reads the current position, raises it by 50 mm and moves there with a joint interpolation at 10 % of the maximum speed. MoveJointToPose returns when the controller accepted the motion, without waiting for its end. WaitForMotionEnd waits for it on the brands that have it. On a brand without it, the example reads the position until it reaches the target.
The parameters of the brand give the settings of the moves. On Fanuc, the example enables RMI, the only route of the moves.
static void Main(){// Fanuc: RMI is the only route of the moves, and the library never opens it by itselfUnderAutomation.Fanuc.ConnectionParameters fanuc = new UnderAutomation.Fanuc.ConnectionParameters("192.168.0.1");fanuc.Rmi.Enable = true;RobotConnectionParameters[] cell ={fanuc,new UnderAutomation.Yaskawa.ConnectParameters("192.168.0.2"),new UnderAutomation.UniversalRobots.ConnectParameters("192.168.0.3"),new UnderAutomation.ABB.ConnectionParameters("192.168.125.1"),new UnderAutomation.Staubli.ConnectionParameters("192.168.0.254"),};foreach (RobotConnectionParameters parameters in cell){// The same code for each controller of this cellRobotController robot = new RobotController();robot.Connect(parameters);// ABB: take the RAPID mastership with the ABB SDK through robot.Native before the move// 50 mm up from the current position, joint interpolation at 10 % of the maximum speedRobotPosition target = robot.Motion.ReadPose();target.Pose.Z += 50;robot.Motion.MoveJointToPose(target, new MotionSpeed { Percent = 10 });if (robot.Motion.IsAvailable(MotionFeature.WaitForMotionEnd)){robot.Motion.WaitForMotionEnd(30000);}else{// No end of motion on this brand: wait until Z reaches the target, 30 s at mostfor (int i = 0; i < 300 && Math.Abs(robot.Motion.ReadPose().Pose.Z - target.Pose.Z) > 0.5; i++)Thread.Sleep(100);}robot.Disconnect();}}}
In Python, the names are in snake_case: robot.motion.move_joint_to_pose(target, speed), robot.motion.wait_for_motion_end(30000), robot.motion.is_available(...).
Move along a line
MoveLinear moves the tool center point along a line to a Cartesian position. Linear of the MotionSpeed is the speed of the tool center point in mm/s. MoveLinearToJoints does it to a joint position, on the brands that have it.
RobotController robot = new RobotController();robot.Connect(RobotConnectionParameters.Create("fanuc", "192.168.0.1"));RobotPosition target = robot.Motion.ReadPose();target.Pose.Z += 50;// Linear interpolation: tool center point at 100 mm/sMotionSpeed speed = new MotionSpeed { Linear = 100 };robot.Motion.MoveLinear(target, speed);robot.Motion.WaitForMotionEnd(30000);// Same move to joint valuesrobot.Motion.MoveLinearToJoints(new JointValues(0, 0, 0, 0, -90, 0), speed);robot.Disconnect();}
Stop the motion
StopMotion stops a motion that was started by the moves of the library.
RobotController robot = new RobotController();robot.Connect(RobotConnectionParameters.Create("fanuc", "192.168.0.1"));robot.Motion.StopMotion();robot.Disconnect();}
What changes from one brand to another
The code does not change. Each controller has its own conditions for a move from the network. The moves that each brand has are in the support table above.
| Brand | Before a move | Brand article |
|---|---|---|
| Fanuc | RMI, option R912 of the controller. The library never opens RMI by itself: set Rmi.Enable to true in the connection parameters. RMI takes the motion control of the controller. | Move the robot remotely |
| Yaskawa | Servo power, remote mode and play mode. | Move the robot |
| Universal Robots | On e-Series and PolyScope X, the robot is in remote control. The default route sends a script: the program that runs on the robot stops. | Move the robot |
| ABB | One RAPID module, UnderAutomationMotion.mod, loaded once in the motion task of the robot, automatic mode, and the RAPID mastership taken with the ABB SDK through robot.Native. Without the module, IsAvailable returns true and a move throws RouteUnavailableException. See Routing. | Motion |
| Stäubli | Remote mode, and no application that holds the arm. The moves use the flange as the tool and the world as the frame. | Move the robot |
The page Motion explains the targets, the configuration, the speeds and the joint moves.
Errors
FeatureNotSupportedException: the brand has no route for the method, for exampleMoveJointon Yaskawa.RouteUnavailableException: the method has routes, but none can be used, for example RMI not enabled on Fanuc, or the RAPID module missing on ABB.ControllerRefusedException: the controller received the move and refused it, for example because it is not in the right mode.RobotControllerException: the route failed. Its inner exception is the exception of the brand SDK.WaitForMotionEndthrows it with an innerTimeoutExceptionwhen the motion is not finished after the timeout.
The page Errors explains each exception.
What to read next
- Motion: every method of the Motion service.
- Get the current position of a robot: read a target before a move.
- Routing settings: enable a route that is off at start.