├── LICENSE
├── ReadMe.md
├── cyberdog_example
├── CMakeLists.txt
├── include
│ └── cyberdog_example
│ │ └── gamepad_lcmt.hpp
├── package.xml
└── src
│ ├── cyberdogmsg_sender.cpp
│ └── keybroad_commander.cpp
├── cyberdog_gazebo
├── CMakeLists.txt
├── config.h.cmake
├── include
│ ├── actuator.hpp
│ ├── ctrl_ros
│ │ ├── c_types.h
│ │ ├── control_parameters
│ │ │ ├── control_parameter_interface.hpp
│ │ │ ├── control_parameters.hpp
│ │ │ └── robot_parameters.hpp
│ │ ├── cpp_types.hpp
│ │ ├── parameters.hpp
│ │ ├── sim_utilities
│ │ │ ├── gamepad_command.hpp
│ │ │ ├── gamepad_lcmt.hpp
│ │ │ ├── imu_types.hpp
│ │ │ ├── simulator_message.hpp
│ │ │ ├── spine_board.hpp
│ │ │ └── visualization_data.hpp
│ │ └── utilities
│ │ │ ├── shared_memory.hpp
│ │ │ └── utilities.h
│ ├── cyberdog_sync_lcmt.hpp
│ ├── foot_contact_plugin.hpp
│ ├── gamepad_lcmt.hpp
│ ├── gazebo_foot_contact.hpp
│ ├── lcmhandler.hpp
│ ├── legged_plugin.hpp
│ ├── legged_simparam.hpp
│ ├── node_executor.hpp
│ └── simulator_lcmt.hpp
├── launch
│ ├── cyberdog_control_launch.py
│ ├── gazebo.launch.py
│ ├── gazebo_nav.launch.py
│ └── heightmap_gazebo.launch.py
├── media
│ └── materials
│ │ ├── CMakeLists.txt
│ │ └── textures
│ │ ├── CMakeLists.txt
│ │ ├── WoodPallet.png
│ │ ├── beigeWall.jpg
│ │ ├── ceiling_tiled.jpg
│ │ ├── clouds.jpg
│ │ ├── dirt_diffusespecular.png
│ │ ├── dirt_normal.png
│ │ ├── flat_normal.png
│ │ ├── fungus_diffusespecular.png
│ │ ├── fungus_normal.png
│ │ ├── granite.jpg
│ │ ├── granite2.jpg
│ │ ├── grass.jpg
│ │ ├── grass_diffusespecular.png
│ │ ├── grass_normal.png
│ │ ├── hardwood_floor.jpg
│ │ ├── motorway.jpg
│ │ ├── paintedWall.jpg
│ │ ├── pioneerBody.jpg
│ │ ├── primary.jpg
│ │ ├── projection_filter.png
│ │ ├── random.png
│ │ ├── residential.jpg
│ │ ├── secondary.jpg
│ │ ├── sidewalk.jpg
│ │ ├── steps.jpeg
│ │ ├── stereo_projection_pattern_high_res.png
│ │ ├── stereo_projection_pattern_high_res_red.png
│ │ ├── terrain.png
│ │ ├── texture_information.txt
│ │ ├── trunk.jpg
│ │ ├── white.bmp
│ │ ├── willowMap.png
│ │ └── wood.jpg
├── package.xml
├── script
│ ├── gazebolauncher.py
│ ├── launchcontrol.sh
│ ├── launchgazebo.sh
│ ├── launchsim.py
│ └── launchvisual.sh
├── src
│ ├── control_parameters
│ │ ├── control_parameter_interface.cpp
│ │ └── control_parameters.cpp
│ ├── foot_contact_plugin.cpp
│ ├── lcmhandler.cpp
│ ├── legged_plugin.cpp
│ ├── legged_simparam.cpp
│ ├── sim_utilities
│ │ └── spine_board.cpp
│ └── utilities
│ │ └── utilities.cpp
├── third-party
│ └── ParamHandler
│ │ ├── CMakeLists.txt
│ │ ├── LICENSE.txt
│ │ ├── ParamHandler.cpp
│ │ ├── ParamHandler.hpp
│ │ ├── README.md
│ │ ├── param_helper.hpp
│ │ └── src
│ │ ├── binary.cpp
│ │ ├── collectionstack.h
│ │ ├── contrib
│ │ ├── graphbuilder.cpp
│ │ ├── graphbuilderadapter.cpp
│ │ └── graphbuilderadapter.h
│ │ ├── convert.cpp
│ │ ├── directives.cpp
│ │ ├── directives.h
│ │ ├── emit.cpp
│ │ ├── emitfromevents.cpp
│ │ ├── emitter.cpp
│ │ ├── emitterstate.cpp
│ │ ├── emitterstate.h
│ │ ├── emitterutils.cpp
│ │ ├── emitterutils.h
│ │ ├── exceptions.cpp
│ │ ├── exp.cpp
│ │ ├── exp.h
│ │ ├── indentation.h
│ │ ├── memory.cpp
│ │ ├── node.cpp
│ │ ├── node_data.cpp
│ │ ├── nodebuilder.cpp
│ │ ├── nodebuilder.h
│ │ ├── nodeevents.cpp
│ │ ├── nodeevents.h
│ │ ├── null.cpp
│ │ ├── ostream_wrapper.cpp
│ │ ├── parse.cpp
│ │ ├── parser.cpp
│ │ ├── ptr_vector.h
│ │ ├── regex_yaml.cpp
│ │ ├── regex_yaml.h
│ │ ├── regeximpl.h
│ │ ├── scanner.cpp
│ │ ├── scanner.h
│ │ ├── scanscalar.cpp
│ │ ├── scanscalar.h
│ │ ├── scantag.cpp
│ │ ├── scantag.h
│ │ ├── scantoken.cpp
│ │ ├── setting.h
│ │ ├── simplekey.cpp
│ │ ├── singledocparser.cpp
│ │ ├── singledocparser.h
│ │ ├── stream.cpp
│ │ ├── stream.h
│ │ ├── streamcharsource.h
│ │ ├── stringsource.h
│ │ ├── tag.cpp
│ │ ├── tag.h
│ │ └── token.h
└── world
│ ├── heightmap.world
│ └── simple.world
├── cyberdog_msg
├── CMakeLists.txt
├── msg
│ ├── ApplyForce.msg
│ └── YamlParam.msg
└── package.xml
├── cyberdog_robot
└── cyberdog_description
│ ├── CMakeLists.txt
│ ├── launch
│ ├── cyberdog.launch.py
│ └── cyberdog_description.launch.py
│ ├── meshes
│ ├── abad.dae
│ ├── body.dae
│ ├── hip.dae
│ ├── hip_mirror.dae
│ └── knee.dae
│ ├── package.xml
│ ├── rviz
│ └── cyberdog.rviz
│ └── xacro
│ ├── const.xacro
│ ├── gazebo.xacro
│ ├── leg.xacro
│ ├── robot.xacro
│ └── transmission.xacro
├── cyberdog_simulator
├── CMakeLists.txt
└── package.xml
└── cyberdog_visual
├── CMakeLists.txt
├── include
└── cyberdog_visual
│ └── cyberdog_visual.hpp
├── launch
├── cyberdog_lcm_repaly.launch.py
└── cyberdog_visual.launch.py
├── lcm_type
├── leg_control_data_lcmt.hpp
├── localization_lcmt.hpp
├── simulator_lcmt.hpp
└── state_estimator_lcmt.hpp
├── package.xml
├── rviz
├── config.rviz
├── cyberdog_visual2.rviz
└── cyberdog_visual_replay.rviz
└── src
├── cyberdog_visual.cpp
└── cyberdog_visual_node.cpp
/ReadMe.md:
--------------------------------------------------------------------------------
1 | # CyberDog simulator
2 |
3 | 该仿真平台使用gazebo plugin的形式,消除ros通信不同步对控制的影响。同时,提供了基于Rviz2的可视化工具,将机器人状态的lcm数据转发到ROS。
4 | 该仿真平台需和cyberdog_locomotion仓通信进行使用,建议通过cyberdog_sim仓进行安装
5 |
6 | 详细信息可参照[**仿真平台文档**](https://miroboticslab.github.io/blogs/#/cn/cyberdog_gazebo_cn)
7 |
8 | 推荐安装环境: Ubuntu 20.04 + ROS2 Galactic
9 |
10 | ## 依赖安装
11 | 运行仿真平台需要安装如下的依赖
12 | **ros2_Galactic**
13 | ```
14 | $ sudo apt update && sudo apt install curl gnupg lsb-release
15 | $ sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
16 | $ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
17 | $ sudo apt update
18 | $ sudo apt install ros-galactic-desktop
19 | ```
20 | **Gazebo**
21 | ```
22 | $ curl -sSL http://get.gazebosim.org | sh
23 | $ sudo apt install ros-galactic-gazebo-ros
24 | $ sudo apt install ros-galactic-gazebo-msgs
25 | ```
26 | **LCM**
27 | ```
28 | $ git clone https://github.com/lcm-proj/lcm.git
29 | $ cd lcm
30 | $ mkdir build
31 | $ cd build
32 | $ cmake -DLCM_ENABLE_JAVA=ON ..
33 | $ make
34 | $ sudo make install
35 | ```
36 | **Eigen**
37 | ```
38 | $ git clone https://github.com/eigenteam/eigen-git-mirror
39 | $ cd eigen-git-mirror
40 | $ mkdir build
41 | $ cd build
42 | $ cmake ..
43 | $ sudo make install
44 | ```
45 | **xacro**
46 | ```
47 | $ sudo apt install ros-galactic-xacro
48 | ```
49 |
50 | **vcstool**
51 | ```
52 | $ sudo apt install python3-vcstool
53 | ```
54 |
55 | **colcon**
56 | ```
57 | $ sudo apt install python3-colcon-common-extensions
58 | ```
59 |
60 | 注意:若环境中安装有其他版本的yaml-cpp,可能会与ros galactic 自带的yaml-cpp发生冲突,建议编译时环境中无其他版本yaml-cpp
61 |
62 | ## 下载
63 | ```
64 | $ git clone https://github.com/MiRoboticsLab/cyberdog_sim.git
65 | $ cd cyberdog_sim
66 | $ vcs import < cyberdog_sim.repos
67 | ```
68 | ## 编译
69 | 需要将src/cyberdog locomotion/CMakeLists.txt中的BUILD_ROS置为ON
70 | 然后需要在cyberdog_sim文件夹下进行编译
71 | ```
72 | $ source /opt/ros/galactic/setup.bash
73 | $ colcon build --merge-install --symlink-install --packages-up-to cyberdog_locomotion cyberdog_simulator
74 | ```
75 |
76 | ## 使用
77 | 需要在cyberdog_sim文件夹下运行
78 | ```
79 | $ python3 src/cyberdog_simulator/cyberdog_gazebo/script/launchsim.py
80 | ```
81 |
82 | ### 也可以通过以下命令分别运行各程序:
83 |
84 | 首先启动gazebo程序,于cyberdog_sim文件夹下进行如下操作:
85 | ```
86 | $ source /opt/ros/galactic/setup.bash
87 | $ source install/setup.bash
88 | $ ros2 launch cyberdog_gazebo gazebo.launch.py
89 | ```
90 | 也可通过如下命令打开激光雷达
91 | ```
92 | $ source /opt/ros/galactic/setup.bash
93 | $ source install/setup.bash
94 | $ ros2 launch cyberdog_gazebo gazebo.launch.py use_lidar:=true
95 | ```
96 |
97 | 然后启动cyberdog_locomotion仓的控制程序。在cyberdog_sim文件夹下运行:
98 | ```
99 | $ source /opt/ros/galactic/setup.bash
100 | $ source install/setup.bash
101 | $ ros2 launch cyberdog_gazebo cyberdog_control_launch.py
102 | ```
103 |
104 | 最后打开可视化界面,在cyberdog_sim文件夹下运行:
105 | ```
106 | $ source /opt/ros/galactic/setup.bash
107 | $ source install/setup.bash
108 | $ ros2 launch cyberdog_visual cyberdog_visual.launch.py
109 | ```
110 |
111 | ### 播放实机lcm log数据
112 | 该平台能够通过rviz2将实机的运动控制lcm数据进行播放和可视化。
113 | 操作方法如下:
114 | 运行lcm数据可视化界面,于cyberdog_sim文件夹下进行如下操作:
115 | ```
116 | $ source /opt/ros/galactic/setup.bash
117 | $ source install/setup.bash
118 | $ ros2 launch cyberdog_visual cyberdog_lcm_repaly.launch.py
119 | ```
120 | 打开可视化界面后,通过运行cyberdog_locomotion仓的script目录下的脚本播放lcm log数据。
121 | 于cyberdog_sim文件夹下进行如下操作:
122 | ```
123 | $ cd src/cyberdog_locomotion/scripts
124 | $ ./make_types.sh #初次使用时需要运行
125 | $ ./launch_lcm_logplayer.sh
126 | ```
127 | 运行后选择需要播放的lcm log文件,即可进行log数据的播放,此时通过rviz可视化界面能复现机器人的姿态。
128 |
--------------------------------------------------------------------------------
/cyberdog_example/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 | project(cyberdog_example)
3 |
4 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
5 | add_compile_options(-Wall -Wextra -Wpedantic)
6 | endif()
7 |
8 | # find dependencies
9 | find_package(ament_cmake REQUIRED)
10 | find_package(rclcpp REQUIRED)
11 | find_package(rclcpp_action REQUIRED)
12 | find_package(std_msgs REQUIRED)
13 | find_package(cyberdog_msg REQUIRED)
14 | find_package(lcm REQUIRED)
15 |
16 | include_directories(include)
17 |
18 | add_executable(cyberdogmsg_sender src/cyberdogmsg_sender.cpp)
19 | ament_target_dependencies(cyberdogmsg_sender rclcpp rclcpp_action cyberdog_msg)
20 |
21 | add_executable(keybroad_commander src/keybroad_commander.cpp)
22 | ament_target_dependencies(keybroad_commander rclcpp rclcpp_action cyberdog_msg)
23 | target_link_libraries(keybroad_commander lcm)
24 |
25 | ament_package()
26 |
--------------------------------------------------------------------------------
/cyberdog_example/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | cyberdog_example
5 | 0.0.0
6 | TODO: Package description
7 | ljh
8 | TODO: License declaration
9 |
10 | ament_cmake
11 |
12 | ament_lint_auto
13 | ament_lint_common
14 |
15 | cyberdog_msg
16 |
17 | std_msgs
18 | rclcpp
19 | rclcpp_action
20 |
21 |
22 | ament_cmake
23 |
24 |
25 |
--------------------------------------------------------------------------------
/cyberdog_example/src/cyberdogmsg_sender.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | enum class ControlParameterValueKind : uint64_t {
8 | kDOUBLE = 1,
9 | kS64 = 2,
10 | kVEC_X_DOUBLE = 3, // for template type derivation
11 | kMAT_X_DOUBLE = 4 // for template type derivation
12 | };
13 |
14 | class ExampleNode: public rclcpp::Node
15 | {
16 | public:
17 | ExampleNode(std::string node_name):Node(node_name){};
18 | ~ExampleNode(){};
19 | };
20 |
21 | int main(int argc, char** argv){
22 | rclcpp::init(argc, argv);
23 | auto example_node_=std::make_shared("cyberdogmsg_node");
24 | rclcpp::Publisher::SharedPtr para_pub_;
25 | rclcpp::Publisher::SharedPtr force_pub_;
26 |
27 | para_pub_=example_node_->create_publisher("yaml_parameter",10);
28 | force_pub_=example_node_->create_publisher("apply_force",10);
29 |
30 | auto param_message_ = cyberdog_msg::msg::YamlParam();
31 | auto force_message_ = cyberdog_msg::msg::ApplyForce();
32 |
33 | sleep(1);
34 |
35 | //send control mode to Gamepad_controller mode which can enable control from simulator program
36 | param_message_.name = "use_rc";
37 | param_message_.kind = uint64_t(ControlParameterValueKind::kS64);
38 | param_message_.s64_value = int64_t(0);
39 | param_message_.is_user = 0;
40 | para_pub_->publish(param_message_);
41 | std::cout<<"switch to gamepad control model..."<publish(param_message_);
52 | std::cout<<"recovery stand ..."<publish(param_message_);
62 | std::cout<<"locomotion ..."< rel_pos_;
68 | std::array force_;
69 | force_[2] = 20;
70 |
71 | force_message_.link_name = "FL_knee";
72 | force_message_.rel_pos = rel_pos_;
73 | force_message_.force = force_;
74 | force_message_.time = 2;
75 | force_pub_->publish(force_message_);
76 | std::cout<<"applying force on FL_knee ..."< vecxd_value_;
82 | vecxd_value_[0] = 0.2;
83 | vecxd_value_[2] = 0.25;
84 |
85 | param_message_.name = "des_roll_pitch_height";
86 | param_message_.kind = uint64_t(ControlParameterValueKind::kVEC_X_DOUBLE);
87 | param_message_.vecxd_value = vecxd_value_;
88 | param_message_.is_user = 1;
89 | para_pub_->publish(param_message_);
90 | std::cout<<"set roll angle to 0.2 ..."<publish(param_message_);
101 | std::cout<<"recovery stand ..."<
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "cyberdog_example/gamepad_lcmt.hpp"
8 |
9 | enum class ControlParameterValueKind : uint64_t {
10 | kDOUBLE = 1,
11 | kS64 = 2,
12 | kVEC_X_DOUBLE = 3, // for template type derivation
13 | kMAT_X_DOUBLE = 4 // for template type derivation
14 | };
15 |
16 | class ExampleNode: public rclcpp::Node
17 | {
18 | public:
19 | ExampleNode(std::string node_name):Node(node_name){};
20 | ~ExampleNode(){};
21 | };
22 |
23 | int main(int argc, char** argv){
24 | //initialize rclcpp
25 | rclcpp::init(argc, argv);
26 | auto example_node_=std::make_shared("kdcommand_node");
27 | rclcpp::Publisher::SharedPtr para_pub_;
28 | para_pub_=example_node_->create_publisher("yaml_parameter",10);
29 |
30 | auto param_message_ = cyberdog_msg::msg::YamlParam();
31 |
32 | sleep(1);
33 |
34 | //send control mode to Gamepad_controller mode which can enable control from simulator program
35 | param_message_.name = "use_rc";
36 | param_message_.kind = uint64_t(ControlParameterValueKind::kS64);
37 | param_message_.s64_value = int64_t(0);
38 | param_message_.is_user = 0;
39 | para_pub_->publish(param_message_);
40 | std::cout<<"switch to gamepad control model..."<> key;
56 | switch(key){
57 | case 'w': //x direction speed
58 | if(gamepad_lcm_type.leftStickAnalog[1]<0.9)
59 | gamepad_lcm_type.leftStickAnalog[1] += 0.1;
60 | break;
61 | case 's': //x direction speed
62 | if(gamepad_lcm_type.leftStickAnalog[1]>-0.9)
63 | gamepad_lcm_type.leftStickAnalog[1] += -0.1;
64 | break;
65 | case 'd': //y direction speed
66 | if(gamepad_lcm_type.leftStickAnalog[0]<0.9)
67 | gamepad_lcm_type.leftStickAnalog[0] += 0.1;
68 | break;
69 | case 'a': //y direction speed
70 | if(gamepad_lcm_type.leftStickAnalog[0]<0.9)
71 | gamepad_lcm_type.leftStickAnalog[0] += -0.1;
72 | break;
73 | case 'i': //pitch direction speed
74 | if(gamepad_lcm_type.rightStickAnalog[1]<0.9)
75 | gamepad_lcm_type.rightStickAnalog[1] += 0.1;
76 | break;
77 | case 'k': //pitch direction speed
78 | if(gamepad_lcm_type.rightStickAnalog[1]>-0.9)
79 | gamepad_lcm_type.rightStickAnalog[1] += -0.1;
80 | break;
81 | case 'j': //yaw direction speed
82 | if(gamepad_lcm_type.rightStickAnalog[0]<0.9)
83 | gamepad_lcm_type.rightStickAnalog[0] += 0.1;
84 | break;
85 | case 'l': //yaw direction speed
86 | if(gamepad_lcm_type.rightStickAnalog[0]>-0.9)
87 | gamepad_lcm_type.rightStickAnalog[0] += -0.1;
88 | break;
89 | case 'e': //QP stand
90 | gamepad_lcm_type.x = 1;
91 | break;
92 | case 'r': //locomotion
93 | gamepad_lcm_type.y = 1;
94 | break;
95 | case 't': //pure damper
96 | gamepad_lcm_type.a = 1;
97 | break;
98 | case 'y': //recoverystand
99 | gamepad_lcm_type.b = 1;
100 | break;
101 | case 'c': //clear speed of all direction
102 | gamepad_lcm_type.leftStickAnalog[0] = 0;
103 | gamepad_lcm_type.leftStickAnalog[1] = 0;
104 | gamepad_lcm_type.rightStickAnalog[0] = 0;
105 | gamepad_lcm_type.rightStickAnalog[1] = 0;
106 | break;
107 | }
108 |
109 | //publish lcm
110 | lcm_.publish("gamepad_lcmt",&gamepad_lcm_type);
111 |
112 | //clear button states
113 | gamepad_lcm_type.x = 0;
114 | gamepad_lcm_type.y = 0;
115 | gamepad_lcm_type.a = 0;
116 | gamepad_lcm_type.b = 0;
117 | }
118 |
119 |
120 | }
--------------------------------------------------------------------------------
/cyberdog_gazebo/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.5)
2 | project(cyberdog_gazebo)
3 |
4 | set(CMAKE_IGNORE_PATH "/usr/local")
5 |
6 | # Default to C99
7 | if(NOT CMAKE_C_STANDARD)
8 | set(CMAKE_C_STANDARD 99)
9 | endif()
10 |
11 | # Default to C++14
12 | if(NOT CMAKE_CXX_STANDARD)
13 | set(CMAKE_CXX_STANDARD 14)
14 | endif()
15 |
16 | if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
17 | add_compile_options(-Wall -Wextra -Wpedantic)
18 | endif()
19 |
20 | if(ONBOARD_BUILD)
21 | SET (THIS_COM "../" )
22 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
23 | ${CMAKE_BINARY_DIR}/Configuration.h)
24 | else(ONBOARD_BUILD)
25 | SET (THIS_COM "${PROJECT_SOURCE_DIR}/" )
26 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake
27 | ${CMAKE_BINARY_DIR}/Configuration.h)
28 | endif(ONBOARD_BUILD)
29 |
30 | # find dependencies
31 | find_package(ament_cmake REQUIRED)
32 | find_package(rosidl_default_generators REQUIRED)
33 | find_package(rosidl_typesupport_cpp REQUIRED)
34 | find_package(rclcpp REQUIRED)
35 | find_package(rclcpp_components REQUIRED)
36 | find_package(Eigen3 REQUIRED)
37 | find_package(gazebo_dev REQUIRED)
38 | find_package(gazebo_ros REQUIRED)
39 | find_package(gazebo_msgs REQUIRED)
40 | find_package(cyberdog_msg REQUIRED)
41 | find_package(lcm REQUIRED)
42 |
43 |
44 | set(dependencies
45 | rclcpp
46 | Eigen3
47 | gazebo_msgs
48 | gazebo_dev
49 | gazebo_ros
50 | cyberdog_msg
51 | )
52 |
53 | file(GLOB_RECURSE sources "src/control_parameters/*.cpp"
54 | "src/sim_utilities/*.cpp"
55 | "src/utilities/*.cpp")
56 |
57 | include_directories(include)
58 | include_directories(include/ctrl_ros)
59 | include_directories("third-party/ParamHandler")
60 | include_directories(${CMAKE_BINARY_DIR})
61 |
62 | add_subdirectory("third-party/ParamHandler")
63 |
64 | add_library(foot_contact_plugin SHARED src/foot_contact_plugin.cpp)
65 | ament_target_dependencies(foot_contact_plugin ${dependencies})
66 | target_link_libraries(foot_contact_plugin ${GAZEBO_LIBRARIES} lcm)
67 |
68 | add_library(legged_plugin SHARED ${sources} src/legged_plugin.cpp src/legged_simparam.cpp src/lcmhandler.cpp)
69 | ament_target_dependencies(legged_plugin ${dependencies})
70 | target_link_libraries(legged_plugin ${GAZEBO_LIBRARIES} param_handler pthread lcm)
71 |
72 | install(TARGETS legged_plugin param_handler foot_contact_plugin
73 | EXPORT export_${PROJECT_NAME}
74 | ARCHIVE DESTINATION lib
75 | LIBRARY DESTINATION lib
76 | RUNTIME DESTINATION bin
77 | )
78 |
79 | # Mark other files for installation
80 | install(
81 | DIRECTORY
82 | launch
83 | world
84 | DESTINATION share/${PROJECT_NAME}
85 | )
86 |
87 | ament_package()
88 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/config.h.cmake:
--------------------------------------------------------------------------------
1 | #ifndef CTRL_CONFIG_H
2 | #define CTRL_CONFIG_H
3 |
4 | #define THIS_COM "@THIS_COM@"
5 |
6 | #endif
7 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/ctrl_ros/c_types.h:
--------------------------------------------------------------------------------
1 | /*! @file c_types.h
2 | * @brief Common types that can also be included in C code
3 | *
4 | * This file contains types which are shared between C and C++ code. The
5 | * low-level drivers (rt folder) are all in C and everything else is C++.
6 | * Because this file is included in both C and C++, it can't contain C++ type
7 | * alias ("using"), namespaces, or templates.
8 | */
9 |
10 | #ifndef PROJECT_CTYPES_H
11 | #define PROJECT_CTYPES_H
12 |
13 | #include // for size_t
14 | #include
15 |
16 | // short version of the stdint default integer types
17 | typedef uint64_t u64;
18 | typedef uint32_t u32;
19 | typedef uint16_t u16;
20 | typedef uint8_t u8;
21 | typedef int8_t s8;
22 | typedef int16_t s16;
23 | typedef int32_t s32;
24 | typedef int64_t s64;
25 |
26 | #endif // PROJECT_CTYPES_H
27 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/ctrl_ros/control_parameters/robot_parameters.hpp:
--------------------------------------------------------------------------------
1 | #ifndef ROBOT_PARAMETERS_HPP_
2 | #define ROBOT_PARAMETERS_HPP_
3 |
4 | #include "control_parameters/control_parameters.hpp"
5 |
6 | /**
7 | * @brief ControlParameters shared among all robot controllers
8 | *
9 | */
10 | class RobotControlParameters : public ControlParameters {
11 | public:
12 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
13 |
14 | /**
15 | * @brief Construct RobotControlParameters
16 | */
17 | RobotControlParameters()
18 | : ControlParameters( "robot-parameters" ), INIT_PARAMETER( control_mode ), INIT_PARAMETER( gait_id ), INIT_PARAMETER( controller_dt ), INIT_PARAMETER( cheater_mode ),
19 | INIT_PARAMETER( imu_process_noise_position ), INIT_PARAMETER( imu_process_noise_velocity ), INIT_PARAMETER( foot_process_noise_position ), INIT_PARAMETER( foot_sensor_noise_position ),
20 | INIT_PARAMETER( foot_sensor_noise_velocity ), INIT_PARAMETER( foot_height_sensor_noise ), INIT_PARAMETER( use_rc ), INIT_PARAMETER( imu_bias_estimation ),
21 | INIT_PARAMETER( imu_adaptive_gain ), INIT_PARAMETER( gain_acc ), INIT_PARAMETER( speed_offset_trot_10_4 ), INIT_PARAMETER( speed_offset_trot_follow ),
22 | INIT_PARAMETER( speed_offset_trot_medium ), INIT_PARAMETER( speed_offset_trot_slow ), INIT_PARAMETER( speed_offset_trot_fast ), INIT_PARAMETER( speed_offset_trot_24_16 ),
23 | INIT_PARAMETER( speed_offset_trot_8_3 ), INIT_PARAMETER( speed_offset_ballet ), INIT_PARAMETER( speed_offset_bound ), INIT_PARAMETER( speed_offset_pronk ),
24 | INIT_PARAMETER( se_ori_cali_gain ), INIT_PARAMETER( se_ori_cali_offset ), INIT_PARAMETER( filter_type ), INIT_PARAMETER( delt_roll ), INIT_PARAMETER( delt_pitch ),
25 | INIT_PARAMETER( complementaryfilter_source ), INIT_PARAMETER( lcm_debug_switch ) {}
26 |
27 | DECLARE_PARAMETER( s64, control_mode )
28 | DECLARE_PARAMETER( s64, gait_id );
29 | DECLARE_PARAMETER( double, controller_dt )
30 |
31 | // state estimator
32 | DECLARE_PARAMETER( s64, cheater_mode )
33 | DECLARE_PARAMETER( double, imu_process_noise_position )
34 | DECLARE_PARAMETER( double, imu_process_noise_velocity )
35 | DECLARE_PARAMETER( double, foot_process_noise_position )
36 | DECLARE_PARAMETER( double, foot_sensor_noise_position )
37 | DECLARE_PARAMETER( double, foot_sensor_noise_velocity )
38 | DECLARE_PARAMETER( double, foot_height_sensor_noise )
39 |
40 | DECLARE_PARAMETER( s64, use_rc )
41 |
42 | DECLARE_PARAMETER( s64, imu_bias_estimation )
43 | DECLARE_PARAMETER( s64, imu_adaptive_gain )
44 | DECLARE_PARAMETER( double, gain_acc )
45 |
46 | DECLARE_PARAMETER( Vec3< double >, speed_offset_trot_10_4 );
47 | DECLARE_PARAMETER( Vec3< double >, speed_offset_trot_follow );
48 | DECLARE_PARAMETER( Vec3< double >, speed_offset_trot_medium );
49 | DECLARE_PARAMETER( Vec3< double >, speed_offset_trot_slow );
50 | DECLARE_PARAMETER( Vec3< double >, speed_offset_trot_fast );
51 | DECLARE_PARAMETER( Vec3< double >, speed_offset_trot_24_16 );
52 | DECLARE_PARAMETER( Vec3< double >, speed_offset_trot_8_3 );
53 | DECLARE_PARAMETER( Vec3< double >, speed_offset_ballet );
54 | DECLARE_PARAMETER( Vec3< double >, speed_offset_bound );
55 | DECLARE_PARAMETER( Vec3< double >, speed_offset_pronk );
56 | DECLARE_PARAMETER( Vec3< double >, se_ori_cali_gain );
57 | DECLARE_PARAMETER( Vec3< double >, se_ori_cali_offset );
58 |
59 | DECLARE_PARAMETER( s64, filter_type )
60 |
61 | DECLARE_PARAMETER( double, delt_roll )
62 | DECLARE_PARAMETER( double, delt_pitch )
63 | DECLARE_PARAMETER( double, complementaryfilter_source )
64 | DECLARE_PARAMETER( s64, lcm_debug_switch )
65 | };
66 |
67 | #endif // ROBOT_PARAMETERS_HPP_
68 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/ctrl_ros/cpp_types.hpp:
--------------------------------------------------------------------------------
1 | /*! @file c_types.h
2 | * @brief Common types that are only valid in C++
3 | *
4 | * This file contains types which are only used in C++ code. This includes
5 | * Eigen types, template types, aliases, ...
6 | */
7 |
8 | #ifndef PROJECT_CPPTYPES_H
9 | #define PROJECT_CPPTYPES_H
10 |
11 | // TODO: we MUST COMMIT IT
12 | #if defined (__APPLE__)
13 | #undef __ARM_NEON__
14 | #undef __ARM_NEON
15 | #endif
16 |
17 |
18 | #include
19 | #include "c_types.h"
20 | #include
21 |
22 | // Rotation Matrix
23 | template
24 | using RotMat = typename Eigen::Matrix;
25 |
26 | // 2x1 Vector
27 | template
28 | using Vec2 = typename Eigen::Matrix;
29 |
30 | // 3x1 Vector
31 | template
32 | using Vec3 = typename Eigen::Matrix;
33 |
34 | // 4x1 Vector
35 | template
36 | using Vec4 = typename Eigen::Matrix;
37 |
38 | // 6x1 Vector
39 | template
40 | using Vec6 = Eigen::Matrix;
41 |
42 | // 8x1 Vector
43 | template
44 | using Vec8 = Eigen::Matrix;
45 |
46 | // 9x1 Vector
47 | template
48 | using Vec9 = Eigen::Matrix;
49 |
50 | // 10x1 Vector
51 | template
52 | using Vec10 = Eigen::Matrix;
53 |
54 | // 12x1 Vector
55 | template
56 | using Vec12 = Eigen::Matrix;
57 |
58 | // 18x1 Vector
59 | template
60 | using Vec18 = Eigen::Matrix;
61 |
62 | // 24x1 vector
63 | template
64 | using Vec24 = Eigen::Matrix;
65 |
66 | // 28x1 vector
67 | template
68 | using Vec28 = Eigen::Matrix;
69 |
70 | template
71 | using VecX = Eigen::Matrix;
72 |
73 | // 3x3 Matrix
74 | template
75 | using Mat3 = typename Eigen::Matrix;
76 |
77 | // 4x1 Vector
78 | template
79 | using Quat = typename Eigen::Matrix;
80 |
81 | // Spatial Vector (6x1, all subspaces)
82 | template
83 | using SVec = typename Eigen::Matrix;
84 |
85 | // Spatial Transform (6x6)
86 | template
87 | using SXform = typename Eigen::Matrix;
88 |
89 | // 6x6 Matrix
90 | template
91 | using Mat6 = typename Eigen::Matrix;
92 |
93 | // 12x12 Matrix
94 | template
95 | using Mat12 = typename Eigen::Matrix;
96 |
97 | // 18x18 Matrix
98 | template
99 | using Mat18 = Eigen::Matrix;
100 |
101 | // 24x12 Matrix
102 | template
103 | using Mat2412 = Eigen::Matrix;
104 |
105 | // 28x28 Matrix
106 | template
107 | using Mat28 = Eigen::Matrix;
108 |
109 | // 3x4 Matrix
110 | template
111 | using Mat34 = Eigen::Matrix;
112 |
113 | // 3x4 Matrix
114 | template
115 | using Mat23 = Eigen::Matrix;
116 |
117 | // 4x4 Matrix
118 | template
119 | using Mat4 = typename Eigen::Matrix;
120 |
121 | // 10x1 Vector
122 | template
123 | using MassProperties = typename Eigen::Matrix;
124 |
125 | // Dynamically sized vector
126 | template
127 | using DVec = typename Eigen::Matrix;
128 |
129 | // Dynamically sized matrix
130 | template
131 | using DMat = typename Eigen::Matrix;
132 |
133 | // Dynamically sized matrix with spatial vector columns
134 | template
135 | using D6Mat = typename Eigen::Matrix;
136 |
137 | // Dynamically sized matrix with cartesian vector columns
138 | template
139 | using D3Mat = typename Eigen::Matrix;
140 |
141 | // std::vector (a list) of Eigen things
142 | template
143 | using vectorAligned = typename std::vector>;
144 |
145 | enum class RobotType { CYBERDOG, MINI_CYBERDOG };
146 |
147 | #endif // PROJECT_CPPTYPES_H
148 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/ctrl_ros/parameters.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by hujian on 2021/5/28.
3 | //
4 |
5 | #ifndef SIM_PARAMETERS_H
6 | #define SIM_PARAMETERS_H
7 |
8 | #define IMU_CALIBRATE_FILE_PATH "/mnt/misc/imu_calibrate_param.yaml"
9 |
10 | #define OFFSET_CALIBRATE_PARAM_FILE_PATH "/mnt/misc/offset_calibrate_param.yaml"
11 |
12 | #define POSE_CALIBRATE_PARAM_FILE_PATH "/mnt/misc/pose_calibrate_param.yaml"
13 |
14 | #define SPEED_CALIBRATE_FILE_PATH "/mnt/misc/speed_calibrate_param.yaml"
15 |
16 | #define SPEED_PARAMETER_CALIBRATE_CONTROL_DEBUG 1
17 |
18 | #define SPI_YAML_SH_PATH "/robot-software/config/mini-cheetah-spi.yaml"
19 | #define SPI_YAML_HAND_SH_PATH "/robot-software/config/mini-cheetah-spi-hand.yaml"
20 | #define SPI_YAML_HAND_SH_BAK_PATH "/robot-software/config/mini-cheetah-spi-hand.yaml.bak"
21 | #define MANAGER_SCRIPT_PATH "/mnt/UDISK/test/manager.sh"
22 |
23 | #define ROBOT_INTERFACE_UPDATE_PERIOD (1.f / 60.f)
24 | #define INTERFACE_LCM_NAME "interface"
25 | #define TIMES_TO_RESEND_CONTROL_PARAM 5
26 |
27 | #define K_WORDS_PER_MESSAGE 66
28 | #define ZERO_FLAG 0xdead
29 |
30 | #define BUDDA_Q_SCALE 6.f
31 |
32 | #define MAX_STACK_SIZE 16384 // 16KB of stack
33 | #define TASK_PRIORITY 49 // linux priority, this is not the nice value
34 |
35 | #define DEFAULT_TERRAIN_FILE "/default-terrain.yaml"
36 | #define DEFAULT_USER_FILE "/default-user-parameters-file.yaml"
37 |
38 | #define SIM_LCM_NAME "simulator_state"
39 |
40 | // Normal robot states
41 | #define K_PASSIVE 0
42 | #define K_BALANCE_STAND 3
43 | #define K_LOCOMOTION 4
44 | #define K_LOCOMOTION_TEST 5
45 | #define K_RECOVERY_STAND 6
46 | #define K_VISION 8
47 | #define K_BACKFLIP 9
48 | #define K_FRONTJUMP 11
49 | #define K_FRONTFLIP 12
50 |
51 | // Specific control states
52 | #define K_JOINT_PD 51
53 | #define K_IMPEDANCE_CONTROL 52
54 | #define K_MOTION 62
55 |
56 | //Extra control states
57 | #define K_PUREDAMPER_J 71
58 | #define K_INVALID 100
59 |
60 | // new gait
61 | #define K_Dance 101
62 | #define K_TwoLegStand_PD 302
63 |
64 | #define IMU_SERIAL_COM "/dev/ttyUSB0"
65 | #define BMS_SERIAL_COM "/dev/ttyS3"
66 |
67 | #define YAML_COLLECTION_NAME_KEY "__collection-name__"
68 |
69 | //all print control DEBUG
70 | #define PRINT_CONVEX_MPC_DEBUG 0
71 |
72 | #define GRAVITY 9.81
73 |
74 | #endif //SIM_PARAMETERS_H
75 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/ctrl_ros/sim_utilities/gamepad_command.hpp:
--------------------------------------------------------------------------------
1 | /*! @file gamepad_command.hpp
2 | * @brief The GamepadCommand type containing joystick information
3 | */
4 |
5 | #ifndef PROJECT_GAMEPADCOMMAND_H
6 | #define PROJECT_GAMEPADCOMMAND_H
7 |
8 | #include "utilities/utilities.h"
9 | #include "cpp_types.hpp"
10 | #include "gamepad_lcmt.hpp"
11 |
12 | //using namespace dreame_dog;
13 |
14 | /*!
15 | * The state of the gamepad
16 | */
17 | struct GamepadCommand {
18 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
19 |
20 | /*!
21 | * Construct a gamepad and set to zero.
22 | */
23 | GamepadCommand() { zero(); }
24 |
25 | bool leftBumper, rightBumper, leftTriggerButton, rightTriggerButton, back,
26 | start, a, b, x, y, leftStickButton, rightStickButton, logitechButton;
27 |
28 | Vec2 leftStickAnalog, rightStickAnalog;
29 | float leftTriggerAnalog, rightTriggerAnalog;
30 |
31 | /*!
32 | * Set all values to zero
33 | */
34 | void zero() {
35 | leftBumper = false;
36 | rightBumper = false;
37 | leftTriggerButton = false;
38 | rightTriggerButton = false;
39 | back = false;
40 | start = false;
41 | a = false;
42 | b = false;
43 | x = false;
44 | y = false;
45 | leftStickButton = false;
46 | rightStickButton = false;
47 |
48 | leftTriggerAnalog = 0;
49 | rightTriggerAnalog = 0;
50 | leftStickAnalog = Vec2::Zero();
51 | rightStickAnalog = Vec2::Zero();
52 | }
53 |
54 | /*!
55 | * Set the values from an LCM message
56 | * @param lcmt : LCM message
57 | */
58 | void set(const gamepad_lcmt* lcmt) {
59 | leftBumper = lcmt->leftBumper;
60 | rightBumper = lcmt->rightBumper;
61 | leftTriggerButton = lcmt->leftTriggerButton;
62 | rightTriggerButton = lcmt->rightTriggerButton;
63 | back = lcmt->back;
64 | start = lcmt->start;
65 | a = lcmt->a;
66 | x = lcmt->x;
67 | b = lcmt->b;
68 | y = lcmt->y;
69 | leftStickButton = lcmt->leftStickButton;
70 | rightStickButton = lcmt->rightStickButton;
71 | leftTriggerAnalog = lcmt->leftTriggerAnalog;
72 | rightTriggerAnalog = lcmt->rightTriggerAnalog;
73 | for (int i = 0; i < 2; i++) {
74 | leftStickAnalog[i] = lcmt->leftStickAnalog[i];
75 | rightStickAnalog[i] = lcmt->rightStickAnalog[i];
76 | }
77 | }
78 |
79 | /*!
80 | * Copy the values into an LCM message
81 | * @param lcmt : LCM message
82 | */
83 | void get(gamepad_lcmt* lcmt) {
84 | lcmt->leftBumper = leftBumper;
85 | lcmt->rightBumper = rightBumper;
86 | lcmt->leftTriggerButton = leftTriggerButton;
87 | lcmt->rightTriggerButton = rightTriggerButton;
88 | lcmt->back = back;
89 | lcmt->start = start;
90 | lcmt->a = a;
91 | lcmt->x = x;
92 | lcmt->b = b;
93 | lcmt->y = y;
94 | lcmt->leftStickButton = leftStickButton;
95 | lcmt->rightStickButton = rightStickButton;
96 | lcmt->leftTriggerAnalog = leftTriggerAnalog;
97 | lcmt->rightTriggerAnalog = rightTriggerAnalog;
98 | for (int i = 0; i < 2; i++) {
99 | lcmt->leftStickAnalog[i] = leftStickAnalog[i];
100 | lcmt->rightStickAnalog[i] = rightStickAnalog[i];
101 | }
102 | }
103 |
104 | /*!
105 | * The Logitech F310's seem to do a bad job of returning to zero exactly, so a
106 | * deadband around zero is useful when integrating joystick commands
107 | * @param f : The deadband
108 | */
109 | void GamepadApplyDeadband( float f ) {
110 | EigenApplyDeadband( leftStickAnalog, f );
111 | EigenApplyDeadband( rightStickAnalog, f );
112 | leftTriggerAnalog = ApplyDeadband( leftTriggerAnalog, f );
113 | rightTriggerAnalog = ApplyDeadband( rightTriggerAnalog, f );
114 | }
115 |
116 | /*!
117 | * Represent as human-readable string.
118 | * @return string representing state
119 | */
120 | std::string ToString() {
121 | std::string result = "Result:\nleftBumper: " + BoolToString( leftBumper ) + "\n" + "rightBumper: " + BoolToString( rightBumper ) + "\n"
122 | + "leftTriggerButton: " + BoolToString( leftTriggerButton ) + "\n" + "rightTriggerButton: " + BoolToString( rightTriggerButton ) + "\n" + "back: " + BoolToString( back )
123 | + "\n" + "start: " + BoolToString( start ) + "\n" + "a: " + BoolToString( a ) + "\n" + "b: " + BoolToString( b ) + "\n" + "x: " + BoolToString( x ) + "\n"
124 | + "y: " + BoolToString( y ) + "\n" + "leftStickButton: " + BoolToString( leftStickButton ) + "\n" + "rightStickButton: " + BoolToString( rightStickButton ) + "\n"
125 | + "leftTriggerAnalog: " + std::to_string( leftTriggerAnalog ) + "\n" + "rightTriggerAnalog: " + std::to_string( rightTriggerAnalog ) + "\n"
126 | + "leftStickAnalog: " + EigenToString( leftStickAnalog ) + "\n" + "rightStickAnalog: " + EigenToString( rightStickAnalog ) + "\n";
127 | return result;
128 | }
129 | };
130 |
131 | #endif // PROJECT_DRIVERCOMMAND_H
132 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/ctrl_ros/sim_utilities/imu_types.hpp:
--------------------------------------------------------------------------------
1 | /*! @file imu_types.hpp
2 | * @brief Data from IMUs
3 | */
4 |
5 | #ifndef PROJECT_IMUTYPES_H
6 | #define PROJECT_IMUTYPES_H
7 |
8 | #include "cpp_types.hpp"
9 |
10 | /*!
11 | * Mini Cheetah's IMU
12 | */
13 | struct VectorNavData {
14 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
15 |
16 | VectorNavData() {
17 | accelerometer = Vec3(0, 0, 9.81);
18 | gyro.setZero();
19 | quat = Quat(0, 0, 0, 1);
20 | }
21 |
22 | Vec3 accelerometer;
23 | Vec3 gyro;
24 | Quat quat;
25 | // todo is there status for the vectornav?
26 | };
27 |
28 | /*!
29 | * "Cheater" state sent to the robot from simulator
30 | */
31 | template
32 | struct CheaterState {
33 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
34 |
35 | Quat orientation;
36 | Vec3 position;
37 | Vec3 omegaBody;
38 | Vec3 vBody;
39 | Vec3 acceleration;
40 | };
41 |
42 | #endif // PROJECT_IMUTYPES_H
43 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/ctrl_ros/sim_utilities/simulator_message.hpp:
--------------------------------------------------------------------------------
1 | /*! @file simulator_message.hpp
2 | * @brief Messages sent to/from the development simulator
3 | *
4 | * These messsages contain all data that is exchanged between the robot program
5 | * and the simulator using shared memory. This is basically everything except
6 | * for debugging logs, which are handled by LCM instead
7 | */
8 |
9 | #ifndef PROJECT_SIMULATORTOROBOTMESSAGE_H
10 | #define PROJECT_SIMULATORTOROBOTMESSAGE_H
11 |
12 | #include "control_parameters/control_parameter_interface.hpp"
13 | #include "sim_utilities/gamepad_command.hpp"
14 | #include "sim_utilities/imu_types.hpp"
15 | #include "sim_utilities/spine_board.hpp"
16 | #include "sim_utilities/visualization_data.hpp"
17 | #include "utilities/shared_memory.hpp"
18 |
19 | /*!
20 | * The mode for the simulator
21 | */
22 | enum class SimulatorMode {
23 | RUN_CONTROL_PARAMETERS, // don't run the robot controller, just process
24 | // Control Parameters
25 | RUN_CONTROLLER, // run the robot controller
26 | DO_NOTHING, // just to check connection
27 | EXIT // quit!
28 | };
29 |
30 | /*!
31 | * A plain message from the simulator to the robot
32 | */
33 | struct SimulatorToRobotMessage {
34 | int value0[2];//value*: tmp for struct 8bytes alignment
35 |
36 | int value1;
37 |
38 | int value2;
39 | GamepadCommand gamepadCommand;// joystick
40 | RobotType robotType;// which robot the simulator thinks we are simulating
41 |
42 |
43 | // imu data
44 | VectorNavData vectorNav;
45 | CheaterState cheaterState;
46 |
47 | // leg data
48 | SpiData spiData;
49 | // TODO: remove tiboard related later
50 | // TiBoardData tiBoardData[4];
51 | ControlParameterRequest controlParameterRequest;
52 |
53 | SimulatorMode mode;
54 | //int value2;
55 | };
56 |
57 | /*!
58 | * A plain message from the robot to the simulator
59 | */
60 | struct RobotToSimulatorMessage {
61 |
62 | RobotType robotType;
63 | SpiCommand spiCommand;
64 | // TiBoardCommand tiBoardCommand[4];
65 |
66 | VisualizationData visualizationData;
67 | CheetahVisualization mainCheetahVisualization;
68 | ControlParameterResponse controlParameterResponse;
69 |
70 | char errorMessage[2056];
71 | };
72 |
73 | /*!
74 | * All the data shared between the robot and the simulator
75 | */
76 | struct SimulatorMessage {
77 | RobotToSimulatorMessage robotToSim;
78 | SimulatorToRobotMessage simToRobot;
79 | };
80 |
81 | #endif // PROJECT_SIMULATORTOROBOTMESSAGE_H
82 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/ctrl_ros/sim_utilities/spine_board.hpp:
--------------------------------------------------------------------------------
1 | /*! @file spine_board.hpp
2 | * @brief Spine Board Code, used to simulate the SpineBoard.
3 | *
4 | * This is mostly a copy of the exact code that runs on the SpineBoard
5 | */
6 |
7 | #ifndef PROJECT_SPINEBOARD_H
8 | #define PROJECT_SPINEBOARD_H
9 |
10 | #include "c_types.h"
11 | #include
12 |
13 | /*!
14 | * Command to spine board
15 | */
16 | struct SpiCommand {
17 | float q_des_abad[4];
18 | float q_des_hip[4];
19 | float q_des_knee[4];
20 |
21 | float qd_des_abad[4];
22 | float qd_des_hip[4];
23 | float qd_des_knee[4];
24 |
25 | float kp_abad[4];
26 | float kp_hip[4];
27 | float kp_knee[4];
28 |
29 | float kd_abad[4];
30 | float kd_hip[4];
31 | float kd_knee[4];
32 |
33 | float tau_abad_ff[4];
34 | float tau_hip_ff[4];
35 | float tau_knee_ff[4];
36 |
37 | int32_t flags[4];
38 |
39 | explicit SpiCommand() {
40 | memset(this, 0, sizeof(SpiCommand));
41 | }
42 | };
43 |
44 | /*!
45 | * Data from spine board
46 | */
47 | struct SpiData {
48 | explicit SpiData() { memset(this, 0, sizeof(SpiData)); }
49 |
50 | float q_abad[4];
51 | float q_hip[4];
52 | float q_knee[4];
53 | float qd_abad[4];
54 | float qd_hip[4];
55 | float qd_knee[4];
56 | int32_t flags[12];
57 | int32_t spi_driver_status;
58 |
59 | float tau_abad[4];
60 | float tau_hip[4];
61 | float tau_knee[4];
62 |
63 | int16_t tmp_abad[ 4 ];
64 | int16_t tmp_hip[ 4 ];
65 | int16_t tmp_knee[ 4 ];
66 |
67 | uint8_t reserve[ 40 ];
68 | };
69 |
70 | /*!
71 | * Spine board control logic
72 | */
73 | class SpineBoard {
74 | public:
75 | SpineBoard() {}
76 | void init(float side_sign, s32 board);
77 | void run();
78 | void resetData();
79 | void resetCommand();
80 | SpiCommand* cmd = nullptr;
81 | SpiData* data = nullptr;
82 | float torque_out[3];
83 |
84 | private:
85 | float side_sign;
86 | s32 board_num;
87 | const float max_torque[3] = {17.f, 24.f, 26.f}; // TODO CHECK WITH BEN
88 | const float wimp_torque[3] = {6.f, 6.f, 6.f}; // TODO CHECK WITH BEN
89 | const float disabled_torque[3] = {0.f, 0.f, 0.f};
90 | const float q_limit_p[3] = {1.5f, 5.0f, 0.f};
91 | const float q_limit_n[3] = {-1.5f, -5.0f, 0.f};
92 | const float kp_softstop = 100.f;
93 | const float kd_softstop = 0.4f;
94 | s32 iter_counter = 0;
95 | };
96 |
97 | #endif // PROJECT_SPINEBOARD_H
98 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/ctrl_ros/sim_utilities/visualization_data.hpp:
--------------------------------------------------------------------------------
1 | /*! @file VisualizationData.h
2 | * @brief Data sent from robot code to simulator GUI for debugging
3 | *
4 | */
5 |
6 | #ifndef VISUALIZATION_DATA_H
7 | #define VISUALIZATION_DATA_H
8 |
9 | #define VISUALIZATION_MAX_PATH_POINTS 2000
10 | #define VISUALIZATION_MAX_PATHS 10
11 | #define VISUALIZATION_MAX_ITEMS 10000
12 | #define VISUALIZATION_MAX_CHEETAHS 0
13 |
14 | #define VISUALIZATION_MAX_MESHES 5
15 | #define VISUALIZATION_MAX_MESH_GRID 150
16 |
17 | #include "cpp_types.hpp"
18 |
19 | /*!
20 | * Debugging sphere
21 | */
22 | struct SphereVisualization {
23 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
24 |
25 | Vec3 position;
26 | Vec4 color;
27 | double radius;
28 | };
29 |
30 | /*!
31 | * Debugging box
32 | */
33 | struct BlockVisualization {
34 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
35 |
36 | Vec3 dimension;
37 | Vec3 corner_position;
38 | Vec3 rpy;
39 | Vec4 color;
40 | };
41 |
42 | /*!
43 | * Debugging arrow
44 | */
45 | struct ArrowVisualization {
46 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 |
48 | Vec3 base_position;
49 | Vec3 direction;
50 | Vec4 color;
51 | float head_width;
52 | float head_length;
53 | float shaft_width;
54 | };
55 |
56 | /*!
57 | * Debugging robot (draws the same type of robot as currently simulating)
58 | */
59 | struct CheetahVisualization {
60 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
61 |
62 | Vec12 q;
63 | Quat quat;
64 | Vec3 p;
65 | Vec4 color;
66 | };
67 |
68 | /*!
69 | * Debugging "path"
70 | */
71 | struct PathVisualization {
72 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
73 |
74 | size_t num_points = 0;
75 | Vec4 color;
76 | Vec3 position[VISUALIZATION_MAX_PATH_POINTS];
77 | void clear() {
78 | num_points = 0;
79 | }
80 | };
81 |
82 | /*!
83 | * Debugging Cone
84 | */
85 | struct ConeVisualization {
86 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
87 |
88 | Vec3 point_position;
89 | Vec3 direction;
90 | Vec4 color;
91 | double radius;
92 | };
93 |
94 | /*!
95 | * Mesh Visualization
96 | */
97 | struct MeshVisualization {
98 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW
99 |
100 | Vec3 left_corner;
101 | Eigen::Matrix height_map;
102 |
103 | int rows, cols;
104 |
105 | float grid_size;
106 | float height_max;
107 | float height_min;
108 | };
109 |
110 |
111 | /*!
112 | * Collection of all debugging data
113 | */
114 | struct VisualizationData {
115 | size_t num_paths = 0, num_arrows = 0, num_cones = 0, num_spheres = 0,
116 | num_blocks = 0, num_meshes = 0;
117 | SphereVisualization spheres[VISUALIZATION_MAX_ITEMS];
118 | BlockVisualization blocks[VISUALIZATION_MAX_ITEMS];
119 | ArrowVisualization arrows[VISUALIZATION_MAX_ITEMS];
120 | ConeVisualization cones[VISUALIZATION_MAX_ITEMS];
121 | PathVisualization paths[VISUALIZATION_MAX_PATHS];
122 | MeshVisualization meshes[VISUALIZATION_MAX_MESHES];
123 |
124 | /*!
125 | * Remove all debug data
126 | */
127 | void clear() {
128 | num_paths = 0, num_arrows = 0, num_cones = 0, num_spheres = 0, num_blocks = 0;
129 | num_meshes = 0;
130 | }
131 |
132 | /*!
133 | * Add a new sphere
134 | * @return A sphere, or nullptr if there isn't enough room
135 | */
136 | SphereVisualization* addSphere() {
137 | if(num_spheres < VISUALIZATION_MAX_ITEMS) {
138 | return &spheres[num_spheres++];
139 | }
140 | return nullptr;
141 | }
142 |
143 | /*!
144 | * Add a new box
145 | * @return A box, or nullptr if there isn't enough room
146 | */
147 | BlockVisualization* addBlock() {
148 | if(num_blocks < VISUALIZATION_MAX_ITEMS) {
149 | return &blocks[num_blocks++];
150 | }
151 | return nullptr;
152 | }
153 |
154 | /*!
155 | * Add a new arrow
156 | * @return An arrow, or nullptr if there isn't enough room
157 | */
158 | ArrowVisualization* addArrow() {
159 | if(num_arrows < VISUALIZATION_MAX_ITEMS) {
160 | return &arrows[num_arrows++];
161 | }
162 | return nullptr;
163 | }
164 |
165 | /*!
166 | * Add a new cone
167 | * @return A cone, or nullptr if there isn't enough room
168 | */
169 | ConeVisualization* addCone() {
170 | if(num_cones < VISUALIZATION_MAX_ITEMS) {
171 | return &cones[num_cones++];
172 | }
173 | return nullptr;
174 | }
175 |
176 | /*!
177 | * Add a new path
178 | * @return A path, or nullptr if there isn't enough room
179 | */
180 | PathVisualization* addPath() {
181 | if(num_paths < VISUALIZATION_MAX_PATHS) {
182 | auto* path = &paths[num_paths++];
183 | path->clear();
184 | return path;
185 | }
186 | return nullptr;
187 | }
188 |
189 | /*!
190 | * Add a new Mesh
191 | * @return A mesh, or nullptr if there isn't enough room
192 | */
193 | MeshVisualization* addMesh() {
194 | if(num_paths < VISUALIZATION_MAX_MESHES) {
195 | return &meshes[num_meshes++];
196 | }
197 | return nullptr;
198 | }
199 | };
200 |
201 | #endif
202 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/foot_contact_plugin.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023-2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #ifndef FOOT_CONTACT_PLUGIN_HPP
15 | #define FOOT_CONTACT_PLUGIN_HPP
16 |
17 | #include
18 |
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | #include "gazebo_foot_contact.hpp"
27 |
28 |
29 | namespace gazebo
30 | {
31 | class FootContactPlugin : public SensorPlugin
32 | {
33 |
34 | public:
35 | /**
36 | * @brief Construct a new Foot Contact Plugin object
37 | *
38 | */
39 | FootContactPlugin();
40 |
41 | /**
42 | * @brief Destroy the Foot Contact Plugin object
43 | *
44 | */
45 | virtual ~FootContactPlugin();
46 |
47 | /**
48 | * @brief Load the sensor plugin.
49 | *
50 | * @param _sensor Pointer to the sensor that loaded this plugin.
51 | * @param _sdf SDF element that describes the plugin.
52 | */
53 | virtual void Load(sensors::SensorPtr _sensor, sdf::ElementPtr _sdf);
54 |
55 | private:
56 | /**
57 | * @brief Callback that receives the contact sensor's update signal.
58 | *
59 | */
60 | virtual void OnUpdate();
61 |
62 | // Pointer to the contact sensor
63 | sensors::ContactSensorPtr parentSensor;
64 |
65 | // Connection that maintains a link between the contact sensor's
66 | // updated signal and the OnUpdate callback.
67 | event::ConnectionPtr updateConnection;
68 | };
69 | }
70 | #endif
71 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/gazebo_foot_contact.hpp:
--------------------------------------------------------------------------------
1 | /** THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY
2 | * BY HAND!!
3 | *
4 | * Generated by lcm-gen
5 | **/
6 |
7 | #ifndef __gazebo_foot_contact_hpp__
8 | #define __gazebo_foot_contact_hpp__
9 |
10 | #include
11 |
12 |
13 |
14 | class gazebo_foot_contact
15 | {
16 | public:
17 | double contact_force[12];
18 |
19 | double euler_angle[12];
20 |
21 | double contact_force_W[12];
22 |
23 | public:
24 | /**
25 | * Encode a message into binary form.
26 | *
27 | * @param buf The output buffer.
28 | * @param offset Encoding starts at thie byte offset into @p buf.
29 | * @param maxlen Maximum number of bytes to write. This should generally be
30 | * equal to getEncodedSize().
31 | * @return The number of bytes encoded, or <0 on error.
32 | */
33 | inline int encode(void *buf, int offset, int maxlen) const;
34 |
35 | /**
36 | * Check how many bytes are required to encode this message.
37 | */
38 | inline int getEncodedSize() const;
39 |
40 | /**
41 | * Decode a message from binary form into this instance.
42 | *
43 | * @param buf The buffer containing the encoded message.
44 | * @param offset The byte offset into @p buf where the encoded message starts.
45 | * @param maxlen The maximum number of bytes to read while decoding.
46 | * @return The number of bytes decoded, or <0 if an error occured.
47 | */
48 | inline int decode(const void *buf, int offset, int maxlen);
49 |
50 | /**
51 | * Retrieve the 64-bit fingerprint identifying the structure of the message.
52 | * Note that the fingerprint is the same for all instances of the same
53 | * message type, and is a fingerprint on the message type definition, not on
54 | * the message contents.
55 | */
56 | inline static int64_t getHash();
57 |
58 | /**
59 | * Returns "gazebo_foot_contact"
60 | */
61 | inline static const char* getTypeName();
62 |
63 | // LCM support functions. Users should not call these
64 | inline int _encodeNoHash(void *buf, int offset, int maxlen) const;
65 | inline int _getEncodedSizeNoHash() const;
66 | inline int _decodeNoHash(const void *buf, int offset, int maxlen);
67 | inline static uint64_t _computeHash(const __lcm_hash_ptr *p);
68 | };
69 |
70 | int gazebo_foot_contact::encode(void *buf, int offset, int maxlen) const
71 | {
72 | int pos = 0, tlen;
73 | int64_t hash = getHash();
74 |
75 | tlen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
76 | if(tlen < 0) return tlen; else pos += tlen;
77 |
78 | tlen = this->_encodeNoHash(buf, offset + pos, maxlen - pos);
79 | if (tlen < 0) return tlen; else pos += tlen;
80 |
81 | return pos;
82 | }
83 |
84 | int gazebo_foot_contact::decode(const void *buf, int offset, int maxlen)
85 | {
86 | int pos = 0, thislen;
87 |
88 | int64_t msg_hash;
89 | thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &msg_hash, 1);
90 | if (thislen < 0) return thislen; else pos += thislen;
91 | if (msg_hash != getHash()) return -1;
92 |
93 | thislen = this->_decodeNoHash(buf, offset + pos, maxlen - pos);
94 | if (thislen < 0) return thislen; else pos += thislen;
95 |
96 | return pos;
97 | }
98 |
99 | int gazebo_foot_contact::getEncodedSize() const
100 | {
101 | return 8 + _getEncodedSizeNoHash();
102 | }
103 |
104 | int64_t gazebo_foot_contact::getHash()
105 | {
106 | static int64_t hash = static_cast(_computeHash(NULL));
107 | return hash;
108 | }
109 |
110 | const char* gazebo_foot_contact::getTypeName()
111 | {
112 | return "gazebo_foot_contact";
113 | }
114 |
115 | int gazebo_foot_contact::_encodeNoHash(void *buf, int offset, int maxlen) const
116 | {
117 | int pos = 0, tlen;
118 |
119 | tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->contact_force[0], 12);
120 | if(tlen < 0) return tlen; else pos += tlen;
121 |
122 | tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->euler_angle[0], 12);
123 | if(tlen < 0) return tlen; else pos += tlen;
124 |
125 | tlen = __double_encode_array(buf, offset + pos, maxlen - pos, &this->contact_force_W[0], 12);
126 | if(tlen < 0) return tlen; else pos += tlen;
127 |
128 | return pos;
129 | }
130 |
131 | int gazebo_foot_contact::_decodeNoHash(const void *buf, int offset, int maxlen)
132 | {
133 | int pos = 0, tlen;
134 |
135 | tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->contact_force[0], 12);
136 | if(tlen < 0) return tlen; else pos += tlen;
137 |
138 | tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->euler_angle[0], 12);
139 | if(tlen < 0) return tlen; else pos += tlen;
140 |
141 | tlen = __double_decode_array(buf, offset + pos, maxlen - pos, &this->contact_force_W[0], 12);
142 | if(tlen < 0) return tlen; else pos += tlen;
143 |
144 | return pos;
145 | }
146 |
147 | int gazebo_foot_contact::_getEncodedSizeNoHash() const
148 | {
149 | int enc_size = 0;
150 | enc_size += __double_encoded_array_size(NULL, 12);
151 | enc_size += __double_encoded_array_size(NULL, 12);
152 | enc_size += __double_encoded_array_size(NULL, 12);
153 | return enc_size;
154 | }
155 |
156 | uint64_t gazebo_foot_contact::_computeHash(const __lcm_hash_ptr *)
157 | {
158 | uint64_t hash = 0xdb59eefda79a1cffLL;
159 | return (hash<<1) + ((hash>>63)&1);
160 | }
161 |
162 | #endif
163 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/lcmhandler.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023-2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #ifndef LCM_HANDLER_HPP__
15 | #define LCM_HANDLER_HPP__
16 |
17 | #include
18 |
19 | #include "simulator_lcmt.hpp"
20 | #include "gamepad_lcmt.hpp"
21 | #include "sim_utilities/gamepad_command.hpp"
22 |
23 |
24 | namespace gazebo
25 | {
26 | class LCMHandler
27 | {
28 | public:
29 |
30 | /**
31 | * @brief Construct a new LCMHandler object
32 | *
33 | */
34 | LCMHandler();
35 |
36 | /**
37 | * @brief Receive gamepad command messages
38 | *
39 | * @return GamepadCommand
40 | */
41 | GamepadCommand ReceiveGPC();
42 |
43 | /**
44 | * @brief Send simlator state message by lcm
45 | *
46 | * @param _lcm_sim_handler simlator state message
47 | */
48 | void SendSimData(simulator_lcmt &_lcm_sim_handler);
49 |
50 | /**
51 | * @brief Return true if lcmhandler receive a lcm message
52 | *
53 | * @return true Lcmhandler receive a lcm message
54 | * @return false No lcm message is received
55 | */
56 | bool HasEvent();
57 |
58 | private:
59 |
60 | /**
61 | * @brief Handle gamepad command messages
62 | *
63 | * @param rbuf
64 | * @param chan
65 | * @param msg
66 | */
67 | void HandleCommand(const lcm::ReceiveBuffer *rbuf, const std::string &chan, const gamepad_lcmt *msg);
68 |
69 | lcm::LCM lcm_;
70 | gamepad_lcmt lcm_gamepad_;
71 |
72 | GamepadCommand gamepad_command_;
73 | };
74 |
75 | }
76 |
77 | #endif //LCM_HANDLER_HPP__
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/legged_simparam.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023-2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #ifndef _LEGGED_SIMPARAM_HPP__
15 | #define _LEGGED_SIMPARAM_HPP__
16 |
17 | #include
18 |
19 | #include "rclcpp/rclcpp.hpp"
20 | #include
21 |
22 | #include "ctrl_ros/cpp_types.hpp"
23 | #include "utilities/shared_memory.hpp"
24 | #include "sim_utilities/simulator_message.hpp"
25 |
26 | #include "ctrl_ros/control_parameters/control_parameters.hpp"
27 | #include "ctrl_ros/control_parameters/robot_parameters.hpp"
28 | #include "node_executor.hpp"
29 |
30 | namespace gazebo
31 | {
32 | struct ParamHandler
33 | {
34 | std::string name;
35 | ControlParameterValueKind kind;
36 | ControlParameterValue value;
37 | };
38 |
39 | class SimParam
40 | {
41 | public:
42 | /**
43 | * @brief Construct a new Sim Param object
44 | *
45 | * @param model_name name of robot
46 | * @param node_executor node executor to subscribe yaml message
47 | */
48 | SimParam(std::string model_name, NodeExc* node_executor);
49 |
50 | /**
51 | * @brief Build connection to control program at the first run
52 | *
53 | */
54 | void FirstRun();
55 |
56 | /**
57 | * @brief Send sharedmemory data to control program
58 | *
59 | * @param _SimToRobot sharedmemory data to control program
60 | */
61 | void SendSMData(SimulatorToRobotMessage _SimToRobot);
62 |
63 | /**
64 | * @brief Receive sharedmemory data from control program
65 | *
66 | * @return SpiCommand sharedmemory data from control program
67 | */
68 | SpiCommand ReceiveSMData();
69 |
70 | /**
71 | * @brief Receive YamlParam topic message
72 | *
73 | */
74 | void ReceiveTopic();
75 |
76 | /**
77 | * @brief Set the LcmHasEvent if gamepad lcm message is received
78 | *
79 | * @return true Gamepad lcm message is received
80 | * @return false No gamepad lcm message is received
81 | */
82 | void LcmHasEvent(){lcm_has_event_ = true;};
83 |
84 | private:
85 |
86 | /**
87 | * @brief Load simulator and control parameter from yaml files
88 | *
89 | */
90 | void LoadYaml();
91 |
92 | /**
93 | * @brief Send ControlParameter by shared memory to control program
94 | *
95 | * @param name Name of ControlParameter
96 | * @param value Value of ControlParameter
97 | * @param kind Kind of ControlParameter
98 | * @param isUser true for userparameter
99 | * false for robotparameter
100 | */
101 | void SendControlParameter( const std::string& name, ControlParameterValue value, ControlParameterValueKind kind, bool isUser );
102 |
103 | /**
104 | * @brief Handle error message if control program has a error
105 | *
106 | */
107 | void HandleControlError();
108 |
109 | /**
110 | * @brief Handle YamlParam topic message
111 | *
112 | * @param msg YamlParam topic message
113 | */
114 | void HandleYamlParam(const cyberdog_msg::msg::YamlParam::SharedPtr msg);
115 |
116 |
117 | SharedMemoryObject shared_memory_;
118 |
119 | RobotType robotType;
120 | ControlParameters user_parameters_;
121 | RobotControlParameters robot_parameters_;
122 | bool lcm_has_event_;
123 |
124 | // ros2 node to receive YamlParam topic
125 | std::shared_ptr gazebo_node_;
126 | rclcpp::Subscription::SharedPtr para_sub_;
127 |
128 | NodeExc* node_executor_ = nullptr;
129 |
130 | std::function< void( std::string ) > error_callback_;
131 | bool running_ = false;
132 | bool connected_ = false;
133 | bool want_stop_ = false;
134 |
135 | };
136 | }
137 |
138 | #endif //_LEGGED_SIMPARAM_HPP__
--------------------------------------------------------------------------------
/cyberdog_gazebo/include/node_executor.hpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023-2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | #ifndef _NODE_EXCUTOR_HPP__
15 | #define _NODE_EXCUTOR_HPP__
16 |
17 | #include "rclcpp/rclcpp.hpp"
18 |
19 | namespace gazebo
20 | {
21 | class GazeboNode: public rclcpp::Node
22 | {
23 | public:
24 | /**
25 | * @brief Construct a new GazeboNode object to subscribe topic messages
26 | *
27 | * @param node_name
28 | */
29 | GazeboNode(std::string node_name):Node(node_name){};
30 | ~GazeboNode(){};
31 | };
32 |
33 | class NodeExc
34 | {
35 | public:
36 | /**
37 | * @brief Construct a new NodeExecutor object
38 | *
39 | */
40 | NodeExc(){}
41 |
42 | /**
43 | * @brief Add node into node executor
44 | *
45 | * @param node
46 | */
47 | void AddNode(std::shared_ptr node)
48 | {
49 | executor_.add_node(node);
50 | }
51 |
52 | /**
53 | * @brief Receive topics
54 | *
55 | */
56 | void ReceiveTopic()
57 | {
58 | using namespace std::chrono_literals;
59 | auto wait_time = 100ns;
60 | executor_.spin_once(wait_time);
61 | }
62 |
63 |
64 | private:
65 | rclcpp::executors::SingleThreadedExecutor executor_;
66 | };
67 |
68 |
69 | }
70 |
71 | #endif //_NODE_EXCUTOR_HPP__
--------------------------------------------------------------------------------
/cyberdog_gazebo/launch/cyberdog_control_launch.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 | #
3 | # Copyright (c) 2023-2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
4 |
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 |
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 |
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | import os
18 | import sys
19 |
20 | import launch
21 | import subprocess
22 | import launch_ros.actions
23 | from ament_index_python.packages import get_package_prefix
24 | from ament_index_python.packages import get_package_share_directory
25 | # from ament_index_python.packages import get_package_library_directory
26 |
27 | def generate_launch_description():
28 | # Get the launch directory
29 | library_dir = get_package_share_directory('cyberdog_locomotion')
30 | cmd_path = os.path.join(library_dir, "../../lib/cyberdog_locomotion")
31 |
32 | # cd
33 | # open_cmd = os.path.join("cd ", cmd_path)
34 | open_cmd = "cd " + cmd_path + " && ./cyberdog_control m s"
35 | print(open_cmd)
36 |
37 | os.system(open_cmd)
38 |
39 | ld = launch.LaunchDescription()
40 | return ld
41 |
42 | if __name__ == '__main__':
43 | generate_launch_description()
44 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/launch/heightmap_gazebo.launch.py:
--------------------------------------------------------------------------------
1 | import os
2 | from time import sleep
3 | import launch
4 | from launch.conditions import IfCondition, UnlessCondition
5 | from launch.launch_description_sources import PythonLaunchDescriptionSource
6 | from launch.substitutions import Command, LaunchConfiguration, PythonExpression
7 | from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription
8 | from launch.actions import OpaqueFunction
9 | from ament_index_python.packages import get_package_prefix
10 | from ament_index_python.packages import get_package_share_directory
11 | import xacro
12 |
13 |
14 | def launch_setup(context, *args, **kwargs):
15 | # pkg
16 | pkg_share = get_package_share_directory('cyberdog_gazebo')
17 | pkg_prefix = get_package_prefix('cyberdog_gazebo')
18 | pkg_gazebo_ros = get_package_share_directory('gazebo_ros')
19 |
20 | # config
21 | hang_robot = LaunchConfiguration('hang_robot').perform(context)
22 | use_lidar = LaunchConfiguration('use_lidar').perform(context)
23 | wname = LaunchConfiguration('wname').perform(context)
24 | rname = LaunchConfiguration('rname').perform(context)
25 |
26 | # env
27 | my_env = os.environ.copy()
28 | my_env["GAZEBO_MODEL_PATH"] = os.path.join(pkg_share, 'model')
29 | my_env["GAZEBO_PLUGIN_PATH"] = os.path.join(get_package_prefix('cyberdog_gazebo'), 'lib')
30 |
31 | # world
32 | world_path = os.path.join(pkg_share, 'world', wname+'.world')
33 |
34 | # urdf
35 | xacro_path = os.path.join(get_package_share_directory(
36 | rname+'_description'), 'xacro', 'robot.xacro')
37 | urdf_contents = xacro.process_file(xacro_path, mappings={
38 | 'DEBUG': hang_robot, 'USE_LIDAR': use_lidar}).toprettyxml(indent=' ')
39 |
40 | # spawn
41 | spawn_entity_message_contents = "'{initial_pose:{ position: {x: 0, y: 0, z: 0.6}, orientation: {x: 0.0, y: 0.0, z: 0.0, w: 1.0}}, name: \"robot\", xml: \"" + \
42 | urdf_contents.replace('"', '\\"') + "\"}'"
43 | spawn_entity = launch.actions.ExecuteProcess(
44 | name='spawn_entity', cmd=['ros2', 'service', 'call', '/spawn_entity', 'gazebo_msgs/SpawnEntity', spawn_entity_message_contents], env=my_env, shell=True, log_cmd=False)
45 |
46 | # gazebo server
47 | start_gazebo_server_cmd = IncludeLaunchDescription(
48 | PythonLaunchDescriptionSource(os.path.join(
49 | pkg_gazebo_ros, 'launch', 'gzserver.launch.py')),
50 | condition=IfCondition(LaunchConfiguration('use_simulator')),
51 | launch_arguments={
52 | 'world': world_path,
53 | 'debug': LaunchConfiguration('debug'),
54 | 'gui': LaunchConfiguration('gui'),
55 | 'paused': LaunchConfiguration('paused'),
56 | 'use_sim_time': LaunchConfiguration('use_sim_time'),
57 | 'headless': LaunchConfiguration('headless'),
58 | 'env': my_env
59 | }.items()
60 | )
61 |
62 | # gazebo client
63 | start_gazebo_client_cmd = IncludeLaunchDescription(
64 | PythonLaunchDescriptionSource(os.path.join(
65 | pkg_gazebo_ros, 'launch', 'gzclient.launch.py')),
66 | condition=IfCondition(PythonExpression(
67 | [LaunchConfiguration('use_simulator'), ' and not ', LaunchConfiguration('headless')]))
68 | )
69 |
70 | return [
71 | start_gazebo_server_cmd,
72 | start_gazebo_client_cmd,
73 | spawn_entity]
74 |
75 |
76 | def generate_launch_description():
77 | ld = launch.LaunchDescription([
78 | DeclareLaunchArgument(
79 | name='headless',
80 | default_value='False',
81 | description='Whether to execute gzclient'
82 | ),
83 | DeclareLaunchArgument(
84 | name='use_simulator',
85 | default_value='True',
86 | description='Whether to start the simulator'
87 | ),
88 | DeclareLaunchArgument(
89 | name='paused',
90 | default_value='true'
91 | ),
92 | DeclareLaunchArgument(
93 | name='use_sim_time',
94 | default_value='true'
95 | ),
96 | DeclareLaunchArgument(
97 | name='gui',
98 | default_value='true'
99 | ),
100 | DeclareLaunchArgument(
101 | name='debug',
102 | default_value='false'
103 | ),
104 | DeclareLaunchArgument(
105 | name='hang_robot',
106 | default_value='false'
107 | ),
108 | DeclareLaunchArgument(
109 | name='use_lidar',
110 | default_value='false'
111 | ),
112 | DeclareLaunchArgument(
113 | name='rname',
114 | default_value='cyberdog'
115 | ),
116 | DeclareLaunchArgument(
117 | name='wname',
118 | default_value='heightmap'
119 | ),
120 | OpaqueFunction(function=launch_setup)
121 | ])
122 | return ld
123 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | ADD_SUBDIRECTORY(textures)
2 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set (files
2 | beigeWall.jpg
3 | ceiling_tiled.jpg
4 | clouds.jpg
5 | dirt_diffusespecular.png
6 | dirt_normal.png
7 | flat_normal.png
8 | fungus_diffusespecular.png
9 | fungus_normal.png
10 | granite2.jpg
11 | granite.jpg
12 | grass_diffusespecular.png
13 | grass.jpg
14 | grass_normal.png
15 | hardwood_floor.jpg
16 | motorway.jpg
17 | paintedWall.jpg
18 | pioneerBody.jpg
19 | primary.jpg
20 | projection_filter.png
21 | random.png
22 | residential.jpg
23 | secondary.jpg
24 | sidewalk.jpg
25 | steps.jpeg
26 | stereo_projection_pattern_high_res.png
27 | stereo_projection_pattern_high_res_red.png
28 | terrain.png
29 | trunk.jpg
30 | white.bmp
31 | willowMap.png
32 | wood.jpg
33 | WoodPallet.png
34 | )
35 |
36 |
37 | INSTALL(FILES ${files} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/gazebo-${GAZEBO_VERSION}/media/materials/textures/)
38 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/WoodPallet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/WoodPallet.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/beigeWall.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/beigeWall.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/ceiling_tiled.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/ceiling_tiled.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/clouds.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/clouds.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/dirt_diffusespecular.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/dirt_diffusespecular.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/dirt_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/dirt_normal.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/flat_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/flat_normal.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/fungus_diffusespecular.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/fungus_diffusespecular.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/fungus_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/fungus_normal.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/granite.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/granite.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/granite2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/granite2.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/grass.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/grass.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/grass_diffusespecular.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/grass_diffusespecular.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/grass_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/grass_normal.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/hardwood_floor.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/hardwood_floor.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/motorway.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/motorway.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/paintedWall.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/paintedWall.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/pioneerBody.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/pioneerBody.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/primary.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/primary.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/projection_filter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/projection_filter.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/random.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/random.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/residential.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/residential.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/secondary.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/secondary.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/sidewalk.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/sidewalk.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/steps.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/steps.jpeg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/stereo_projection_pattern_high_res.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/stereo_projection_pattern_high_res.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/stereo_projection_pattern_high_res_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/stereo_projection_pattern_high_res_red.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/terrain.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/terrain.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/texture_information.txt:
--------------------------------------------------------------------------------
1 | Textures for roads were acquired from http://texturelib.com/.
2 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/trunk.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/trunk.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/white.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/white.bmp
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/willowMap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/willowMap.png
--------------------------------------------------------------------------------
/cyberdog_gazebo/media/materials/textures/wood.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MiRoboticsLab/cyberdog_simulator/da6383903b9591e15432284e9356d840fd334c66/cyberdog_gazebo/media/materials/textures/wood.jpg
--------------------------------------------------------------------------------
/cyberdog_gazebo/package.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | cyberdog_gazebo
5 | 0.0.0
6 | The cyberdog_gazebo package
7 |
8 | ljh
9 | You Yangwei
10 |
11 |
12 |
13 |
14 | Apache License, Version 2.0
15 |
16 | ament_cmake
17 |
18 | cyberdog_msg
19 |
20 | rclcpp
21 | gazebo_msgs
22 | gazebo_dev
23 | gazebo_ros
24 | yaml_cpp_vendor
25 |
26 |
27 | ament_cmake
28 |
29 |
30 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/script/gazebolauncher.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | # Copyright (c) 2023-2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
3 |
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 |
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 |
16 | import sys, signal, subprocess, time
17 |
18 |
19 | timeout_before_kill = 1.0 # [s]
20 | timeout_after_kill = 1.0 # [s]
21 |
22 |
23 | def signal_handler(sig, frame):
24 | print('killing gazebo')
25 | time.sleep(timeout_before_kill)
26 | subprocess.call("killall -q gzclient & killall -q gzserver", shell=True)
27 | time.sleep(timeout_after_kill)
28 | subprocess.call("killall -9 -q gzclient & killall -9 -q gzserver", shell=True)
29 | sys.exit(0)
30 |
31 |
32 | if __name__ == "__main__":
33 | signal.signal(signal.SIGINT, signal_handler)
34 | cmd = ' '.join(sys.argv[1:])
35 | print(cmd)
36 | subprocess.call(cmd, shell=True)
--------------------------------------------------------------------------------
/cyberdog_gazebo/script/launchcontrol.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | source /opt/ros/galactic/setup.bash
4 | source install/setup.bash
5 |
6 | ros2 launch cyberdog_gazebo cyberdog_control_launch.py
--------------------------------------------------------------------------------
/cyberdog_gazebo/script/launchgazebo.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | source /opt/ros/galactic/setup.bash
4 | source install/setup.bash
5 | chmod +x src/cyberdog_simulator/cyberdog_gazebo/script/gazebolauncher.py
6 |
7 | # ros2 launch cyberdog_gazebo gazebo.launch.py
8 | python3 src/cyberdog_simulator/cyberdog_gazebo/script/gazebolauncher.py ros2 launch cyberdog_gazebo gazebo.launch.py
--------------------------------------------------------------------------------
/cyberdog_gazebo/script/launchsim.py:
--------------------------------------------------------------------------------
1 | #!usr/bin/env python
2 |
3 | # Copyright (c) 2023-2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
4 |
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 |
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 |
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | import os
18 | import sys
19 | import time
20 |
21 | def launchsim():
22 |
23 | os.system('gnome-terminal -t "cyberdog_gazebo" -e "bash ./src/cyberdog_simulator/cyberdog_gazebo/script/launchgazebo.sh"')
24 | time.sleep(5)
25 | os.system('gnome-terminal -t "cyberdog_viusal" -e "bash ./src/cyberdog_simulator/cyberdog_gazebo/script/launchvisual.sh"')
26 | os.system('gnome-terminal -t "cyberdog_control" -e "bash ./src/cyberdog_simulator/cyberdog_gazebo/script/launchcontrol.sh"')
27 |
28 | if __name__=="__main__":
29 | launchsim()
30 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/script/launchvisual.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # gnome-terminal -t "cyberdog_gazebo" -x bash -c "source /opt/ros/galactic/setup.bash;source install/setup.bash;ros2 launch cyberdog_gazebo gazebo.launch.py rname:=l91_p1_1;exec bash;"
4 | source /opt/ros/galactic/setup.bash
5 | source install/setup.bash
6 |
7 | ros2 launch cyberdog_visual cyberdog_visual.launch.py
--------------------------------------------------------------------------------
/cyberdog_gazebo/src/control_parameters/control_parameter_interface.cpp:
--------------------------------------------------------------------------------
1 | /*! @file ControlParameterInterface.cpp
2 | * @brief Types to allow remote access of control parameters, for use with
3 | * LCM/Shared memory
4 | *
5 | * There are response/request messages. The robot receives request messages and
6 | * responds with response messages The request messages either request setting a
7 | * parameter or getting a parameter
8 | */
9 |
10 | #include "control_parameters/control_parameter_interface.hpp"
11 |
12 | /*!
13 | * Convert control parameter request kind into a string
14 | */
15 | std::string ControlParameterRequestKindToString( ControlParameterRequestKind request ) {
16 | switch ( request ) {
17 | case ControlParameterRequestKind::kGET_USER_PARAM_BY_NAME:
18 | return "get user";
19 | case ControlParameterRequestKind::kSET_USER_PARAM_BY_NAME:
20 | return "set user";
21 | case ControlParameterRequestKind::kGET_ROBOT_PARAM_BY_NAME:
22 | return "get robot";
23 | case ControlParameterRequestKind::kSET_ROBOT_PARAM_BY_NAME:
24 | return "set robot";
25 | case ControlParameterRequestKind::kGET_SPEED_CALIBRATE_PARAM_BY_NAME:
26 | return "get speed_calibrate";
27 | case ControlParameterRequestKind::kSET_SPEED_CALIBRATE_PARAM_BY_NAME:
28 | return "set speed_calibrate";
29 | case ControlParameterRequestKind::kGET_IMU_CALIBRATE_PARAM_BY_NAME:
30 | return "get imu_calibrate";
31 | case ControlParameterRequestKind::kSET_IMU_CALIBRATE_PARAM_BY_NAME:
32 | return "set imu_calibrate";
33 | default:
34 | return "unknown";
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/src/foot_contact_plugin.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023-2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "foot_contact_plugin.hpp"
16 |
17 | namespace gazebo
18 | {
19 |
20 | GZ_REGISTER_SENSOR_PLUGIN(FootContactPlugin)
21 |
22 | /////////////////////////////////////////////////
23 | FootContactPlugin::FootContactPlugin() : SensorPlugin()
24 | {
25 | }
26 |
27 | /////////////////////////////////////////////////
28 | FootContactPlugin::~FootContactPlugin()
29 | {
30 | }
31 |
32 | /////////////////////////////////////////////////
33 | void FootContactPlugin::Load(sensors::SensorPtr _sensor, sdf::ElementPtr /*_sdf*/)
34 | {
35 | // Get the parent sensor.
36 | this->parentSensor =
37 | std::dynamic_pointer_cast(_sensor);
38 |
39 | // Make sure the parent sensor is valid.
40 | if (!this->parentSensor)
41 | {
42 | gzerr << "FootContactPlugin requires a ContactSensor.\n";
43 | return;
44 | }
45 |
46 | // Connect to the sensor update event.
47 | this->updateConnection = this->parentSensor->ConnectUpdated(
48 | std::bind(&FootContactPlugin::OnUpdate, this));
49 |
50 | // Make sure the parent sensor is active.
51 | this->parentSensor->SetActive(true);
52 | }
53 |
54 | /////////////////////////////////////////////////
55 | void FootContactPlugin::OnUpdate() {}
56 |
57 |
58 |
59 | }
--------------------------------------------------------------------------------
/cyberdog_gazebo/src/lcmhandler.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (c) 2023-2023 Beijing Xiaomi Mobile Software Co., Ltd. All rights reserved.
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | #include "lcmhandler.hpp"
16 |
17 | namespace gazebo
18 | {
19 | LCMHandler::LCMHandler(){
20 | if (!lcm_.good()){
21 | exit(1);
22 | }
23 |
24 | lcm_.subscribe("gamepad_lcmt", &LCMHandler::HandleCommand, this);
25 |
26 | }
27 |
28 | GamepadCommand LCMHandler::ReceiveGPC()
29 | {
30 | lcm_.handle();
31 | gamepad_command_.a=lcm_gamepad_.a;
32 | gamepad_command_.b=lcm_gamepad_.b;
33 | gamepad_command_.x=lcm_gamepad_.x;
34 | gamepad_command_.y=lcm_gamepad_.y;
35 | gamepad_command_.leftStickAnalog[0]=lcm_gamepad_.leftStickAnalog[0];
36 | gamepad_command_.leftStickAnalog[1]=lcm_gamepad_.leftStickAnalog[1];
37 | gamepad_command_.rightStickAnalog[0]=lcm_gamepad_.rightStickAnalog[0];
38 | gamepad_command_.rightStickAnalog[1]=lcm_gamepad_.rightStickAnalog[1];
39 |
40 | return gamepad_command_;
41 | }
42 |
43 | void LCMHandler::HandleCommand(const lcm::ReceiveBuffer *rbuf, const std::string &chan, const gamepad_lcmt *msg)
44 | {
45 | lcm_gamepad_ = *msg;
46 | }
47 |
48 | bool LCMHandler::HasEvent()
49 | {
50 | // setup the LCM file descriptor for waiting.
51 | int lcm_fd = lcm_.getFileno();
52 | fd_set fds;
53 | FD_ZERO(&fds);
54 | FD_SET(lcm_fd, &fds);
55 |
56 | // wait a limited amount of time for an incoming message
57 | struct timeval timeout = {
58 | 0, // seconds
59 | 1 // microseconds
60 | };
61 | int status = select(lcm_fd + 1, &fds, 0, 0, &timeout);
62 |
63 | if (0 == status) {
64 | // no messages
65 | return false;
66 | }
67 | else if (FD_ISSET(lcm_fd, &fds)) {
68 | // LCM has events ready to be processed.
69 | return true;
70 | }
71 | else{
72 | // Undefined
73 | return false;
74 | }
75 | }
76 |
77 | void LCMHandler::SendSimData(simulator_lcmt &_lcm_sim_handler)
78 | {
79 | lcm_.publish("simulator_state", &_lcm_sim_handler);
80 | }
81 |
82 | }
--------------------------------------------------------------------------------
/cyberdog_gazebo/src/sim_utilities/spine_board.cpp:
--------------------------------------------------------------------------------
1 | /*! @file spine_board.cpp
2 | * @brief Spine Board Code, used to simulate the SpineBoard.
3 | */
4 |
5 | #include
6 |
7 | #include "sim_utilities/spine_board.hpp"
8 |
9 | /*!
10 | * Spine board setup (per board)
11 | */
12 | void SpineBoard::init(float sideSign, s32 board) {
13 | this->board_num = board;
14 | this->side_sign = sideSign;
15 | }
16 |
17 | /*!
18 | * Reset all data for the board
19 | */
20 | void SpineBoard::resetData() {
21 | if (data == nullptr) {
22 | printf(
23 | "[ERROR: SPINE board] reset_spine_board_data called when "
24 | "cheetahlcm_spi_data_t* was null\n");
25 | return;
26 | }
27 |
28 | data->flags[board_num] = 0;
29 | data->qd_abad[board_num] = 0.f;
30 | data->qd_hip[board_num] = 0.f;
31 | data->qd_knee[board_num] = 0.f;
32 | data->q_abad[board_num] = 0.f;
33 | data->q_hip[board_num] = 0.f;
34 | data->q_knee[board_num] = 0.f;
35 | data->spi_driver_status = 0;
36 | }
37 |
38 | /*!
39 | * Reset all commands for the board
40 | */
41 | void SpineBoard::resetCommand() {
42 | if (cmd == nullptr) {
43 | printf(
44 | "[ERROR: SPINE board] reset_spine_board_command called when "
45 | "cheetahlcm_spi_command_t* was null\n");
46 | return;
47 | }
48 |
49 | cmd->flags[board_num] = 0;
50 | cmd->kd_abad[board_num] = 0.f;
51 | cmd->kd_hip[board_num] = 0.f;
52 | cmd->kd_knee[board_num] = 0.f;
53 | cmd->kp_abad[board_num] = 0.f;
54 | cmd->kp_hip[board_num] = 0.f;
55 | cmd->kp_knee[board_num] = 0.f;
56 | cmd->qd_des_abad[board_num] = 0.f;
57 | cmd->qd_des_hip[board_num] = 0.f;
58 | cmd->qd_des_knee[board_num] = 0.f;
59 | cmd->q_des_abad[board_num] = 0.f;
60 | cmd->q_des_hip[board_num] = 0.f;
61 | cmd->q_des_knee[board_num] = 0.f;
62 | cmd->tau_abad_ff[board_num] = 0.f;
63 | cmd->tau_hip_ff[board_num] = 0.f;
64 | cmd->tau_hip_ff[board_num] = 0.f;
65 | cmd->tau_knee_ff[board_num] = 0.f;
66 | }
67 |
68 | /*!
69 | * Run spine board control
70 | */
71 | void SpineBoard::run() {
72 | iter_counter++;
73 | if (cmd == nullptr || data == nullptr) {
74 | printf(
75 | "[ERROR: SPINE board] run_spine_board_iteration called with null "
76 | "command or data!\n");
77 | torque_out[0] = 0.f;
78 | torque_out[1] = 0.f;
79 | torque_out[2] = 0.f;
80 | return;
81 | }
82 |
83 | /// Check abad softstop ///
84 | if (data->q_abad[board_num] > q_limit_p[0]) {
85 | torque_out[0] = kp_softstop * (q_limit_p[0] - data->q_abad[board_num]) -
86 | kd_softstop * (data->qd_abad[board_num]) +
87 | cmd->tau_abad_ff[board_num];
88 | } else if (data->q_abad[board_num] < q_limit_n[0]) {
89 | torque_out[0] = kp_softstop * (q_limit_n[0] - data->q_abad[board_num]) -
90 | kd_softstop * (data->qd_abad[board_num]) +
91 | cmd->tau_abad_ff[board_num];
92 | } else {
93 | torque_out[0] = cmd->kp_abad[board_num] *
94 | (cmd->q_des_abad[board_num] - data->q_abad[board_num]) +
95 | cmd->kd_abad[board_num] * (cmd->qd_des_abad[board_num] -
96 | data->qd_abad[board_num]) +
97 | cmd->tau_abad_ff[board_num];
98 | }
99 |
100 | /// Check hip softstop ///
101 | if (data->q_hip[board_num] > q_limit_p[1]) {
102 | torque_out[1] = kp_softstop * (q_limit_p[1] - data->q_hip[board_num]) -
103 | kd_softstop * (data->qd_hip[board_num]) +
104 | cmd->tau_hip_ff[board_num];
105 | } else if (data->q_hip[board_num] < q_limit_n[1]) {
106 | torque_out[1] = kp_softstop * (q_limit_n[1] - data->q_hip[board_num]) -
107 | kd_softstop * (data->qd_hip[board_num]) +
108 | cmd->tau_hip_ff[board_num];
109 | } else {
110 | torque_out[1] = cmd->kp_hip[board_num] *
111 | (cmd->q_des_hip[board_num] - data->q_hip[board_num]) +
112 | cmd->kd_hip[board_num] *
113 | (cmd->qd_des_hip[board_num] - data->qd_hip[board_num]) +
114 | cmd->tau_hip_ff[board_num];
115 | }
116 |
117 | /// No knee softstop right now ///
118 | torque_out[2] = cmd->kp_knee[board_num] *
119 | (cmd->q_des_knee[board_num] - data->q_knee[board_num]) +
120 | cmd->kd_knee[board_num] *
121 | (cmd->qd_des_knee[board_num] - data->qd_knee[board_num]) +
122 | cmd->tau_knee_ff[board_num];
123 |
124 | const float* torque_limits = disabled_torque;
125 |
126 | if (cmd->flags[board_num] & 0b1) {
127 | if (cmd->flags[board_num] & 0b10)
128 | torque_limits = wimp_torque;
129 | else
130 | torque_limits = max_torque;
131 | }
132 |
133 | for (int i = 0; i < 3; i++) {
134 | if (torque_out[i] > torque_limits[i]) torque_out[i] = torque_limits[i];
135 | if (torque_out[i] < -torque_limits[i]) torque_out[i] = -torque_limits[i];
136 | }
137 |
138 | }
139 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/src/utilities/utilities.cpp:
--------------------------------------------------------------------------------
1 | /*!
2 | * @file utilities.cpp
3 | * @brief Common utility functions
4 | */
5 |
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include "utilities/utilities.h"
12 | #include "Configuration.h"
13 |
14 |
15 | /**
16 | * @brief Write std::string to file with given name
17 | *
18 | * @param fileName
19 | * @param fileData
20 | */
21 | void WriteStringToFile( const std::string& fileName, const std::string& fileData ) {
22 | FILE* fp = fopen( fileName.c_str(), "w" );
23 | if ( !fp ) {
24 | printf( "Failed to fopen %s\n", fileName.c_str() );
25 | throw std::runtime_error( "Failed to open file" );
26 | }
27 | fprintf( fp, "%s", fileData.c_str() );
28 | fclose( fp );
29 | }
30 |
31 | /**
32 | * @brief Get the current time and return date object as a string
33 | *
34 | * @return std::string
35 | */
36 | std::string GetCurrentTimeAndDate() {
37 | auto t = std::time( nullptr );
38 | auto tm = *std::localtime( &t );
39 | std::ostringstream ss;
40 | ss << std::put_time( &tm, "%c" );
41 | return ss.str();
42 | }
43 |
44 | /**
45 | * @brief Return the path of config directory
46 | *
47 | * @return std::string
48 | */
49 | std::string GetConfigDirectoryPath() {
50 | return std::string( THIS_COM ) + "config/";
51 | }
52 |
53 | /**
54 | * @brief Return the path of config directory of control program
55 | *
56 | * @return std::string
57 | */
58 | std::string GetLocoConfigDirectoryPath() { return std::string( THIS_COM ) + "../../cyberdog_locomotion/common/config/"; }
59 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | find_package(yaml_cpp_vendor REQUIRED)
4 |
5 |
6 | option(PARAM_TEST "Build test programe for ParamHandler")
7 |
8 |
9 | set(YAML_CPP_INCLUDE_DIR "/opt/ros/galactic/opt/yaml_cpp_vendor/include")
10 | set(YAML_CPP_LIBRARIES "/opt/ros/galactic/opt/yaml_cpp_vendor/lib/libyaml-cpp.so")
11 |
12 | include_directories(${YAML_CPP_INCLUDE_DIR})
13 |
14 |
15 |
16 |
17 | ###
18 | ### Library
19 | ###
20 | add_library(param_handler SHARED
21 | ParamHandler.hpp
22 | ParamHandler.cpp
23 | )
24 |
25 |
26 |
27 |
28 | target_include_directories(param_handler PUBLIC
29 | ${YAML_CPP_INCLUDE_DIR}
30 | )
31 |
32 | target_link_libraries(param_handler
33 | ${YAML_CPP_LIBRARIES}
34 | )
35 |
36 | if (PARAM_TEST)
37 | add_executable(test_param
38 | test/test_param_main.cpp
39 | )
40 |
41 | target_link_libraries(test_param
42 | param_handler
43 | )
44 | endif()
45 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2008-2015 Jesse Beder.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/ParamHandler.cpp:
--------------------------------------------------------------------------------
1 | #include "ParamHandler.hpp"
2 | #include
3 |
4 | ParamHandler::ParamHandler(const std::string &file_name) {
5 | try {
6 | config_ = YAML::LoadFile(file_name);
7 | fileLoaded = true;
8 | } catch (std::exception& e) {
9 | fileLoaded = false;
10 | }
11 | }
12 |
13 | ParamHandler::~ParamHandler() {}
14 |
15 | bool ParamHandler::getString(const std::string &key, std::string &str_value) {
16 | try {
17 | str_value = config_[key].as();
18 | } catch (std::exception &e) {
19 | return false;
20 | }
21 | return true;
22 | }
23 |
24 | bool ParamHandler::getString(const std::string &category, const std::string &key, std::string &str_value) {
25 | try {
26 | str_value = config_[category][key].as();
27 | } catch(std::exception &e) {
28 | return false;
29 | }
30 | return true;
31 | }
32 |
33 | bool ParamHandler::getBoolean(const std::string &key, bool &bool_value) {
34 | try {
35 | bool_value = config_[key].as();
36 | } catch (std::exception &e) {
37 | return false;
38 | }
39 | return true;
40 | }
41 |
42 | bool ParamHandler::getInteger(const std::string &key, int &int_value) {
43 | try {
44 | int_value = config_[key].as();
45 | } catch (std::exception &e) {
46 | return false;
47 | }
48 | return true;
49 | }
50 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/ParamHandler.hpp:
--------------------------------------------------------------------------------
1 | #ifndef PARAMETER_HANDLER
2 | #define PARAMETER_HANDLER
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | using YAML::NodeType;
9 |
10 | class ParamHandler {
11 | public:
12 | ParamHandler(const std::string &file_name);
13 |
14 | virtual ~ParamHandler();
15 |
16 | bool getString(const std::string &key, std::string &str_value);
17 | bool getString(const std::string &category, const std::string &key, std::string & str_value);
18 |
19 | NodeType::value getType(const std::string& key) {
20 | return config_[key].Type();
21 | }
22 |
23 | template
24 | bool getVector(const std::string &key, std::vector &vec_value) {
25 | try {
26 | vec_value = config_[key].as >();
27 | } catch (std::exception &e) {
28 | return false;
29 | }
30 | return true;
31 | }
32 |
33 | template
34 | bool getVector(const std::string &category, const std::string &key, std::vector &vec_value) {
35 | try {
36 | vec_value = config_[category][key].as>();
37 | } catch (std::exception &e) {
38 | return false;
39 | }
40 | return true;
41 | }
42 |
43 | template
44 | bool get2DArray(const std::string &category, const std::string &key, std::vector > &vec_value) {
45 | try {
46 | vec_value = config_[category][key].as > >();
47 | } catch (std::exception &e) {
48 | return false;
49 | }
50 | return true;
51 | }
52 |
53 | template
54 | bool get2DArray(const std::string &key, std::vector > &vec_value) {
55 | try {
56 | vec_value = config_[key].as > >();
57 | } catch (std::exception &e) {
58 | return false;
59 | }
60 | return true;
61 | }
62 |
63 | template
64 | bool getValue(const std::string &key, T &T_value) {
65 | try {
66 | T_value = config_[key].as();
67 | } catch (std::exception &e) {
68 | return false;
69 | }
70 | return true;
71 | }
72 |
73 | template
74 | bool getValue(const std::string &category, const std::string &key, T &T_value) {
75 | try {
76 | T_value = config_[category][key].as();
77 | return true;
78 | } catch (std::exception &e) {
79 | return false;
80 | }
81 | return true;
82 | }
83 |
84 | bool getBoolean(const std::string & category, const std::string &key, bool &bool_value){
85 | try {
86 | bool_value = config_[category][key].as();
87 | return true;
88 | } catch (std::exception &e) {
89 | return false;
90 | }
91 | return true;
92 | }
93 |
94 |
95 | std::vector getKeys() {
96 | std::vector v;
97 | v.reserve(config_.size());
98 | for(auto it = config_.begin(); it != config_.end(); it++) {
99 | v.push_back(it->first.as());
100 | }
101 | return v;
102 | }
103 |
104 |
105 | bool getBoolean(const std::string &key, bool &bool_value);
106 |
107 | bool getInteger(const std::string &key, int &int_value);
108 |
109 | bool fileOpenedSuccessfully() {
110 | return fileLoaded;
111 | }
112 |
113 | protected:
114 | YAML::Node config_;
115 |
116 | private:
117 | bool fileLoaded = false;
118 | };
119 |
120 | #endif
121 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/README.md:
--------------------------------------------------------------------------------
1 | # yaml-cpp [](https://travis-ci.org/jbeder/yaml-cpp) [](https://codedocs.xyz/jbeder/yaml-cpp/)
2 |
3 | yaml-cpp is a [YAML](http://www.yaml.org/) parser and emitter in C++ matching the [YAML 1.2 spec](http://www.yaml.org/spec/1.2/spec.html).
4 |
5 | To get a feel for how it can be used, see the [Tutorial](https://github.com/jbeder/yaml-cpp/wiki/Tutorial) or [How to Emit YAML](https://github.com/jbeder/yaml-cpp/wiki/How-To-Emit-YAML). For the old API (version < 0.5.0), see [How To Parse A Document](https://github.com/jbeder/yaml-cpp/wiki/How-To-Parse-A-Document-(Old-API)).
6 |
7 | # Problems? #
8 |
9 | If you find a bug, post an [issue](https://github.com/jbeder/yaml-cpp/issues)! If you have questions about how to use yaml-cpp, please post it on http://stackoverflow.com and tag it [`yaml-cpp`](http://stackoverflow.com/questions/tagged/yaml-cpp).
10 |
11 | # How to Build #
12 |
13 | yaml-cpp uses [CMake](http://www.cmake.org) to support cross-platform building. The basic steps to build are:
14 |
15 | 1. Download and install [CMake](http://www.cmake.org) (Resources -> Download).
16 |
17 | **Note:** If you don't use the provided installer for your platform, make sure that you add CMake's bin folder to your path.
18 |
19 | 2. Navigate into the source directory, and type:
20 |
21 | ```
22 | mkdir build
23 | cd build
24 | ```
25 |
26 | 3. Run CMake. The basic syntax is:
27 |
28 | ```
29 | cmake [-G generator] [-DBUILD_SHARED_LIBS=ON|OFF] ..
30 | ```
31 |
32 | * The `generator` is whatever type of build system you'd like to use. To see a full list of generators on your platform, just run `cmake` (with no arguments). For example:
33 | * On Windows, you might use "Visual Studio 12 2013" to generate a Visual Studio 2013 solution or "Visual Studio 14 2015 Win64" to generate a 64-bit Visual Studio 2015 solution.
34 | * On OS X, you might use "Xcode" to generate an Xcode project
35 | * On a UNIX-y system, simply omit the option to generate a makefile
36 |
37 | * yaml-cpp defaults to building a static library, but you may build a shared library by specifying `-DBUILD_SHARED_LIBS=ON`.
38 |
39 | * For more options on customizing the build, see the [CMakeLists.txt](https://github.com/jbeder/yaml-cpp/blob/master/CMakeLists.txt) file.
40 |
41 | 4. Build it!
42 |
43 | 5. To clean up, just remove the `build` directory.
44 |
45 | # Recent Release #
46 |
47 | [yaml-cpp 0.5.3](https://github.com/jbeder/yaml-cpp/releases/tag/release-0.5.3) has been released! This is a bug fix release. It also will be the last release that uses Boost; futures releases will require C++11 instead.
48 |
49 | [yaml-cpp 0.3.0](https://github.com/jbeder/yaml-cpp/releases/tag/release-0.3.0) is still available if you want the old API.
50 |
51 | **The old API will continue to be supported, and will still receive bugfixes!** The 0.3.x and 0.4.x versions will be old API releases, and 0.5.x and above will all be new API releases.
52 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/param_helper.hpp:
--------------------------------------------------------------------------------
1 | /*!
2 | * @file param_helper.hpp
3 | * @brief some helper function for parameter parser
4 | *
5 | *
6 | * Authored by JackeyHuo, 2021-02-07
7 | */
8 |
9 | #ifndef PARAM_HELPER_H
10 | #define PARAM_HELPER_H
11 |
12 | #include
13 | #include
14 | #include
15 |
16 |
17 | template
18 | std::vector loadVectorFromString(const std::string& str_buff) {
19 | std::vector vv;
20 | try {
21 | YAML::Node node = YAML::Load(str_buff);
22 | vv = node.as>();
23 | } catch (std::exception& e) {
24 | // do nothing
25 | }
26 | return vv;
27 | }
28 |
29 | template
30 | std::vector> loadMatFromString(const std::string& str_buff) {
31 | std::vector> mm;
32 | try {
33 | YAML::Node node = YAML::Load(str_buff);
34 | mm = node.as>>();
35 | } catch (std::exception& e) {
36 | // do nothing
37 | }
38 | return mm;
39 | }
40 |
41 |
42 | #endif // PARAM_HELPER_H
43 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/src/binary.cpp:
--------------------------------------------------------------------------------
1 | #include "dynacore_yaml-cpp/binary.h"
2 |
3 | namespace dynacore_YAML {
4 | static const char encoding[] =
5 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
6 |
7 | std::string EncodeBase64(const unsigned char *data, std::size_t size) {
8 | const char PAD = '=';
9 |
10 | std::string ret;
11 | ret.resize(4 * size / 3 + 3);
12 | char *out = &ret[0];
13 |
14 | std::size_t chunks = size / 3;
15 | std::size_t remainder = size % 3;
16 |
17 | for (std::size_t i = 0; i < chunks; i++, data += 3) {
18 | *out++ = encoding[data[0] >> 2];
19 | *out++ = encoding[((data[0] & 0x3) << 4) | (data[1] >> 4)];
20 | *out++ = encoding[((data[1] & 0xf) << 2) | (data[2] >> 6)];
21 | *out++ = encoding[data[2] & 0x3f];
22 | }
23 |
24 | switch (remainder) {
25 | case 0:
26 | break;
27 | case 1:
28 | *out++ = encoding[data[0] >> 2];
29 | *out++ = encoding[((data[0] & 0x3) << 4)];
30 | *out++ = PAD;
31 | *out++ = PAD;
32 | break;
33 | case 2:
34 | *out++ = encoding[data[0] >> 2];
35 | *out++ = encoding[((data[0] & 0x3) << 4) | (data[1] >> 4)];
36 | *out++ = encoding[((data[1] & 0xf) << 2)];
37 | *out++ = PAD;
38 | break;
39 | }
40 |
41 | ret.resize(out - &ret[0]);
42 | return ret;
43 | }
44 |
45 | static const unsigned char decoding[] = {
46 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
47 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
48 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255,
49 | 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
50 | 255, 0, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
51 | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
52 | 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33,
53 | 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
54 | 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
55 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
56 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
57 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
58 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
59 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
60 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
61 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
62 | 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
63 | 255,
64 | };
65 |
66 | std::vector DecodeBase64(const std::string &input) {
67 | typedef std::vector ret_type;
68 | if (input.empty())
69 | return ret_type();
70 |
71 | ret_type ret(3 * input.size() / 4 + 1);
72 | unsigned char *out = &ret[0];
73 |
74 | unsigned value = 0;
75 | for (std::size_t i = 0; i < input.size(); i++) {
76 | unsigned char d = decoding[static_cast(input[i])];
77 | if (d == 255)
78 | return ret_type();
79 |
80 | value = (value << 6) | d;
81 | if (i % 4 == 3) {
82 | *out++ = value >> 16;
83 | if (i > 0 && input[i - 1] != '=')
84 | *out++ = value >> 8;
85 | if (input[i] != '=')
86 | *out++ = value;
87 | }
88 | }
89 |
90 | ret.resize(out - &ret[0]);
91 | return ret;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/src/collectionstack.h:
--------------------------------------------------------------------------------
1 | #ifndef COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 | #define COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3 |
4 | #if defined(_MSC_VER) || \
5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
7 | #pragma once
8 | #endif
9 |
10 | #include
11 | #include
12 |
13 | namespace dynacore_YAML {
14 | struct CollectionType {
15 | enum value { NoCollection, BlockMap, BlockSeq, FlowMap, FlowSeq, CompactMap };
16 | };
17 |
18 | class CollectionStack {
19 | public:
20 | CollectionType::value GetCurCollectionType() const {
21 | if (collectionStack.empty())
22 | return CollectionType::NoCollection;
23 | return collectionStack.top();
24 | }
25 |
26 | void PushCollectionType(CollectionType::value type) {
27 | collectionStack.push(type);
28 | }
29 | void PopCollectionType(CollectionType::value type) {
30 | assert(type == GetCurCollectionType());
31 | collectionStack.pop();
32 | }
33 |
34 | private:
35 | std::stack collectionStack;
36 | };
37 | }
38 |
39 | #endif // COLLECTIONSTACK_H_62B23520_7C8E_11DE_8A39_0800200C9A66
40 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/src/contrib/graphbuilder.cpp:
--------------------------------------------------------------------------------
1 | #include "graphbuilderadapter.h"
2 |
3 | #include "dynacore_yaml-cpp/parser.h" // IWYU pragma: keep
4 |
5 | namespace dynacore_YAML {
6 | class GraphBuilderInterface;
7 |
8 | void* BuildGraphOfNextDocument(Parser& parser,
9 | GraphBuilderInterface& graphBuilder) {
10 | GraphBuilderAdapter eventHandler(graphBuilder);
11 | if (parser.HandleNextDocument(eventHandler)) {
12 | return eventHandler.RootNode();
13 | } else {
14 | return NULL;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/src/contrib/graphbuilderadapter.cpp:
--------------------------------------------------------------------------------
1 | #include "graphbuilderadapter.h"
2 | #include "dynacore_yaml-cpp/contrib/graphbuilder.h"
3 |
4 | namespace dynacore_YAML {
5 | struct Mark;
6 |
7 | int GraphBuilderAdapter::ContainerFrame::sequenceMarker;
8 |
9 | void GraphBuilderAdapter::OnNull(const Mark &mark, anchor_t anchor) {
10 | void *pParent = GetCurrentParent();
11 | void *pNode = m_builder.NewNull(mark, pParent);
12 | RegisterAnchor(anchor, pNode);
13 |
14 | DispositionNode(pNode);
15 | }
16 |
17 | void GraphBuilderAdapter::OnAlias(const Mark &mark, anchor_t anchor) {
18 | void *pReffedNode = m_anchors.Get(anchor);
19 | DispositionNode(m_builder.AnchorReference(mark, pReffedNode));
20 | }
21 |
22 | void GraphBuilderAdapter::OnScalar(const Mark &mark, const std::string &tag,
23 | anchor_t anchor, const std::string &value) {
24 | void *pParent = GetCurrentParent();
25 | void *pNode = m_builder.NewScalar(mark, tag, pParent, value);
26 | RegisterAnchor(anchor, pNode);
27 |
28 | DispositionNode(pNode);
29 | }
30 |
31 | void GraphBuilderAdapter::OnSequenceStart(const Mark &mark,
32 | const std::string &tag,
33 | anchor_t anchor,
34 | EmitterStyle::value /* style */) {
35 | void *pNode = m_builder.NewSequence(mark, tag, GetCurrentParent());
36 | m_containers.push(ContainerFrame(pNode));
37 | RegisterAnchor(anchor, pNode);
38 | }
39 |
40 | void GraphBuilderAdapter::OnSequenceEnd() {
41 | void *pSequence = m_containers.top().pContainer;
42 | m_containers.pop();
43 |
44 | DispositionNode(pSequence);
45 | }
46 |
47 | void GraphBuilderAdapter::OnMapStart(const Mark &mark, const std::string &tag,
48 | anchor_t anchor,
49 | EmitterStyle::value /* style */) {
50 | void *pNode = m_builder.NewMap(mark, tag, GetCurrentParent());
51 | m_containers.push(ContainerFrame(pNode, m_pKeyNode));
52 | m_pKeyNode = NULL;
53 | RegisterAnchor(anchor, pNode);
54 | }
55 |
56 | void GraphBuilderAdapter::OnMapEnd() {
57 | void *pMap = m_containers.top().pContainer;
58 | m_pKeyNode = m_containers.top().pPrevKeyNode;
59 | m_containers.pop();
60 | DispositionNode(pMap);
61 | }
62 |
63 | void *GraphBuilderAdapter::GetCurrentParent() const {
64 | if (m_containers.empty()) {
65 | return NULL;
66 | }
67 | return m_containers.top().pContainer;
68 | }
69 |
70 | void GraphBuilderAdapter::RegisterAnchor(anchor_t anchor, void *pNode) {
71 | if (anchor) {
72 | m_anchors.Register(anchor, pNode);
73 | }
74 | }
75 |
76 | void GraphBuilderAdapter::DispositionNode(void *pNode) {
77 | if (m_containers.empty()) {
78 | m_pRootNode = pNode;
79 | return;
80 | }
81 |
82 | void *pContainer = m_containers.top().pContainer;
83 | if (m_containers.top().isMap()) {
84 | if (m_pKeyNode) {
85 | m_builder.AssignInMap(pContainer, m_pKeyNode, pNode);
86 | m_pKeyNode = NULL;
87 | } else {
88 | m_pKeyNode = pNode;
89 | }
90 | } else {
91 | m_builder.AppendToSequence(pContainer, pNode);
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/cyberdog_gazebo/third-party/ParamHandler/src/contrib/graphbuilderadapter.h:
--------------------------------------------------------------------------------
1 | #ifndef GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 | #define GRAPHBUILDERADAPTER_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3 |
4 | #if defined(_MSC_VER) || \
5 | (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
6 | (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
7 | #pragma once
8 | #endif
9 |
10 | #include
11 | #include