Skip to content

Commit

Permalink
v3.3.1 support arm32
Browse files Browse the repository at this point in the history
  • Loading branch information
TrivasZhang committed Oct 8, 2021
1 parent 2c8b7c8 commit 20929b5
Show file tree
Hide file tree
Showing 22 changed files with 363 additions and 145 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,19 @@ target_link_libraries(example_torque ${EXTRA_LIBS})
add_executable(example_walk examples/example_walk.cpp)
target_link_libraries(example_walk ${EXTRA_LIBS})

add_executable(example_dance examples/example_dance.cpp)
target_link_libraries(example_dance ${EXTRA_LIBS})

add_executable(example_wirelessHandle examples/example_wirelessHandle.cpp)
target_link_libraries(example_wirelessHandle ${EXTRA_LIBS})

# one pc multi process
add_executable(lcm_server_high examples/lcm_server_high.cpp)
target_link_libraries(lcm_server_high ${EXTRA_LIBS})

add_executable(lcm_server_low examples/lcm_server_low.cpp)
target_link_libraries(lcm_server_low ${EXTRA_LIBS})

# multi pc
add_executable(udp_send_test examples/multi_pc_udp_send.cpp)
target_link_libraries(udp_send_test ${EXTRA_LIBS})
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# v3.4
# v3.3.1
The unitree_legged_sdk is mainly used for communication between PC and Controller board.
It also can be used in other PCs with UDP.

### Notice
support robot: Go1
support robot: Aliengo, A1(sport_mode >= v1.19)

not support robot: Laikago, Aliengo, A1. (Check release [v3.2](https://github.com/unitreerobotics/unitree_legged_sdk/releases/tag/v3.2) for support)
not support robot: Laikago, Go1.

### Dependencies
* [Boost](http://www.boost.org) (version 1.5.4 or higher)
Expand Down
138 changes: 138 additions & 0 deletions examples/example_dance.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*****************************************************************
Copyright (c) 2020, Unitree Robotics.Co.Ltd. All rights reserved.
******************************************************************/

#include "unitree_legged_sdk/unitree_legged_sdk.h"
#include <math.h>
#include <iostream>
#include <unistd.h>
#include <string.h>

using namespace UNITREE_LEGGED_SDK;

class Custom
{
public:
Custom(uint8_t level): safe(LeggedType::A1), udp(8090, "192.168.123.161", 8082, sizeof(HighCmd), sizeof(HighState)){
udp.InitCmdData(cmd);
}
void UDPRecv();
void UDPSend();
void RobotControl();

Safety safe;
UDP udp;
HighCmd cmd = {0};
HighState state = {0};
int motiontime = 0;
float dt = 0.002; // 0.001~0.01
};


void Custom::UDPRecv()
{
udp.Recv();
}

void Custom::UDPSend()
{
udp.Send();
}

void Custom::RobotControl()
{
motiontime += 2;
udp.GetRecv(state);
// printf("%d %f\n", motiontime, state.forwardSpeed);

cmd.mode = 0; // 0:idle, default stand 1:forced stand 2:walk continuously
cmd.gaitType = 0;
cmd.speedLevel = 0;
cmd.footRaiseHeight = 0;
cmd.bodyHeight = 0;
cmd.euler[0] = 0;
cmd.euler[1] = 0;
cmd.euler[2] = 0;
cmd.velocity[0] = 0.0f;
cmd.velocity[1] = 0.0f;
cmd.yawSpeed = 0.0f;


if(motiontime > 0 && motiontime < 4000){
cmd.mode = 12;
printf("dance1 \n");
}
if(motiontime > 4000 && motiontime < 5000){
cmd.mode = 2;
}
if(motiontime > 5000 && motiontime < 6000){
cmd.mode = 1;
}

if(motiontime > 6000 && motiontime < 10000){
cmd.mode = 13;
printf("dance2 \n");
}
if(motiontime > 10000 && motiontime < 11000){
cmd.mode = 2;
}
if(motiontime > 11000 && motiontime < 12000){
cmd.mode = 1;
}


if(motiontime > 12000 && motiontime < 13000){
cmd.mode = 2;
}
if(motiontime > 13000 && motiontime < 14000){
cmd.mode = 1;
}

if(motiontime > 14000 && motiontime < 18000){
cmd.mode = 10;
printf("jumpYaw \n");
}
if(motiontime > 18000 && motiontime < 19000){
cmd.mode = 2;
}
if(motiontime > 19000 && motiontime < 20000){
cmd.mode = 1;
}

if(motiontime > 20000 && motiontime < 26000){
cmd.mode = 11;
printf("straightHand1 \n");
}
if(motiontime > 26000 && motiontime < 27000){
cmd.mode = 2;
}
if(motiontime > 27000 && motiontime < 28000){
cmd.mode = 1;
}

udp.SetSend(cmd);
}

int main(void)
{
std::cout << "Communication level is set to HIGH-level." << std::endl
<< "WARNING: Make sure the robot is standing on the ground." << std::endl
<< "Press Enter to continue..." << std::endl;
std::cin.ignore();

Custom custom(HIGHLEVEL);
InitEnvironment();
LoopFunc loop_control("control_loop", custom.dt, boost::bind(&Custom::RobotControl, &custom));
LoopFunc loop_udpSend("udp_send", custom.dt, 3, boost::bind(&Custom::UDPSend, &custom));
LoopFunc loop_udpRecv("udp_recv", custom.dt, 3, boost::bind(&Custom::UDPRecv, &custom));

loop_udpSend.start();
loop_udpRecv.start();
loop_control.start();

while(1){
sleep(10);
};

return 0;
}
7 changes: 3 additions & 4 deletions examples/example_position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using namespace UNITREE_LEGGED_SDK;
class Custom
{
public:
Custom(uint8_t level): safe(LeggedType::Go1), udp(level) {
Custom(uint8_t level): safe(LeggedType::Aliengo), udp(level) {
udp.InitCmdData(cmd);
}
void UDPRecv();
Expand Down Expand Up @@ -123,10 +123,9 @@ void Custom::RobotControl()

if(motiontime > 10){
safe.PositionLimit(cmd);
int res1 = safe.PowerProtect(cmd, state, 1);
safe.PowerProtect(cmd, state, 1);
// You can uncomment it for position protection
// int res2 = safe.PositionProtect(cmd, state, 0.087);
if(res1 < 0) exit(-1);
// safe.PositionProtect(cmd, state, 0.087);
}

udp.SetSend(cmd);
Expand Down
5 changes: 2 additions & 3 deletions examples/example_torque.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using namespace UNITREE_LEGGED_SDK;
class Custom
{
public:
Custom(uint8_t level): safe(LeggedType::Go1), udp(level){
Custom(uint8_t level): safe(LeggedType::A1), udp(level){
udp.InitCmdData(cmd);
}
void UDPSend();
Expand Down Expand Up @@ -59,8 +59,7 @@ void Custom::RobotControl()
cmd.motorCmd[FR_1].Kd = 0;
cmd.motorCmd[FR_1].tau = torque;
}
int res = safe.PowerProtect(cmd, state, 1);
if(res < 0) exit(-1);
safe.PowerProtect(cmd, state, 1);

udp.SetSend(cmd);
}
Expand Down
7 changes: 3 additions & 4 deletions examples/example_velocity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using namespace UNITREE_LEGGED_SDK;
class Custom
{
public:
Custom(uint8_t level): safe(LeggedType::Go1), udp(level){
Custom(uint8_t level): safe(LeggedType::Aliengo), udp(level){
udp.InitCmdData(cmd);
}
void UDPRecv();
Expand Down Expand Up @@ -60,10 +60,9 @@ void Custom::RobotControl()
}

if(motiontime > 10){
int res1 = safe.PowerProtect(cmd, state, 1);
safe.PowerProtect(cmd, state, 1);
// You can uncomment it for position protection
// int res2 = safe.PositionProtect(cmd, state, 0.087);
if(res1 < 0) exit(-1);
// safe.PositionProtect(cmd, state, 0.087);
}

udp.SetSend(cmd);
Expand Down
13 changes: 6 additions & 7 deletions examples/example_walk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ using namespace UNITREE_LEGGED_SDK;
class Custom
{
public:
Custom(uint8_t level):
safe(LeggedType::A1),
udp(8090, "192.168.123.161", 8082, sizeof(HighCmd), sizeof(HighState))
{
Custom(uint8_t level): safe(LeggedType::A1), udp(8090, "192.168.123.161", 8082, sizeof(HighCmd), sizeof(HighState)){
udp.InitCmdData(cmd);
}
void UDPRecv();
Expand Down Expand Up @@ -46,9 +43,10 @@ void Custom::RobotControl()
{
motiontime += 2;
udp.GetRecv(state);
printf("%d %f\n", motiontime, state.imu.quaternion[2]);

cmd.mode = 0; // 0:idle, default stand 1:forced stand 2:walk continuously
// printf("%f %f %f %f %f\n", state.imu.rpy[1], state.imu.rpy[2], state.position[0], state.position[1], state.velocity[0]);

cmd.mode = 0;
cmd.gaitType = 0;
cmd.speedLevel = 0;
cmd.footRaiseHeight = 0;
Expand All @@ -59,7 +57,7 @@ void Custom::RobotControl()
cmd.velocity[0] = 0.0f;
cmd.velocity[1] = 0.0f;
cmd.yawSpeed = 0.0f;
cmd.reserve = 0;


if(motiontime > 0 && motiontime < 1000){
cmd.mode = 1;
Expand Down Expand Up @@ -125,6 +123,7 @@ void Custom::RobotControl()
cmd.bodyHeight = 0.1;
// printf("walk\n");
}

if(motiontime>24000 ){
cmd.mode = 1;
}
Expand Down
7 changes: 3 additions & 4 deletions examples/example_wirelessHandle.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/************************************************************************
Copyright (c) 2020, Unitree Robotics.Co.Ltd. All rights reserved.
Use of this source code is governed by the MPL-2.0 license, see LICENSE.
************************************************************************/
/*****************************************************************
Copyright (c) 2020, Unitree Robotics.Co.Ltd. All rights reserved.
******************************************************************/

#include "unitree_legged_sdk/unitree_legged_sdk.h"
#include "unitree_legged_sdk/unitree_joystick.h"
Expand Down
6 changes: 5 additions & 1 deletion examples/lcm_server.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*****************************************************************
Copyright (c) 2020, Unitree Robotics.Co.Ltd. All rights reserved.
******************************************************************/

#include "unitree_legged_sdk/lcm_server.h"
#include <iostream>

Expand Down Expand Up @@ -58,4 +62,4 @@ int main(int argc, char *argv[])
}

return 0;
}
}
74 changes: 74 additions & 0 deletions examples/lcm_server_high.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*****************************************************************
Copyright (c) 2020, Unitree Robotics.Co.Ltd. All rights reserved.
******************************************************************/

#include "unitree_legged_sdk/unitree_legged_sdk.h"
#include <math.h>

using namespace UNITREE_LEGGED_SDK;

class Custom
{
public:
Custom(uint8_t level):
udp(8090, "192.168.123.161", 8082, sizeof(HighCmd), sizeof(HighState)),
mylcm(level){}
void UDPRecv(){
udp.Recv();
}
void UDPSend(){
udp.Send();
}
void LCMRecv();
void RobotControl();

UDP udp;
LCM mylcm;
HighCmd cmd = {0};
HighState state = {0};
};

void Custom::LCMRecv()
{
if(mylcm.highCmdLCMHandler.isrunning){
pthread_mutex_lock(&mylcm.highCmdLCMHandler.countMut);
mylcm.highCmdLCMHandler.counter++;
if(mylcm.highCmdLCMHandler.counter > 10){
printf("Error! LCM Time out.\n");
exit(-1); // can be commented out
}
pthread_mutex_unlock(&mylcm.highCmdLCMHandler.countMut);
}
mylcm.Recv();
}

void Custom::RobotControl()
{
udp.GetRecv(state);
mylcm.Send(state);
mylcm.Get(cmd);
udp.SetSend(cmd);
}

int main(void)
{
Custom custom(HIGHLEVEL);
// InitEnvironment();
custom.mylcm.SubscribeCmd();

LoopFunc loop_control("control_loop", 0.002, 3, boost::bind(&Custom::RobotControl, &custom));
LoopFunc loop_udpSend("UDP_Send", 0.002, 3, boost::bind(&Custom::UDPSend, &custom));
LoopFunc loop_udpRecv("UDP_Recv", 0.002, 3, boost::bind(&Custom::UDPRecv, &custom));
LoopFunc loop_lcm("LCM_Recv", 0.002, 3, boost::bind(&Custom::LCMRecv, &custom));

loop_udpSend.start();
loop_udpRecv.start();
loop_lcm.start();
loop_control.start();

while(1){
sleep(10);
}

return 0;
}
Loading

0 comments on commit 20929b5

Please sign in to comment.