HansRobot SDK Document

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

HansRobot SDK

Install SDK

Users can install the Java SDK through maven :

<dependency>
<groupId>com.hansrobot</groupId>
<artifactId>robot-sdk</artifactId>
<version>1.0.0</version>
</dependency>

//为 common
<dependency>
<groupId>com.hansrobot</groupId>
<artifactId>common</artifactId>
<version>1.0.0</version>
</dependency>

Uninstall SDK

Uninstall the SDK by removing pom dependencies or source code。

Import Class Name

COS Java SDK class name is com.hansrobot.robotsdk.*,You can import the classes
required for program execution through IDE tools such as Eclipse or Intellij.

Callback Type Interface

There are two situations when executing an action, one is that the status
will be returned synchronously, and the other is that the status will be
returned asynchronously. The asynchronous state is that when the interface
is called, it will immediately return a call state of the interface, and
then asynchronously return an execution state; For example, navigation
interface: Calling a navigation interface will immediately return a status
indicating whether the call was successful or not (immediately), and then
return a status indicating whether the AGV navigation was successful or not
(asynchronously)

Connecting robots
Before operating a robot, you need to connect the robot

HansRobotSDK api = new HansRobotSDK();


//robotIp is robot ip ,At this point, you need to connect
to the network segment of the robot
//32000 Request port for robot
//32001 For the push port for the robot
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
//Determine whether the connection is successfully connected
Assert.assertEquals(cr.getError(),
HansRobotError.SUCCESS);
Some enumeration field descriptions

//Robots subscription data


public enum SubscribeTopic{
ROBOT_DATA, //Robot data
LASER_DATA, //Laser data
REQUEST_RESULT_ASYNC, //Notification of the requested
asynchronous results
ROBOT_INFO //Robot information, push RobotInfo
class
}

//Robot action description


public static enum RunCmdEnum {
START, //Start the action
PAUSE, //Pause an action, used only after the action begins
CONTINUE, //Continue to use this state only after a pause
STOP; //Stop the action, which can be requested during the
execution process
}

Subscribe to bot messages

Subscribe the bot message is


returned

subscribe(SubscribeTopic.ROBOT_DATA.name(), true,null);
Interface call instructions

When calling the robot, you need to confirm two things: 1. Before the robot

confirms the positioning, it needs to confirm whether the robot is in the normal

position, or is not moved in the case of shutdown 2. Before calling, you need to seize

the control of the robot, otherwise the action cannot be executed (the control can

be seized repeatedly)

AGV navigation
The AGV can navigate to a certain site of the map based on the built
parameters

HansRobotSDK api = new HansRobotSDK();


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

if (CallResult.check(cr)) {
CallResult finalResult = CallResult.success();
NavigateRequestParam param = new
NavigateRequestParam();
//
param.setCmd(CommonTypes.RunCmdEnum.START);
//Site name
param.setDestPosition("LM30");
//Map name
param.setDestMap("0823");
//result For pullback parameters
cr = api.navigate(param, result -> {

if (CallResult.check(result))
System.out.println("navigate successfully");
else
System.out.println("navigate failed");
finalResult.fromOther(result);
finalResult.setData("");
System.out.println("error:" + result.getError() + "
msg:" + result.getMessage());
});
Assert.assertEquals(HansRobotError.SUCCESS,
cr.getError());
while (finalResult.getData() == null) {
CommonClass.sleep(1000);
}
}

NavigateRequestParam:

Member name describe type


Site information
destPosition String
within the map

destMap Map name String

cmd executing state Enum

Whether the accurate


noNeedPrecision arrival is generally Boolean
false

AGV Navigation (Sync Method)

AGV can navigate to a certain site in the map based on the built parameters,
and since the method is a synchronous method, there is no need to wait for
a callback
HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
Assert.assertEquals(cr.getError(),
HansRobotError.SUCCESS);

if (CallResult.check(cr)) {
CallResult finalResult = CallResult.success();
NavigateRequestParam param = new
NavigateRequestParam();
param.setCmd(CommonTypes.RunCmdEnum.START);
param.setDestPosition("LM1");
param.setDestMap("testMap");
cr = api.navigateForSync(param);
Assert.assertEquals(HansRobotError.SUCCESS,
cr.getError());
}

NavigateRequestParam:

Member name describe type

Site information
destPosition String
within the map

destMap map name String

cmd executing state Enum

Whether the accurate


noNeedPrecision arrival is generally Boolean
false

The ARM performs the robotic arm action

ARM can perform actions already preset in the robotic arm, simply passing
the script name, or transfer parameters to perform IF conditions
HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
Assert.assertEquals(cr.getError(),
HansRobotError.SUCCESS);

if (CallResult.check(cr)) {
RunArmFunctionRequestParam param = new
RunArmFunctionRequestParam();
param.setCmd(CommonTypes.RunCmdEnum.START);
param.setFunctionName("Func_test");
CallResult finalResult = CallResult.success();
cr = api.runArmFunction(param, result -> {
if (CallResult.check(result))
System.out.println("run arm script function
successfully");
else
System.out.println("run arm script function
failed");
finalResult.setData("");

System.out.println("error:" + result.getError() + "


msg:" + result.getMessage());
});

RunArmFunctionRequestParam :

Member name describe type

scriptName Script name String

Name of the function


functionName String
being executed

The incoming
functionParams Enum
parameters

cmd executing state Boolean

Timeout time, -1 is no
timeout int
timeout
ARM performs robotic arm action (synchronization method)

The ARM can perform actions that are already preset in the robotic arm, and
only need to transmit Script name, or transmit parameters to perform IF
conditions

HansRobotSDK api = new HansRobotSDK();


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

if (CallResult.check(cr)) {
RunArmFunctionRequestParam param = new
RunArmFunctionRequestParam();
param.setCmd(CommonTypes.RunCmdEnum.START);
param.setFunctionName("Func_test");
CallResult finalResult = CallResult.success();
cr = api.runArmFunctionForSync(param);
}

RunArmFunctionRequestParam :

Member name describe type

scriptName Script name String

Name of the function


functionName String
being executed

The incoming
functionParams Enum
parameters

cmd executing state Boolean

Timeout time, -1 is no
timeout int
timeout

Set the profile parameters

Set the profile parameters


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

CallResult result = api.setRobotParams(sdk);

SetParamsForSdkParam:

Member name describe type

Whether the automatic


enableAutoCharge String
charge is turned on

Need to be charged
needChargePowerLevel (automatically charged String
when less than how much)

Exit charge power (exit


quitChargePowerLevel charge after the power String
power is reached)

chargeMap Charging map String

chargePoint Charging point String

homeMap On standby point String

homePoint On call map String

maxLinearSpeed AGV straight speed String

Mechanical arm movement


armSpeedRatio String
speed

The working mode of the robot,


0: single, 1: multi-machine
workMode String
callable, 2: multi-machine
uncallable
maxAngularSpeed The AGV turning speed String

Gets the profile parameters

Obtain the built-in parameters of the robot

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.getPropertiesData();
System.out.println(result.getData());

The available data are as follows:

Member name describe type

Whether the automatic


enableAutoCharge String
charge is turned on

Need to be charged
needChargePowerLevel (automatically charged String
when less than how much)

Exit charge power (exit


quitChargePowerLevel charge after the power String
power is reached)

chargeMap Charging map String

chargePoint Charging point String

homeMap On standby point String

homePoint On call map String

maxLinearSpeed AGV straight speed String

Mechanical arm movement


armSpeedRatio String
speed

The working mode of the robot,


0: single, 1: multi-machine
workMode String
callable, 2: multi-machine
uncallable
maxAngularSpeed The AGV turning speed String

Set the emergency stop state of the robot

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
EmergencyStopRequestParam param = new
EmergencyStopRequestParam();
param.setEstop(true);
CallResult result = api.estop(param);
System.out.println(result.getData());
System.out.println(result.getError());
System.out.println(result.getMessage());

EmergencyStopRequestParam :

Member name describe type

Whether to open the emergency


estop String
stop

Reposition request

Robot relocation request


HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
RelocateRequestParam param = new RelocateRequestParam();
param.setUseHomePose(false);
param.setCancel(true);
param.setRange(0);
param.setRobotX(0);
param.setRobotY(0);
param.setRobotAngle(0);
CallResult result = api.relocation(param, callResult -> {

});
System.out.println(result.getData());
System.out.println(result.getError());
System.out.println(result.getMessage());

RelocateRequestParam :

Member name describe type

True: cancel reset, false: ignored,

cancel other parameters required when boolean

false

Repositioning range, the radius

range of the circle centered on the float

repoint

Repositioning point orientation,


robotAngle float
in rad

Relocation x coordinates in
robotX float
meters

Rethe location point y


robotY float
coordinates, in m

Whether to use the configured

useHomePose home points of the agv interface boolean

for relocation, if true, ignore the


relocation coordinates and

radius parameters.

Confirm the location request

The robot confirms the positioning request, the robot needs to manually
confirm the positioning, and cannot automatically confirm the positioning,
because it cannot be determined whether the robot is moved when it is shut
down

HansRobotSDK api = new HansRobotSDK();


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

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

Preemption of control

The robot takes control, and before you can control the robot, you need to
seize control, otherwise it can't executive command
HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.takeControl();
System.out.println(result.getData());

Release of control

The robot releases control, which can release after seizing

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.releaseControl();
System.out.println(result.getData());

Query of the control of the robot

Query of the control 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 claw

Initialize the clamp claw of the mechanical arm 485type, which cannot hang
articles on the clamp claw, and the mechanical 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 claw

The claw of control arm 485type, true is closed and 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 mechanical arm back to the preset home point, call this interface need
to pay attention to the safety of the mechanical arm, there is anyone around
HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.armGoHomePose(callResult -> {

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

The robotic arm opens the zero-force instruction

The mechanical arm opens zero force teaching, at this time the mechanical
arm can swing at will

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 :

Member name describe type

Whether to open the


param Boolean
zero-force instruction
Control of the 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 :

Member name describe type

The robotic arm moves, uses,


cmd enumerate
continues, and stops
AGV cleanup exception information

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
CallResult result = api.clearErrors();
System.out.println(result.getData());

Get the AGV map collection information

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

To obtain the site information in the map, it can be used with the acquisition
map information interface
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 :

Member name describe type

mapName map name String

Get map information

To obtain the site information in the map, it can be used with the acquisition
map information interface
HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
GetMapInfoRequestParam param = new
GetMapInfoRequestParam();
param.setMapName("0823");
param.setContainPixelData(false);
CallResult result = api.getMapInfo(param);
System.out.println("4" + result.getData());

GetMapInfoRequestParam :

Member name describe type

mapName map name String

containPixelData Don't fill Boolean

The mechanical arm moves continuously

The mechanical arm moves continuously, but it needs to be used with another
interface
longMoveEvent

HansRobotSDK api = new HansRobotSDK();


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

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 for testing, when the real use, you need to call
separately
api.longMoveEvent(true);
}
param.setnState(0);
result = api.ctrlArmLongJogL(param, callResult -> {
System.out.println("test ctrlArmLongJogL11111");
});

//When the mechanical arm is required to move at a fixed distance,


only the following three parameters need to be passed through
// 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 :

Member name describe type

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

derection Movement direction: 0= int


negative; 1= positive;

nState Movement start / stop: 0= stop; int


1= start;

keep Do you want to move on Boolean

Movement mode: 1.
moveMode Continuous movement, and 2. int
Fixed movement

Inform 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, only need to pass the
true parameter directly can be, need to stop, can pass false can
api.longMoveEvent(true);

The AGV rotates in situ

The interface allows the AGV to rotate at an Angle and the speed can be
controlled

HansRobotSDK api = new HansRobotSDK();


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

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

RotateRequestParam :

Member name describe type

rotateSpeed spin velocity double

angle point of view int

The AGV travels at a fixed distance

Drive the AGV a distance


HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
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());

MoveLineRequestParam:

Member name describe type

Forward or backward speed,


xSpeed parameter is positive, double
move forward, and move
backward when negative

ySpeed Fixed to 0 double

distance Forward distance double

The AGV toggle map

The AGV switches over the map function


HansRobotSDK api = new HansRobotSDK();
CallResult cr = api.connectRobot(robotIp, 32000, 32001);
SwitchMapRequestParam param = new SwitchMapRequestParam();
param.setMapName("0823");
CallResult result = api.agvSwitchMap(param);
System.out.println(result.getData());

SwitchMapRequestParam :

Member name describe type

mapName map name String

The AGV moves continuously

The AGV is continuously moving the interface


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

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 类,主要成员属性如下:

Member name describe type

w translational speed float

Keep moving the distance,


with positive numbers
vx moving forward and float
negative numbers moving
backward

vy Pass 0 float

Execute the robotic arm script

The preset robotic arm script can be programmed in the robotic arm and then
used
here

HansRobotSDK api = new HansRobotSDK();


CallResult cr = api.connectRobot(robotIp, 32000, 32001);
//Execute the robotic arm script
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 :

Member name describe type

scriptName Script name String

functionName function name String

functionParams Function parameters String[]

cmd executive command enum

timeout Timeout time, -1 is never int


timeout

Execute the robotic arm script

The preset robotic arm script can be programmed in the robotic arm and then
used here
HansRobotSDK api = new HansRobotSDK();
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());

CtrlArmRequestParam :

Member name describe type

Specifies which parameters are

valid。

0:powerOn

validParam 1:enable int

2:stop

3:clearFaults

4:armSpeed

powerOn Whether on the electricity Boolean

enable Whether to open Boolean

stop Whether to suspend Boolean

Whether to clear the robotic arm


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

armIndex Mechanical arm id, with the int


default to 0

armSpeed Mechanical arm speed float

If you have any questions, please contact me via email;

My message: zouzk10410r@hanslaser.com thanks

You might also like