-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unitree go2 sim and real support (#27)
* feat: unitree go2 sim and real support * feat: remove the `use_history` field, add `observations_history` to support history observations, and adjust the related logic to handle the case of empty history observations * feat: fix coordinate bug in ang_vel * fix: simplified handling of historical observation parameters, ensuring initialization of the observation history buffer in non-empty cases. --------- Co-authored-by: fan-ziqi <[email protected]>
- Loading branch information
Showing
750 changed files
with
125,122 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# rl_sar Developers and Contributors | ||
|
||
This is the official list of rl_sar Project developers and contributors. | ||
|
||
To see the full list of contributors, please check the revision history in the source control. | ||
|
||
Guidelines for modifications: | ||
|
||
* Please keep the lists sorted alphabetically. | ||
* Names should be added to this file as: *individual names* or *organizations*. | ||
|
||
## Developers | ||
|
||
* Ziqi Fan | ||
|
||
## Contributors | ||
|
||
* Jijie Huang | ||
|
||
## Acknowledgements | ||
|
||
* Unitree Robotics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#ifndef RL_REAL_HPP | ||
#define RL_REAL_HPP | ||
|
||
#include "rl_sdk.hpp" | ||
#include "observation_buffer.hpp" | ||
#include "loop.hpp" | ||
#include <unitree/robot/channel/channel_publisher.hpp> | ||
#include <unitree/robot/channel/channel_subscriber.hpp> | ||
#include <unitree/idl/go2/LowState_.hpp> | ||
#include <unitree/idl/go2/LowCmd_.hpp> | ||
#include <unitree/idl/go2/WirelessController_.hpp> | ||
#include <unitree/robot/client/client.hpp> | ||
#include <unitree/common/time/time_tool.hpp> | ||
#include <unitree/common/thread/thread.hpp> | ||
#include <unitree/robot/go2/robot_state/robot_state_client.hpp> | ||
#include <csignal> | ||
|
||
#include "matplotlibcpp.h" | ||
namespace plt = matplotlibcpp; | ||
|
||
using namespace unitree::common; | ||
using namespace unitree::robot; | ||
using namespace unitree::robot::go2; | ||
#define TOPIC_LOWCMD "rt/lowcmd" | ||
#define TOPIC_LOWSTATE "rt/lowstate" | ||
#define TOPIC_JOYSTICK "rt/wirelesscontroller" | ||
constexpr double PosStopF = (2.146E+9f); | ||
constexpr double VelStopF = (16000.0f); | ||
|
||
// 遥控器键值联合体 | ||
typedef union | ||
{ | ||
struct | ||
{ | ||
uint8_t R1 : 1; | ||
uint8_t L1 : 1; | ||
uint8_t start : 1; | ||
uint8_t select : 1; | ||
uint8_t R2 : 1; | ||
uint8_t L2 : 1; | ||
uint8_t F1 : 1; | ||
uint8_t F2 : 1; | ||
uint8_t A : 1; | ||
uint8_t B : 1; | ||
uint8_t X : 1; | ||
uint8_t Y : 1; | ||
uint8_t up : 1; | ||
uint8_t right : 1; | ||
uint8_t down : 1; | ||
uint8_t left : 1; | ||
} components; | ||
uint16_t value; | ||
} xKeySwitchUnion; | ||
|
||
class RL_Real : public RL | ||
{ | ||
public: | ||
RL_Real(); | ||
~RL_Real(); | ||
|
||
private: | ||
// rl functions | ||
torch::Tensor Forward() override; | ||
void GetState(RobotState<double> *state) override; | ||
void SetCommand(const RobotCommand<double> *command) override; | ||
void RunModel(); | ||
void RobotControl(); | ||
|
||
// history buffer | ||
ObservationBuffer history_obs_buf; | ||
torch::Tensor history_obs; | ||
|
||
// loop | ||
std::shared_ptr<LoopFunc> loop_keyboard; | ||
std::shared_ptr<LoopFunc> loop_control; | ||
std::shared_ptr<LoopFunc> loop_rl; | ||
std::shared_ptr<LoopFunc> loop_plot; | ||
|
||
// plot | ||
const int plot_size = 100; | ||
std::vector<int> plot_t; | ||
std::vector<std::vector<double>> plot_real_joint_pos, plot_target_joint_pos; | ||
void Plot(); | ||
|
||
// unitree interface | ||
void InitRobotStateClient(); | ||
void InitLowCmd(); | ||
int QueryServiceStatus(const std::string &serviceName); | ||
uint32_t Crc32Core(uint32_t *ptr, uint32_t len); | ||
void LowStateMessageHandler(const void *messages); | ||
void JoystickHandler(const void *message); | ||
RobotStateClient rsc; | ||
unitree_go::msg::dds_::LowCmd_ unitree_low_command{}; | ||
unitree_go::msg::dds_::LowState_ unitree_low_state{}; | ||
unitree_go::msg::dds_::WirelessController_ joystick{}; | ||
ChannelPublisherPtr<unitree_go::msg::dds_::LowCmd_> lowcmd_publisher; | ||
ChannelSubscriberPtr<unitree_go::msg::dds_::LowState_> lowstate_subscriber; | ||
ChannelSubscriberPtr<unitree_go::msg::dds_::WirelessController_> joystick_subscriber; | ||
xKeySwitchUnion unitree_joy; | ||
|
||
// others | ||
int motiontime = 0; | ||
std::vector<double> mapped_joint_positions; | ||
std::vector<double> mapped_joint_velocities; | ||
int command_mapping[12] = {3, 4, 5, 0, 1, 2, 9, 10, 11, 6, 7, 8}; | ||
int state_mapping[12] = {3, 4, 5, 0, 1, 2, 9, 10, 11, 6, 7, 8}; | ||
}; | ||
|
||
#endif // RL_REAL_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<launch> | ||
<arg name="wname" default="stairs"/> | ||
<arg name="rname" default="go2"/> | ||
<param name="robot_name" type="str" value="$(arg rname)_isaacgym"/> | ||
<param name="ros_namespace" type="str" value="/$(arg rname)_gazebo/"/> | ||
<param name="gazebo_model_name" type="str" value="$(arg rname)_gazebo"/> | ||
<arg name="robot_path" value="(find $(arg rname)_description)"/> | ||
<arg name="dollar" value="$"/> | ||
|
||
<arg name="paused" default="true"/> | ||
<arg name="use_sim_time" default="true"/> | ||
<arg name="gui" default="true"/> | ||
<arg name="headless" default="false"/> | ||
<arg name="debug" default="false"/> | ||
<!-- Debug mode will hung up the robot, use "true" or "false" to switch it. --> | ||
<arg name="user_debug" default="false"/> | ||
|
||
<include file="$(find gazebo_ros)/launch/empty_world.launch"> | ||
<arg name="world_name" value="$(find rl_sar)/worlds/$(arg wname).world"/> | ||
<arg name="debug" value="$(arg debug)"/> | ||
<arg name="gui" value="$(arg gui)"/> | ||
<arg name="paused" value="$(arg paused)"/> | ||
<arg name="use_sim_time" value="$(arg use_sim_time)"/> | ||
<arg name="headless" value="$(arg headless)"/> | ||
</include> | ||
|
||
<!-- Load the URDF into the ROS Parameter Server --> | ||
<param name="robot_description" | ||
command="$(find xacro)/xacro --inorder '$(arg dollar)$(arg robot_path)/xacro/robot.xacro' | ||
DEBUG:=$(arg user_debug)"/> | ||
|
||
<!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot --> | ||
<!-- Set trunk and joint positions at startup --> | ||
<node pkg="gazebo_ros" type="spawn_model" name="urdf_spawner" respawn="false" output="screen" | ||
args="-urdf -z 0.6 -model $(arg rname)_gazebo -param robot_description"/> | ||
|
||
<!-- Load joint controller configurations from YAML file to parameter server --> | ||
<rosparam file="$(arg dollar)$(arg robot_path)/config/robot_control.yaml" command="load"/> | ||
|
||
<!-- load the controllers --> | ||
<node pkg="controller_manager" type="spawner" name="controller_spawner" respawn="false" | ||
output="screen" ns="/$(arg rname)_gazebo" args="joint_state_controller | ||
FL_hip_controller FL_thigh_controller FL_calf_controller | ||
FR_hip_controller FR_thigh_controller FR_calf_controller | ||
RL_hip_controller RL_thigh_controller RL_calf_controller | ||
RR_hip_controller RR_thigh_controller RR_calf_controller "/> | ||
|
||
<!-- convert joint states to TF transforms for rviz, etc --> | ||
<node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher" | ||
respawn="false" output="screen"> | ||
<remap from="/joint_states" to="/$(arg rname)_gazebo/joint_states"/> | ||
</node> | ||
|
||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.