Python Lib

Catalogue
  1. 1. XGOLIB Python Library
    1. 1.1. aim
    2. 1.2. Revision record
    3. 1.3. XGO Class
    4. 1.4. Mobile related methods
      1. 1.4.1. 1.Front and back, left and right translation
      2. 1.4.2. 2.revolve
      3. 1.4.3. 3.mark time
      4. 1.4.4. 4.step frequency
      5. 1.4.5. 5.stop
    5. 1.5. Position Methods
      1. 1.5.1. 1.Body position translation
      2. 1.5.2. 2.Body posture adjustment
      3. 1.5.3. 3.Body cycle translation
      4. 1.5.4. 4.Body cycle rotation
    6. 1.6. other methods
      1. 1.6.1. Restore the initial state
      2. 1.6.2. Set the self-stabilization
      3. 1.6.3. Single Leg
      4. 1.6.4. Servo Control
      5. 1.6.5. Uninstall the single leg Servo
      6. 1.6.6. All Servo are uninstalled
      7. 1.6.7. Single leg Servo loading
      8. 1.6.8. All Servo are loaded
      9. 1.6.9. Set the Servo rotation speed
      10. 1.6.10. update the name of bluetooth
      11. 1.6.11. Perform a preset action
      12. 1.6.12. calibration
    7. 1.7. Read
      1. 1.7.1. read the servo
      2. 1.7.2. Read the battery
      3. 1.7.3. read positon

XGOLIB Python Library

aim

This document aims to describe the API interface of XGO in detail for the development of upper computer python. XGO-Mini Python Lib Download.

Revision record

2022.3.10 creat

XGO Class

All functions are implemented by the methods owned by XGO. When instantiating an XGO class object, three parameters need to be passed in. The first one is the physical interface for serial communication between the host computer and the robot dog. It needs to be modified according to the actual situation. The second parameter is the baud rate of 115200, and the third parameter is 'xgomini' or 'xgolite' according to the model. Assuming that the serial communication interface is COM4, the instantiation code is as follows.

1
2
dog = XGO('COM4',115200,'xgomini')
dog = XGO('COM4',115200,'xgolite')
The following will borrow the dog object to describe the function of the class method. For methods related to pose adjustment and single-leg control, you can check the serial port communication protocol document to understand the definition of the robot coordinate system.

1.Front and back, left and right translation

move(direction, step)

Parameter Name Format Input Range Description
direction character 'x'、'X'、'y'、'Y' 'x'or'X'moves the machine dog forward or back,'y'or'Y'moves the machine dog left or right
step figure x:[-25,25],y:[-18,18] This parameter represents the translation step size, according to the direction, a positive value represents forward or left shift, and a negative value represents backward or right shift. When the input value exceeds the range, move according to the limit value

2.revolve

turn(step)

Parameter Name Format Input Range Description
step figure [-150,150] This parameter represents rotational speed in ° / s, positive is left and negative is right.

3.mark time

mark_time(data)

Parameter Name Format Input Range Description
data figure [10,35] This parameter represents the height of leg lift in mm and stop standing when the input is 0

4.step frequency

pace(mode) speed = step frequency x stripe

Parameter Name Format Input Range Description
mode string ['normal','slow','high'] This parameter represents the step frequency, and normal is the default step frequency, low is the slow step frequency, and high is the high-speed step frequency

5.stop

stop()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
demo
#The machine dog moves at 18mm stripe
dog.move('x',18)

#The machine dog moves right in 5mm stripe
dog.move('y',-5)

#The code can be executed normally and will move left at 18mm stripe
dog.move('Y',30)

#The machine dog turns left at 60 ° / s
dog.turn(60)

#The machine dog moves at a high-speed pace
dog.pace('high')

#The machine dog mark time at the height of 25mm
dog.mark_time(25)

#The machine dog stop make time
dog.mark_time(0)

#Machine dog stop
dog.stop()
A series of methods are encapsulated in the library based on these methods for easy use.

name explain
move_x(step) Move front and back, equivalent to move('x', step)
move_y(step) Move left to right, equivalent to move('y', step)
forward(step) Forward, equivalent to move('x', abs(step))
back(step) Back, equivalent to move('x', -abs(step))
left(step) Left , equivalent to move('y', abs(step))
right(step) Right , equivalent to move('y', -abs(step))
turnleft(step) Left turn, equivalent to turn(abs(step))
turnright(step) Turn right, equivalent to turn(-abs(step))


Position Methods

When adjusting the position, the foot position of the four legs does not change, and the position or Angle of the body changes.

1.Body position translation

translation(direction, data)

Parameter Name Format Input Range Description
direction Single-character or character list 'x'、'y'、'z'or a list containing the above values 'x' represents forward and backward translation, 'y' represents left and right translation, and 'z' represents height
data figure x:[-35,35],y:[-18,18],z:[75,115] This parameter represents the body position translation distance in mm

2.Body posture adjustment

attitude(direction, data)

Parameter Name Format Input Range Description
direction Single-character or character list 'r'、'p'、'y'or a list containing the above values 'r'is roll,'p'is pitch,'y'is yaw
data figure r:[-20,20],p:[-15,15],y:[11,11] This parameter represents the magnitude of the body pose adjustment in °

3.Body cycle translation

periodic_tran(direction, period)
the body will be reciprocated in the specified period and direction by half the position translation limit, allowing periodic movements in multiple directions simultaneously.Body cycle movement and the whole machine movement cannot be carried out at the same time.

Parameter Name Format Input Range Description
direction Single character or character list 'x'、'y'、'z'or a list containing the above values 'x'represents forward and backward translation,'y'represents left and right translation,'z'represents height
period figure [1.5,8] This parameter represents the motion cycle in second; entering 0 represents the stop movement

4.Body cycle rotation

periodic_rot(direction, period)

Parameter Name Format Input Range Description
direction Single character or character list 'r'、'p'、'y'or a list containing the above values 'r'is roll,'p'is pitch,'y'is yaw
period figure [1.5,8] This parameter represents the motion cycle in second; entering 0 represents the stop movement
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
demo
#The body translate18mm forward
dog.translation('x',18)

#The body translate10mm to the right and height set to 100mm
#You can enter either a single value or a list to control the movement in multiple directions
dog.translation(['y','z'],[-10,100])

#The body pitch angle was set to 10 °, yaw angle set to-4 ° and roll angle set to 8 °
dog.attitude(['p','y','r'],[10,-4,8])

#The body was operated in a 3s cycle, with forward and backward translation
dog.periodic_tran('x',3)

#The body was reciprocated at a 3s cycle and at a yaw angle at a 7.4s cycle
dog.periodic_rot(['r','y'],[3,7.4])

#Stop the reciprocation of the yaw angle
dog.periodic_rot('y',0)

other methods

Restore the initial state

reset()
stops all movements, and all states return to the initial state

Set the self-stabilization

imu(mode)
When self-stable , the machine dog will automatically adjust the attitude angle to keep the back in a horizontal position, and must not manually set the attitude angle when turned on.

Parameter Name Format Input Range Description
mode integer 0、1 0 Represents turn off, and 1 represents turn on

perform(mode)
In performance mode, the robot dog will cycle through the preset actions.

Parameter Name Format Input Range Description
mode integer 0、1 0 Represents turn off, and 1 represents turn on


Single Leg

leg(leg_id, data)
Controls the foot position of the specified leg

Parameter Name Format Input Range Description
leg_id integer 1、2、3、4 They represent the left front, right front, right rear and left rear
data List of numbers of length 3 x:[-35,35],y:[-18,18],z:[75,115] This parameter represents the foot position in mm
1
2
3
demo
#Set the foot position of the right front leg as (10mm,-12mm,90mm)
dog.leg(2,[10,-12,90])


Servo Control

motor(motor_id, data)
controls the rotation angle of the Servo

Parameter Name Format Input Range Description
motor_id ist of integer or integer [11,12,13,21,22,23,31,32,33,41,42,43] The first number 1,2,3,4 stand for left front , right front ,right rear ,left rear.The second number 1,2,3 stand for down ,middle and upper Servo
data List of numbers or numbers Down:[-65, 73],Middle:[-66, 93],Upper:[-31, 31] This parameter represents the foot position in °
1
2
3
4
5
6
demo
#Set the right front leg middle Servo rotation angle to 30 °
dog.motor(22,30)

#Set the rotation angle of the upper right front leg at 10 ° and the down left rear leg at-20 °
dog.motor([23,41],[10,-20])


Uninstall the single leg Servo

unload_motor(leg_id)
unload three Servo on one leg without output torque, which can be rotate by hand, generally used for writing actions

Parameter Name Format Input Range Description
leg_id integer 1,2,3,4 They represent the left front, right front, right rear and left rear

All Servo are uninstalled

unload_allmotor()
makes all Servo unloaded without output torque and can be turned by hand

Single leg Servo loading

load_motor(leg_id)
keeps the three Servo on one leg in current position, output the torque, which can not be rotated by hand, and is generally used for writing actions

Parameter Name Format Input Range Description
leg_id integer 1,2,3,4 They represent the left front, right front, right rear and left rear

All Servo are loaded

load_allmotor()
keeps all Servo in current position, output torque which can not be turned by hand

Set the Servo rotation speed

motor_speed(speed)
adjusts the rotation speed of the Servo for separate control

Parameter Name Format Input Range Description
speed integer [0,255] 0 At the lowest speed and 255 at the highest speed

update the name of bluetooth

bt_rename(name)
Re-modify the bluetooth name, the bluetooth will disconnect after calling this function

Parameter Name Format Input Range Description
name String Length not greater than 10 The Bluetooth name format of the robot dog is XGO_xxx, xxx is the modifiable part, and only supports characters in ascii code.

Perform a preset action

action(action_id)

Parameter Name Format Input Range Description
action_id integer [1,255] The ID and action correspondence is shown in the table below
ID action ID action ID action
1 fall 2 stand 3 crawling
4 circle 5 Mark time 6 Squat up
7 Roll 8 Pitch 9 Yaw
10 Three-axis rotation 11 pee 12 sit down
13 hi 14 stretch 15 wave
16 left right 17 pray 18 find food
19 shake hands happy new year

calibration

calibration(state)
If some joints have obvious position deviation after power on, you can call this function for calibration.

Parameter Name Format Input Range Description
state integer [0,1] 1 Enter the calibration state, at this time the steering gear is unloaded, and then swing the robot dog to the calibration state, the calf is parallel to the ground, the thigh and the torso are at 90°, and the torso is parallel to the ground; 0 Complete the calibration

Read

read the servo

read_motor()
Read the angles of 12 servos, If the reading is successful, a list of length 12 will be returned, corresponding to servo with numbers [11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43]. Returns an empty list if the read fails

Read the battery

read_battery()
read the current battery level, If the reading is successful, it will return an integer from 1 to 100, which represents the percentage of remaining battery power. Returns 0 on read failure.

read positon

read_roll()
read_pitch()
read_yaw()
Read the current attitude angle, if the reading is successful, a floating-point number will be returned, and if the reading fails, it will return 0