This is the repo build to run your RL algorithm on the Unitree A1
And now I'll tell you how to use this repo
Before you start, you should have things below:
- cable(connect your PC to A1)
- A PC (Linux / Win is all ok )
- Python(3.8 + recommend)
Now Let's start build
- build your Unitree sdk as following command (from Info to Important parts )
- build the python version(notice the CMAKELISTS.txt)
This repo was forked from Maddy and Unitree
And I've implemented this sdk for python
The unitree_legged_sdk is mainly used for communication between PC and Controller board. It also can be used in other PCs with UDP.
You need to update your Raspi on the A1 to arm64
support robot: Aliengo, A1(sport_mode >= v1.19)
not support robot: Laikago, Go1.
cd lcm-x.x.x
mkdir build
cd build
cmake ../
make
sudo make install
mkdir build
cd build
cmake ../
make
cd python_wrapper
mkdir build
vim ../CMakelists.txt # change your ".so" info for your platform
cmake ..
make
You'll find a repo named "robot_interface*(your platform) *.so"
Run examples with 'sudo' for memory locking.
cp where-to-your-robot_interface-.so where-to-your-destination
cd where-to-your-des
sudo python3
remeber to use sudo to initial UDP
import robot_interface as sdk
import time
udp = sdk.UDP(0xff, sdk.Basic) # oxff is LowCmd
safe = sdk.Safety(sdk.LeggedType.A1)
cmd = sdk.LowCmd()
state = sdk.LowState()
udp.InitCmdData(cmd)
while True:
time.sleep(0.01)
udp.Recv()
udp.GetRecv(state)
for i in state.imu.quaternion:
print(i)
udp.SetSend(cmd)
udp.Send()
The base function of the robot has been written to the robot.py
cd py
sudo python3 ./test_robot.py
The robot usage has been written to the test_robot.py
import api.robot as rbt
from utils.signal_hand import quit_robot
import signal
# this one will make your robot go back to the original position in 100 * self.dt time
def signal_handler(signal, frame):
print('You pressed Ctrl+C!')
quit_robot(a1)
signal.signal(signal.SIGINT, signal_handler)
a1 = rbt.Robot()
a1.observe()
act = a1.position
a1.init_motor(act)
while True:
obs = a1.observe()
act = USE_YOUR_MODEL(obs)
a1.take_action(act)
# run below command if you need hold your posture
# while True:
# a1.hold_on()
- in the
robot.py
file, change theobserve()
func to fit your observation - in the
take_action
func, it'll change your action to command and send it to your robot
- the connection might be not stable if your cable is not very strong or stable ,It'll limit the behavior of your robot
- I've established a limit of torque and position
- change the
PowerProtect
if there is an errorPower Protection end
when you run your model
All these funcs are in the robot.py
file