Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

Stand-alone Robot SDK Documentation

Install the SDK

Users can install the Java SDK through maven:

1. <dependency>
2. <groupId>com.hansrobot</groupId>
3. <artifactId>robot-sdk</artifactId>
4. <version>1.0.0</version>
5. </dependency>
6.
7. //为 common
8. <dependency>
9. <groupId>com.hansrobot</groupId>
10. <artifactId>common</artifactId>
11. <version>1.0.0</version>

12. </dependency>

Uninstall the SDK

The SDK can be uninstalled by deleting pom dependencies or source code.

Import class name

The package name of COS Java SDK is com.hansrobot.robotsdk.* , and you can import the
classes needed for program running through IDE tools such as Eclipse or Intellij.

Callback type interface

There are two cases when executing an action, one is to return the status synchronously, and the
other is to return the status asynchronously. The asynchronous state is that when the interface is
called, it will immediately return a calling state of the interface, and then return an execution state
asynchronously; for example, the navigation interface: calling the navigation interface will
immediately return a status of whether the call is successful (return immediately ), and then return
a status of whether the AGV navigation is successful or not (asynchronous return).

Connect robot

Before operating the robot, you need to connect to the robot.


1. HansRobotSDK api = new HansRobotSDK();
2. //robotIp is robot ip ,you need to connect the robot segment
3. //32000 is the robot request port
4. //32001 is the robot push port
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
5. //judge whether the connection is succeed

6. Assert.assertEquals(cr.getError(), HansRobotError.SUCCESS);

Description of some enumerated fields

1. //robot subscription data


2. public enum SubscribeTopic{
3. ROBOT_DATA, //robot data
4. LASER_DATA, //laser data
5. REQUEST_RESULT_ASYNC, //asynchronous result notification for a request
6. ROBOT_INFO //robot information,push RobotInfo
7. }
8. //Robot Action Description
9. public static enum RunCmdEnum {
10. START, //start action
11. PAUSE, //pause the action, this state can only be used after the action starts
12. CONTINUE, //Continue action, this state can only be used after pause
13. STOP; //Stop the action, you can request it during execution

14. }

Subscribe to robot news

Subscribe to the robot message return

subscribe(SubscribeTopic.ROBOT_DATA.name(), true,null);

Interface call description

When calling the robot, you need to confirm 2 things:

1. Before the robot confirms the position, you need to confirm whether the robot is in the normal
position, or has not been moved by people when it is turned off
2. Before calling, the control right of the robot needs to be preempted, otherwise the action
cannot be executed (the control right can be preempted repeatedly)
AGV navigation

AGV can navigate to a certain site on the map according to the constructed parameters

1. HansRobotSDK api = new HansRobotSDK();


2. //connect robot
3. CallResult cr = api.connectRobot(robotIp, 32000, 32001);
4. Assert.assertEquals(cr.getError(), HansRobotError.SUCCESS);

5. if (CallResult.check(cr)) {
6. CallResult finalResult = CallResult.success();
7. NavigateRequestParam param = new NavigateRequestParam();
8. //
9. param.setCmd(CommonTypes.RunCmdEnum.START);
10. //position name
11. param.setDestPosition("LM30");
12. //map name
13. param.setDestMap("0823");
14. //result is the call parameters
15. cr = api.navigate(param, result -> {

16. if (CallResult.check(result))
17. System.out.println("navigate successfully");
18. else
19. System.out.println("navigate failed");
20. finalResult.fromOther(result);
21. finalResult.setData("");
22. System.out.println("error:" + result.getError() + " msg:" + result.getMessage());
23. });
24. Assert.assertEquals(HansRobotError.SUCCESS, cr.getError());
25. while (finalResult.getData() == null) {
26. CommonClass.sleep(1000);
27. }

28. }

NavigateRequestParam class, the main members are as follows:

member name description type


destPosition Site information on the map String

destMap map name String

cmd execution state Enum

Whether it arrives
noNeedPrecision Boolean
accurately is generally false

AGV navigation (synchronous method)

The AGV can navigate to a certain site on the map according to the constructed parameters.
Since this method is a synchronous method, there is no need to wait for the callback

1. HansRobotSDK api = new HansRobotSDK();


2. CallResult cr = api.connectRobot(robotIp, 32000, 32001);
3. Assert.assertEquals(cr.getError(), HansRobotError.SUCCESS);

4. if (CallResult.check(cr)) {
5. CallResult finalResult = CallResult.success();
6. NavigateRequestParam param = new NavigateRequestParam();
7. param.setCmd(CommonTypes.RunCmdEnum.START);
8. param.setDestPosition("LM1");
9. param.setDestMap("testMap");
10. cr = api.navigateForSync(param);
11. Assert.assertEquals(HansRobotError.SUCCESS, cr.getError());

12. }

NavigateRequestParam class, the main members are as follows:

member name describe type

destPosition Site information on the map String

destMap map name String

cmd execution state Enum

Whether it arrives
noNeedPrecision Boolean
accurately is generally false
ARM performs robotic arm actions

ARM can execute preset actions in the robot arm, just need to pass the script name, and also can
transfer parameters to perform if conditional operation

1. HansRobotSDK api = new HansRobotSDK();


2. CallResult cr = api.connectRobot(robotIp, 32000, 32001);
3. Assert.assertEquals(cr.getError(), HansRobotError.SUCCESS);

4. if (CallResult.check(cr)) {
5. RunArmFunctionRequestParam param = new RunArmFunctionRequestParam();
6. param.setCmd(CommonTypes.RunCmdEnum.START);
7. param.setFunctionName("Func_test");
8. CallResult finalResult = CallResult.success();
9. cr = api.runArmFunction(param, result -> {
10. if (CallResult.check(result))
11. System.out.println("run arm script function successfully");
12. else
13. System.out.println("run arm script function failed");
14. finalResult.setData("");

15. System.out.println("error:" + result.getError() + " msg:" + result.getMessage());


16. });
17. //wait for call data
18. while (finalResult.getData() == null) {
19. CommonClass.sleep(1000);
20. }

21. }

RunArmFunctionRequestParam class, the main members are as follows:

member name description type

scriptName script name String

The name of the function to


functionName String
execute

functionParams incoming parameters Enum


cmd execution status Boolean

Timeout time, -1 means no


timeout int
timeout

ARM performs robotic arm action (synchronous method)

ARM can execute preset actions in the robot arm, just need to pass the script name, and also can
transfer parameters to perform if conditional operation

1. HansRobotSDK api = new HansRobotSDK();


2. CallResult cr = api.connectRobot(robotIp, 32000, 32001);
3. Assert.assertEquals(cr.getError(), HansRobotError.SUCCESS);

4. if (CallResult.check(cr)) {
5. RunArmFunctionRequestParam param = new
RunArmFunctionRequestParam();
6. param.setCmd(CommonTypes.RunCmdEnum.START);
param.setFunctionName("Func_test");
CallResult finalResult = CallResult.success();

RunArmFunctionRequestParam class, the main members are as follows:

member name describe type

scriptName script name String

The name of the function to


functionName String
execute

functionParams incoming parameters Enum

cmd execution state Boolean

Timeout time, -1 means no


timeout int
timeout

Set configuration file parameters

Set the built-in parameters of the robot


1. HansRobotSDK api = new HansRobotSDK();
2. CallResult cr = api.connectRobot(robotIp, 32000, 32001);
3. SubscribeDataCallback callback = new SubscribeDataCallback() {
4. SetParamsForSdkParam sdk = new SetParamsForSdkParam();
5. sdk.setQuitChargePowerLevel("0.95");
6. sdk.setChargeMap("chargeMap");
7. sdk.setHomeMap("A1-5F");

8. CallResult result = api.setRobotParams(sdk);

SetParamsForSdkParam class, the main members are as follows:

member name description type

Whether to enable automatic


enableAutoCharge String
charging

The amount of electricity that


needs to be charged
needChargePowerLevel String
(automatically charge when it is
lower than the amount)

Exit charging power (exit charging


quitChargePowerLevel String
after the power is reached)

chargeMap charging map String

chargePoint charging point String

homeMap stand by String

homePoint standby map String

maxLinearSpeed AGV straight line speed String

armSpeedRatio Arm movement speed String

The working mode of the robot, 0:


workMode stand-alone, 1: multiple machines String
can be called, 2: multiple
machines cannot be called

maxAngularSpeed AGV turning speed String

Get configuration file parameters

Get the built-in parameters of the robot


1. HansRobotSDK api = new HansRobotSDK();
2. CallResult cr = api.connectRobot(robotIp, 32000, 32001);
3. CallResult result = api.getPropertiesData();
4. //data are within data

5. System.out.println(result.getData());

The available data are as follows:

member name describe type

Whether to enable automatic


enableAutoCharge String
charging

The amount of electricity that


needs to be charged
needChargePowerLevel String
(automatically recharge when it is
lower than the amount)

Exit charging power (exit charging


quitChargePowerLevel String
after the power is reached)

chargeMap charging map String

chargePoint charging point String

homeMap stand by String

homePoint standby map String

maxLinearSpeed AGV straight line speed String

armSpeedRatio Arm movement speed String

The working mode of the robot, 0:


workMode stand-alone, 1: multiple machines String
can be called, 2: multiple
machines cannot be called

maxAngularSpeed AGV turning speed String

Set the emergency stop state of the robot

Set the emergency stop state of the robot


1. HansRobotSDK api = new HansRobotSDK();
2. CallResult cr = api.connectRobot(robotIp, 32000, 32001);
3. EmergencyStopRequestParam param = new EmergencyStopRequestParam();
4. param.setEstop(true);
5. CallResult result = api.estop(param);
6. System.out.println(result.getData());
7. System.out.println(result.getError());

8. System.out.println(result.getMessage());

EmergencyStopRequestParam class, the main member attributes are as follows:

member name describe type

Whether to enable emergency


estop String
stop

Relocation request

Robot retargeting request


1. HansRobotSDK api = new HansRobotSDK();
2. CallResult cr = api.connectRobot(robotIp, 32000, 32001);
3. RelocateRequestParam param = new RelocateRequestParam();
4. param.setUseHomePose(false);
5. param.setCancel(true);
6. param.setRange(0);
7. param.setRobotX(0);
8. param.setRobotY(0);
9. param.setRobotAngle(0);
10. CallResult result = api.relocation(param, callResult -> {
11. //internal call interface
12. });
13. System.out.println(result.getData());
14. System.out.println(result.getError());

15. System.out.println(result.getMessage());

RelocateRequestParam class, the main member properties are as follows:

member name description type

true: cancel relocation, false:


cancel ignore, when false, other boolean
parameters are required

The relocation extent, the radius


range of the circle centered on the float
relocation point

robotAngle relocate point orientation, in rad float

relocate point x-coordinate, in


robotX float
meters

relocate point y-coordinate, in


robot Y float
meters

Whether to use the home point


configured on the agv interface
useHomePose for relocation, if true, ignore the boolean
relocation point coordinates and
radius parameters.
Confirm location request

When the robot confirms the positioning request, the robot needs to manually confirm the
positioning, and cannot automatically confirm the positioning, because it is impossible to
determine whether the robot was moved by someone when it was turned off.

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.locationConfirm();

System.out.println(result.getData());

Seize control

The robot seizes the control right. Before controlling the robot, it needs to seize the control right,
otherwise the command cannot be executed.

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.takeControl();

System.out.println(result.getData());

release control

Robot releases control, and it can release control after preemption

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.releaseControl();

System.out.println(result.getData());

Query control

Query the control rights of the robot

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.queryControl();

System.out.println(result.getData());
Initialize the gripper

Initialize the 485-type gripper of the robotic arm. When the gripper is initialized, no items can be
hung on the gripper and the robotic arm needs to be at the home point.

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.initGripper();

System.out.println(result.getData());

Control Gripper

The gripper of the controlled robotic arm 485 type, true is closed, false is open

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CtrlGripperRequestParam params = new CtrlGripperRequestParam();

params.setClose(false);
CallResult result = api.ctrlGripper(params);

System.out.println(result.getData());

The robotic arm returns to the origin

The robot arm returns to the preset home point. When calling this interface, you need to pay
attention to the safety of the robot arm. Is there anyone around?

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.armGoHomePose(callResult -> {

});

System.out.println(result.getData());

The robot arm starts zero-force teaching

The mechanical arm is turned on for zero-force teaching, and the mechanical arm in this state
can swing freely.
HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
BooleanRequestParam params = new BooleanRequestParam();
params.setParam(false);
CallResult result = api.startArmZeroForce(params);

System.out.println(result.getData());

BooleanRequestParam class, the main member attributes are as follows:

member name describe type

Whether to enable zero force


param Boolean
teaching

Control robotic arm movement control

Robotic arm movement control

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
RunCmdRequest params = new RunCmdRequest();
params.setCmd(CommonTypes.RunCmdEnum.STOP);
CallResult result = api.armMoveCtrl(params);

System.out.println(result.getData());。

RunCmdRequest class, the main member properties are as follows:

member name description type

robot arm moves, pauses,


cmd enumerate
continues, and stops.

AGV clears abnormal information

Clear AGV abnormal information

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.clearErrors();

System.out.println(result.getData());
Get AGV map collection information

Get the AGV map collection

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.getMaps();

System.out.println(result.getData());

Query the site information in the map

Obtain the site information in the map, which can be used in conjunction with the interface for
obtaining map information

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
GetPositionsRequestParam param = new GetPositionsRequestParam();
//map name
param.setMapName("0823");
CallResult result = api.getPositions(param);

System.out.println(result.getData());

GetPositionsRequestParam class, the main member properties are as follows:

member name description type

mapName map name String

Get map information

Obtain the site information in the map, which can be used in conjunction with the interface for
obtaining map information.
1 HansRobotSDK api = new HansRobotSDK();
2 CallResult cr = api.connectRobot(robotIp, 32000, 32001);
3 GetMapInfoRequestParam param = new GetMapInfoRequestParam();
4 param.setMapName("0823");
5 param.setContainPixelData(false);
6 CallResult result = api.getMapInfo(param);

7 System.out.println("4" + result.getData());

GetMapInfoRequestParam class, the main member attributes are as follows:

member name describe type

mapName map name String

containPixelData Not fill Boolean


The robot arm moves continuously

The robot arm moves continuously, but it needs to use longMoveEvent

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
//arm continues to move
ArmCtrlLongJogL param = new ArmCtrlLongJogL();
param.setAxisId(2);
param.setDerection(0);
param.setnState(1);
param.setMoveMode(1);
param.setKeep(true);
CallResult result = api.ctrlArmLongJogL(param, callResult -> {
System.out.println("test ctrlArmLongJogL");
});
System.out.println("4" + result.getData());
System.out.println("5" + result.getError());
System.out.println("6" + result.getMessage());
for (int i = 0; i < 10; i++) {
Thread.sleep(300);
//only ofr test. It need to be called alone in actual use.
api.longMoveEvent(true);
}
param.setnState(0);
result = api.ctrlArmLongJogL(param, callResult -> {
System.out.println("test ctrlArmLongJogL11111");
});
// 3 parameters below will be passed when the arm moves certain distance
// param.setAxisId(2);
// param.setDerection(0);
// param.setMoveMode(2);
// CallResult result = api.ctrlArmLongJogL(param,callResult -> {
// System.out.println("test ctrlArmLongJogL");
// });

// System.out.println("" + result.getData());

ArmCtrlLongJogL class, the main member attributes are as follows:


member name description type

Jog axis ID(0-5)


axisId int
(0:X,1:Y,2:Z,3:RX,4:RY,5:RZ)

derectification Movement direction: 0= negative int


direction; 1= positive direction;

nState Motion start and stop: 0= stop; int


1= start;

keep whether to continue moving Boolean

moveMode Movement mode: 1. Continuous int


movement, 2. Fixed movement

Tell the robotic arm to continue moving

When the above interface is moving, it needs to be called once every 500 milliseconds, otherwise
the mechanical arm will stop, just pass the true parameter directly, and pass false when it needs
to stop

api.longMoveEvent(true);

AGV rotates in place

This interface allows the AGV to rotate at a certain angle, and the speed can also be controlled.

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
//AGV rotate in place
RotateRequestParam param = new RotateRequestParam();
param.setRotateSpeed(0.1);
param.setAngle(0.1);
CallResult result = api.rotate(param, callResult -> {

});

System.out.println(result.getData());

RotateRequestParam class, the main member attributes are as follows:


member name describe type

rotateSpeed spinning speed double

the angle angle int

AGV travels a fixed distance

Let the AGV travel a certain distance

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
//AGV moves certain distance in a straight line MoveLineRequestParam param = new
MoveLineRequestParam();
param.setxSpeed(0.1);
param.setySpeed(0);
param.setDistance(0.1);
CallResult result = api.agvMoveLine(param, callResult -> {

});

System.out.println(result.getData());

The MoveLineRequestParam class, the main member attributes are as follows:

member name describe type

xSpeed Forward or backward speed, double


when the parameter is positive,
move forward, when the
parameter is negative, move
backward

ySpeed Fixed to 0 double

distance Advance distance double


AGV switch map

AGV switching map function


HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
//AGV 切换地图
SwitchMapRequestParam param = new SwitchMapRequestParam();
param.setMapName("0823");
CallResult result = api.agvSwitchMap(param);

System.out.println(result.getData());

SwitchMapRequestParam class, the main member attributes are as follows:

member name describe type

mapName map name String

AGV keeps moving

AGV continuous mobile interface


HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
//AGv 持续移动,一直传参就会一直移动
ManualMoveRequestParam param = new ManualMoveRequestParam();
param.setW(0);
param.setVx(1);
param.setVy(0);
for (int i = 0; i < 3; i++) {
CallResult result = api.ctrlAgvMove(param);

ManualMoveRequestParam class, the main member attributes are as follows:

member name describe type

w Moving speed float

Continuous moving distance,


vx positive number moves forward, float
negative number moves
backward
vy Just pass 0 float

Execute the robotic arm script

Execute the preset robotic arm script, which can be programmed in the robotic arm and then
used HansRobotSDK api = new HansRobotSDK(); here
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
//执行机械臂脚本
RunArmScriptRequestParam param = new RunArmScriptRequestParam();
param.setCmd(CommonTypes.RunCmdEnum.START);
param.setFunctionParams(null);
param.setScriptName("");
param.setFunctionName("Func_1");
param.setTimeout(-1);
CallResult result = api.executeArmScript(param, callResult -> {

});

System.out.println(result.getData());

RunArmScriptRequestParam class, the main member attributes are as follows:

member name describe type

scriptName script name String

functionName function name String

functionParams function parameters String[]

cmd Excuting an order enum

timeout Timeout time, -1 means never int


timeout
Execute the robotic arm script

Execute the preset robotic arm script, which can be programmed in the robotic arm and then
used HansRobotSDK api = new HansRobotSDK(); here
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CtrlArmRequestParam param = new CtrlArmRequestParam();
param.setArmIndex(0);
param.setArmSpeed(0);
param.setValidParam(CtrlArmRequestParam.ValidParamEnum.STOP_VALID);
param.setEnable(false);
param.setStop(false);
param.setClearFaults(false);
param.setClearFaults(false);
CallResult result = api.ctrlArm(param);

System.out.println(result.getData());

of CtrlArmRequestParam class are as follows:

member name describe type

Specifies which parameters are


valid.
0: powerOn
validParam 1: enable int
2: stop
3:clearFaults
4: armSpeed

powerOn Whether to power on Boolean

enable whether to open Boolean

stop Whether to suspend Boolean

Whether to clear the error of the


clearFaults robotic arm, when the robotic arm Boolean
reports an error, it can be set to true
to clear the error

armIndex Robot id, default is 0 int

armSpeed Arm speed float

You might also like