Skip to content

Commit

Permalink
feat: [Destructive Update]del submodules unitree_ros
Browse files Browse the repository at this point in the history
  • Loading branch information
fan-ziqi committed May 23, 2024
1 parent 24e8018 commit 382702c
Show file tree
Hide file tree
Showing 40 changed files with 3,401 additions and 102 deletions.
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@ Simulation verification and physical deployment of the quadruped robot's reinfor

## Preparation

Clone the code (sync submodules)
Clone the code

```bash
git clone --recursive https://github.com/fan-ziqi/rl_sar.git
```

If there are updates:

```bash
git pull
git submodule update --remote --recursive
git clone https://github.com/fan-ziqi/rl_sar.git
```

## Dependency
Expand Down Expand Up @@ -182,12 +175,10 @@ In the following, let ROBOT represent the name of your robot.
4. Add a new launch file in the rl_sar/launch folder. Refer to other launch files for guidance on modification.
5. Change ROBOT_NAME to ROBOT in rl_xxx.cpp.
6. Compile and run.
7. If the torque of your robot's joints exceeds 50Nm, you need to modify line 180 in `rl_sar/src/unitree_ros/unitree_legged_control/src/joint_controller.cpp` to:
```cpp
// calcTorque = computeTorque(currentPos, currentVel, servoCmd);
calcTorque = servoCmd.posStiffness * (servoCmd.pos - currentPos) + servoCmd.velStiffness * (servoCmd.vel - currentVel) + servoCmd.torque;
```
This will remove the 50Nm limit.
## Reference
[unitree_ros](https://github.com/unitreerobotics/unitree_ros)
## Citation
Expand Down
22 changes: 6 additions & 16 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,10 @@

## 准备

拉取代码(同步拉取子模块)
拉取代码

```bash
git clone --recursive https://github.com/fan-ziqi/rl_sar.git
```

如有更新:

```bash
git pull
git submodule update --remote --recursive
git clone https://github.com/fan-ziqi/rl_sar.git
```

## 依赖
Expand Down Expand Up @@ -172,7 +165,6 @@ rosrun rl_sar rl_real_a1
bash kill_cyberdog.sh
```


## 添加你的机器人

下文中将ROBOT代表机器人名称
Expand All @@ -183,12 +175,10 @@ rosrun rl_sar rl_real_a1
4. 在rl_sar/launch文件夹中添加一个新的launch文件,请参考其他launch文件自行修改
5. 修改rl_xxx.cpp中的ROBOT_NAME为ROBOT
6. 编译运行
7. 若您的机器人关节力矩大于50Nm,则需要修改`rl_sar/src/unitree_ros/unitree_legged_control/src/joint_controller.cpp`中180行为:
```cpp
// calcTorque = computeTorque(currentPos, currentVel, servoCmd);
calcTorque = servoCmd.posStiffness * (servoCmd.pos - currentPos) + servoCmd.velStiffness * (servoCmd.vel - currentVel) + servoCmd.torque;
```
这样会解除50Nm的限制

## 参考

[unitree_ros](https://github.com/unitreerobotics/unitree_ros)

## 引用

Expand Down
5 changes: 2 additions & 3 deletions src/rl_sar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ find_package(catkin REQUIRED COMPONENTS
tf
geometry_msgs
robot_msgs
unitree_legged_msgs
robot_joint_controller
)

find_package(Python3 COMPONENTS Interpreter Development REQUIRED)
Expand All @@ -36,7 +36,7 @@ include_directories(${YAML_CPP_INCLUDE_DIR})

catkin_package(
CATKIN_DEPENDS
unitree_legged_msgs
robot_joint_controller
)

include_directories(library/unitree_legged_sdk_3.2/include)
Expand All @@ -50,7 +50,6 @@ include_directories(
include
${catkin_INCLUDE_DIRS}
${unitree_legged_sdk_INCLUDE_DIRS}
../unitree_controller/include
library/matplotlibcpp
library/observation_buffer
library/rl_sdk
Expand Down
5 changes: 0 additions & 5 deletions src/rl_sar/include/rl_real_a1.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#ifndef RL_REAL_HPP
#define RL_REAL_HPP

// #include "../library/rl_sdk/rl_sdk.hpp"
#include "rl_sdk.hpp"
#include "observation_buffer.hpp"
#include <unitree_legged_msgs/LowCmd.h>
#include "unitree_legged_msgs/LowState.h"
#include <unitree_legged_msgs/MotorCmd.h>
#include <unitree_legged_msgs/MotorState.h>
#include "unitree_legged_sdk/unitree_legged_sdk.h"
#include "unitree_legged_sdk/unitree_joystick.h"
#include <csignal>
Expand Down
6 changes: 2 additions & 4 deletions src/rl_sar/include/rl_sim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
#include <gazebo_msgs/ModelStates.h>
#include <sensor_msgs/JointState.h>
#include <geometry_msgs/Twist.h>
#include "unitree_legged_msgs/MotorCmd.h"
#include "unitree_legged_sdk/loop.h"
#include <csignal>

// #include "robot_msgs/MotorCommand.h"
#include "robot_msgs/MotorCommand.h"
// #include "robot_msgs/RobotState.h"
// #include "robot_msgs/RobotCommand.h"

Expand Down Expand Up @@ -53,9 +52,8 @@ class RL_Sim : public RL
ros::Subscriber cmd_vel_subscriber_;

std::map<std::string, ros::Publisher> torque_publishers;
std::vector<unitree_legged_msgs::MotorCmd> motor_commands;
std::vector<robot_msgs::MotorCommand> motor_commands;

// std::vector<robot_msgs::MotorCommand> motor_commands;
// robot_msgs::RobotState robot_state;
// robot_msgs::RobotCommand robot_command;

Expand Down
7 changes: 0 additions & 7 deletions src/rl_sar/launch/start_a1.launch
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,4 @@
<remap from="/joint_states" to="/$(arg rname)_gazebo/joint_states"/>
</node>

<!-- <node pkg="unitree_gazebo" type="servo" name="servo" required="true" output="screen"/> -->

<!-- load the parameter unitree_controller -->
<include file="$(find unitree_controller)/launch/set_ctrl.launch">
<arg name="rname" value="$(arg rname)"/>
</include>

</launch>
7 changes: 0 additions & 7 deletions src/rl_sar/launch/start_cyberdog.launch
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,4 @@
<remap from="/joint_states" to="/$(arg rname)_gazebo/joint_states"/>
</node>

<!-- <node pkg="unitree_gazebo" type="servo" name="servo" required="true" output="screen"/> -->

<!-- load the parameter unitree_controller -->
<include file="$(find unitree_controller)/launch/set_ctrl.launch">
<arg name="rname" value="$(arg rname)"/>
</include>

</launch>
2 changes: 1 addition & 1 deletion src/rl_sar/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<exec_depend>roscpp</exec_depend>
<exec_depend>std_msgs</exec_depend>
<depend>robot_msgs</depend>
<depend>unitree_legged_msgs</depend>
<depend>robot_joint_controller</depend>

<export>

Expand Down
7 changes: 3 additions & 4 deletions src/rl_sar/src/rl_sim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ RL_Sim::RL_Sim()

for (int i = 0; i < params.num_of_dofs; ++i)
{
torque_publishers[params.joint_names[i]] = nh.advertise<unitree_legged_msgs::MotorCmd>(
torque_publishers[params.joint_names[i]] = nh.advertise<robot_msgs::MotorCommand>(
ros_namespace + params.joint_names[i].substr(0, params.joint_names[i].size() - 6) + "_controller/command", 10);
}

Expand Down Expand Up @@ -94,13 +94,12 @@ void RL_Sim::RobotControl()
motiontime++;
for (int i = 0; i < params.num_of_dofs; ++i)
{
motor_commands[i].mode = 0x0A;
motor_commands[i].q = output_dof_pos[0][i].item<double>();
motor_commands[i].dq = 0;
// motor_commands[i].Kp = params.stiffness;
// motor_commands[i].Kd = params.damping;
motor_commands[i].Kp = params.p_gains[0][i].item<double>();
motor_commands[i].Kd = params.d_gains[0][i].item<double>();
motor_commands[i].kp = params.p_gains[0][i].item<double>();
motor_commands[i].kd = params.d_gains[0][i].item<double>();
// motor_commands[i].tau = output_torques[0][i].item<double>();
motor_commands[i].tau = 0;

Expand Down
31 changes: 31 additions & 0 deletions src/robot_joint_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 2.8.3)
project(robot_joint_controller)

find_package(catkin REQUIRED COMPONENTS
controller_interface
hardware_interface
pluginlib
roscpp
realtime_tools
robot_msgs
)

catkin_package(
CATKIN_DEPENDS
robot_msgs
controller_interface
hardware_interface
pluginlib
roscpp
INCLUDE_DIRS include
LIBRARIES ${PROJECT_NAME}
)

include_directories(include ${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIR})

link_directories(${catkin_LIB_DIRS} lib)

add_library(robot_joint_controller
src/robot_joint_controller.cpp
)
target_link_libraries(robot_joint_controller ${catkin_LIBRARIES})
75 changes: 75 additions & 0 deletions src/robot_joint_controller/include/robot_joint_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#ifndef ROBOT_JOINT_CONTROLLER_H
#define ROBOT_JOINT_CONTROLLER_H

#include <ros/node_handle.h>
#include <urdf/model.h>
#include <control_toolbox/pid.h>
#include <boost/scoped_ptr.hpp>
#include <boost/thread/condition.hpp>
#include <realtime_tools/realtime_publisher.h>
#include <hardware_interface/joint_command_interface.h>
#include <controller_interface/controller.h>
#include <std_msgs/Float64.h>
#include <realtime_tools/realtime_buffer.h>
#include <controller_interface/controller.h>
#include <hardware_interface/joint_command_interface.h>
#include "robot_msgs/MotorCommand.h"
#include "robot_msgs/MotorState.h"
#include <geometry_msgs/WrenchStamped.h>

#include <stdio.h>
#include <stdint.h>
#include <algorithm>
#include <math.h>

#define PosStopF (2.146E+9f)
#define VelStopF (16000.0f)

typedef struct
{
uint8_t mode;
double pos;
double posStiffness;
double vel;
double velStiffness;
double torque;
} ServoCommand;

namespace robot_joint_controller
{
class RobotJointController: public controller_interface::Controller<hardware_interface::EffortJointInterface>
{
private:
hardware_interface::JointHandle joint;
ros::Subscriber sub_command, sub_ft;
control_toolbox::Pid pid_controller_;
boost::scoped_ptr<realtime_tools::RealtimePublisher<robot_msgs::MotorState> > controller_state_publisher_ ;

public:
std::string name_space;
std::string joint_name;
urdf::JointConstSharedPtr joint_urdf;
realtime_tools::RealtimeBuffer<robot_msgs::MotorCommand> command;
robot_msgs::MotorCommand lastCommand;
robot_msgs::MotorState lastState;
ServoCommand servoCommand;

RobotJointController();
~RobotJointController();
virtual bool init(hardware_interface::EffortJointInterface *robot, ros::NodeHandle &n);
virtual void starting(const ros::Time& time);
virtual void update(const ros::Time& time, const ros::Duration& period);
virtual void stopping();
void setCommandCB(const robot_msgs::MotorCommandConstPtr& msg);
void positionLimits(double &position);
void velocityLimits(double &velocity);
void effortLimits(double &effort);

void setGains(const double &p, const double &i, const double &d, const double &i_max, const double &i_min, const bool &antiwindup = false);
void getGains(double &p, double &i, double &d, double &i_max, double &i_min, bool &antiwindup);
void getGains(double &p, double &i, double &d, double &i_max, double &i_min);

};
}

#endif
27 changes: 27 additions & 0 deletions src/robot_joint_controller/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<package format="2">
<name>robot_joint_controller</name>
<version>0.0.0</version>
<description>The robot_joint_controller package</description>
<maintainer email="[email protected]">Ziqi Fan</maintainer>
<license>Apache</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>controller_interface</build_depend>
<build_depend>hardware_interface</build_depend>
<build_depend>pluginlib</build_depend>
<build_depend>roscpp</build_depend>
<build_export_depend>controller_interface</build_export_depend>
<build_export_depend>hardware_interface</build_export_depend>
<build_export_depend>pluginlib</build_export_depend>
<build_export_depend>roscpp</build_export_depend>
<exec_depend>controller_interface</exec_depend>
<exec_depend>hardware_interface</exec_depend>
<exec_depend>pluginlib</exec_depend>
<exec_depend>roscpp</exec_depend>
<depend>robot_msgs</depend>
<!-- The export tag contains other, unspecified, tags -->
<export>
<!-- Other tools can request additional information be placed here -->
<controller_interface plugin="${prefix}/robot_joint_controller_plugins.xml"/>
</export>
</package>
8 changes: 8 additions & 0 deletions src/robot_joint_controller/robot_joint_controller_plugins.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<library path="lib/librobot_joint_controller">
<class name="robot_joint_controller/RobotJointController"
type="robot_joint_controller::RobotJointController"
base_class_type="controller_interface::ControllerBase"/>
<description>
The robot joint controller.
</description>
</library>
Loading

0 comments on commit 382702c

Please sign in to comment.