【ros2 control 机器人驱动开发】简单双关节机器人学习-example 1

【ros2 control 机器人驱动开发】简单双关节机器人学习-example 1

文章目录

  • 前言
  • 一、RR机器人
    • 创建description pkg
    • 创建demos pkg
  • 二、创建controller相关
    • 创建example pkg
  • 三、测试运行
  • 总结

前言

本系列文件主要有以下目标和内容:

  • 为系统、传感器和执行器创建 HardwareInterface
  • 以URDF文件的形式创建机器人描述
  • 加载配置并使用启动文件启动机器人
  • 控制RRBot的两个关节(两旋转关节机器人)
  • 六自由度机器人的控制
  • 实现机器人的控制器切换策略
  • 使用 ros2_control 中的关节限制和传输概念

一、RR机器人

RRBot( Revolute-Revolute Manipulator Robot)是一个简单的3连杆,2关节的机械臂,我们将使用它来演示各种功能。

它本质上是一个双倒立摆,并在模拟器中演示了一些有趣的控制概念,最初是为Gazebo教程介绍的。

创建description pkg

这里主要是完成机器人描述文件的创建,各个轴的物理尺寸、模型信息,各个轴的关节链接方式、链接点。

mkdir ~/ros2_control_demos
cd ~/ros2_control_demosros2 pkg create --build-type ament_cmake ros2_control_demo_description# 文件结构
$ tree ros2_control_demo_description/
ros2_control_demo_description/
├── CMakeLists.txt
├── package.xml
└── rrbot├── rviz│   └── rrbot.rviz└── urdf├── rrbot.materials.xacro└── rrbot_description.urdf.xacro
# CMakeLists.txtcmake_minimum_required(VERSION 3.8)
project(ros2_control_demo_description)if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")add_compile_options(-Wall -Wextra -Wpedantic)
endif()# find dependencies
find_package(ament_cmake REQUIRED)install(DIRECTORY rrbot/urdf rrbot/rvizDESTINATION share/${PROJECT_NAME}/rrbot
)ament_package()
# packages.xml<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3"><name>ros2_control_demo_description</name><version>0.0.0</version><description>TODO: Package description</description><maintainer email="https://blog.csdn.net/Bing_Lee">dev</maintainer><license>TODO: License declaration</license><buildtool_depend>ament_cmake</buildtool_depend><exec_depend>joint_state_publisher_gui</exec_depend><exec_depend>robot_state_publisher</exec_depend><exec_depend>rviz2</exec_depend>
</package>
# rrbot.rvizPanels:- Class: rviz_common/DisplaysHelp Height: 87Name: DisplaysProperty Tree Widget:Expanded: ~Splitter Ratio: 0.5Tree Height: 1096- Class: rviz_common/SelectionName: Selection- Class: rviz_common/Tool PropertiesExpanded:- /2D Goal Pose1- /Publish Point1Name: Tool PropertiesSplitter Ratio: 0.5886790156364441- Class: rviz_common/ViewsExpanded:- /Current View1Name: ViewsSplitter Ratio: 0.5
Visualization Manager:Class: ""Displays:- Alpha: 0.5Cell Size: 1Class: rviz_default_plugins/GridColor: 160; 160; 164Enabled: trueLine Style:Line Width: 0.029999999329447746Value: LinesName: GridNormal Cell Count: 0Offset:X: 0Y: 0Z: 0Plane: XYPlane Cell Count: 10Reference Frame: <Fixed Frame>Value: true- Alpha: 1Class: rviz_default_plugins/RobotModelCollision Enabled: falseDescription File: ""Description Source: TopicDescription Topic:Depth: 5Durability Policy: VolatileHistory Policy: Keep LastReliability Policy: ReliableValue: /robot_descriptionEnabled: trueLinks:All Links Enabled: trueExpand Joint Details: falseExpand Link Details: falseExpand Tree: falseLink Tree Style: Links in Alphabetic Orderbase_link:Alpha: 1Show Axes: falseShow Trail: falseValue: truecamera_link:Alpha: 1Show Axes: falseShow Trail: falseValue: truecamera_link_optical:Alpha: 1Show Axes: falseShow Trail: falsehokuyo_link:Alpha: 1Show Axes: falseShow Trail: falseValue: truelink1:Alpha: 1Show Axes: falseShow Trail: falseValue: truelink2:Alpha: 1Show Axes: falseShow Trail: falseValue: truetool_link:Alpha: 1Show Axes: falseShow Trail: falseworld:Alpha: 1Show Axes: falseShow Trail: falseMass Properties:Inertia: falseMass: falseName: RobotModelTF Prefix: ""Update Interval: 0Value: trueVisual Enabled: trueEnabled: trueGlobal Options:Background Color: 48; 48; 48Fixed Frame: base_linkFrame Rate: 30Name: rootTools:- Class: rviz_default_plugins/InteractHide Inactive Objects: true- Class: rviz_default_plugins/MoveCamera- Class: rviz_default_plugins/Select- Class: rviz_default_plugins/FocusCamera- Class: rviz_default_plugins/MeasureLine color: 128; 128; 0- Class: rviz_default_plugins/SetInitialPoseCovariance x: 0.25Covariance y: 0.25Covariance yaw: 0.06853891909122467Topic:Depth: 5Durability Policy: VolatileHistory Policy: Keep LastReliability Policy: ReliableValue: /initialpose- Class: rviz_default_plugins/SetGoalTopic:Depth: 5Durability Policy: VolatileHistory Policy: Keep LastReliability Policy: ReliableValue: /goal_pose- Class: rviz_default_plugins/PublishPointSingle click: trueTopic:Depth: 5Durability Policy: VolatileHistory Policy: Keep LastReliability Policy: ReliableValue: /clicked_pointTransformation:Current:Class: rviz_default_plugins/TFValue: trueViews:Current:Class: rviz_default_plugins/OrbitDistance: 8.443930625915527Enable Stereo Rendering:Stereo Eye Separation: 0.05999999865889549Stereo Focal Distance: 1Swap Stereo Eyes: falseValue: falseFocal Point:X: 0.0044944556429982185Y: 1.0785865783691406Z: 2.4839563369750977Focal Shape Fixed Size: trueFocal Shape Size: 0.05000000074505806Invert Z Axis: falseName: Current ViewNear Clip Distance: 0.009999999776482582Pitch: 0.23039916157722473Target Frame: <Fixed Frame>Value: Orbit (rviz)Yaw: 5.150422096252441Saved: ~
Window Geometry:Displays:collapsed: falseHeight: 1379Hide Left Dock: falseHide Right Dock: falseSelection:collapsed: falseTool Properties:collapsed: falseViews:collapsed: falseWidth: 2560X: 0Y: 1470
# rrbot_description.urdf.xacro<?xml version="1.0"?>
<robot xmlns:xacro="http://www.ros.org/wiki/xacro"><xacro:macro name="rrbot" params="parent prefix *origin"><!-- Constants for robot dimensions --><xacro:property name="mass" value="1" /> <!-- arbitrary value for mass --><xacro:property name="width" value="0.1" /> <!-- Square dimensions (widthxwidth) of beams --><xacro:property name="height1" value="2" /> <!-- Link 1 --><xacro:property name="height2" value="1" /> <!-- Link 2 --><xacro:property name="height3" value="1" /> <!-- Link 3 --><xacro:property name="axel_offset" value="0.05" /> <!-- Space btw top of beam and the each joint --><joint name="${prefix}base_joint" type="fixed"><xacro:insert_block name="origin" /><parent link="${parent}"/><child link="${prefix}base_link" /></joint><!-- Base Link --><link name="${prefix}base_link"><collision><origin xyz="0 0 ${height1/2}" rpy="0 0 0"/><geometry><box size="${width} ${width} ${height1}"/></geometry></collision><visual><origin xyz="0 0 ${height1/2}" rpy="0 0 0"/><geometry><box size="${width} ${width} ${height1}"/></geometry><material name="orange"/></visual></link><joint name="${prefix}joint1" type="continuous"><parent link="${prefix}base_link"/><child link="${prefix}link1"/><origin xyz="0 ${width} ${height1 - axel_offset}" rpy="0 0 0"/><axis xyz="0 1 0"/><dynamics damping="0.7"/></joint><!-- Middle Link --><link name="${prefix}link1"><collision><origin xyz="0 0 ${height2/2 - axel_offset}" rpy="0 0 0"/><geometry><box size="${width} ${width} ${height2}"/></geometry></collision><visual><origin xyz="0 0 ${height2/2 - axel_offset}" rpy="0 0 0"/><geometry><box size="${width} ${width} ${height2}"/></geometry><material name="yellow"/></visual></link><joint name="${prefix}joint2" type="continuous"><parent link="${prefix}link1"/><child link="${prefix}link2"/><origin xyz="0 ${width} ${height2 - axel_offset*2}" rpy="0 0 0"/><axis xyz="0 1 0"/><dynamics damping="0.7"/></joint><!-- Top Link --><link name="${prefix}link2"><collision><origin xyz="0 0 ${height3/2 - axel_offset}" rpy="0 0 0"/><geometry><box size="${width} ${width} ${height3}"/></geometry></collision><visual><origin xyz="0 0 ${height3/2 - axel_offset}" rpy="0 0 0"/><geometry><box size="${width} ${width} ${height3}"/></geometry><material name="orange"/></visual></link><joint name="${prefix}tool_joint" type="fixed"><origin xyz="0 0 1" rpy="0 0 0" /><parent link="${prefix}link2"/><child link="${prefix}tool_link" /></joint><!-- Tool Link --><link name="${prefix}tool_link"></link></xacro:macro></robot>
# rrbot.materials.xacro
<?xml version="1.0"?>
<!--
Copied from ROS1 example -
https://github.com/ros-simulation/gazebo_ros_demos/blob/kinetic-devel/rrbot_description/urdf/materials.xacro
-->
<robot><material name="black"><color rgba="0.0 0.0 0.0 1.0"/></material><material name="blue"><color rgba="0.0 0.0 0.8 1.0"/></material><material name="green"><color rgba="0.0 0.8 0.0 1.0"/></material><material name="grey"><color rgba="0.2 0.2 0.2 1.0"/></material><material name="orange"><color rgba="${255/255} ${108/255} ${10/255} 1.0"/></material><material name="brown"><color rgba="${222/255} ${207/255} ${195/255} 1.0"/></material><material name="red"><color rgba="0.8 0.0 0.0 1.0"/></material><material name="yellow"><color rgba="1.0 1.0 0.0 1.0"/></material><material name="white"><color rgba="1.0 1.0 1.0 1.0"/></material></robot>

创建demos pkg

这个包用于引导编译所有相关依赖包,按照下边格式填好即可。

cd ~/ros2_control_demosros2 pkg create --build-type ament_cmake ros2_control_demos# 文件结构
$ tree ros2_control_demos/
ros2_control_demos/
├── CMakeLists.txt
└── package.xml
# CMakeLists.txtcmake_minimum_required(VERSION 3.8)
project(ros2_control_demos)# find dependencies
find_package(ament_cmake REQUIRED)ament_package()
# package.xml<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3"><name>ros2_control_demos</name><version>0.0.0</version><description>TODO: Package description</description><maintainer email="https://blog.csdn.net/Bing_Lee">dev</maintainer><license>TODO: License declaration</license><buildtool_depend>ament_cmake</buildtool_depend><exec_depend>ros2_control_demo_example_1</exec_depend><export><build_type>ament_cmake</build_type></export>
</package>

二、创建controller相关

创建example pkg

cd ~/ros2_control_demosros2 pkg create --build-type ament_cmake ros2_control_demo_example_1

这里涉及hardware部分的实现,具体如下:

# robot.hpp// Copyright 2020 ros2_control Development Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.#ifndef ROS2_CONTROL_DEMO_EXAMPLE_1__RRBOT_HPP_
#define ROS2_CONTROL_DEMO_EXAMPLE_1__RRBOT_HPP_#include <memory>
#include <string>
#include <vector>#include "hardware_interface/handle.hpp"
#include "hardware_interface/hardware_info.hpp"
#include "hardware_interface/system_interface.hpp"
#include "hardware_interface/types/hardware_interface_return_values.hpp"
#include "rclcpp/macros.hpp"
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
#include "rclcpp_lifecycle/state.hpp"
#include "ros2_control_demo_example_1/visibility_control.h"namespace ros2_control_demo_example_1
{
class RRBotSystemPositionOnlyHardware : public hardware_interface::SystemInterface
{
public:RCLCPP_SHARED_PTR_DEFINITIONS(RRBotSystemPositionOnlyHardware);ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIChardware_interface::CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override;ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIChardware_interface::CallbackReturn on_configure(const rclcpp_lifecycle::State & previous_state) override;ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLICstd::vector<hardware_interface::StateInterface> export_state_interfaces() override;ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLICstd::vector<hardware_interface::CommandInterface> export_command_interfaces() override;ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIChardware_interface::CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIChardware_interface::CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIChardware_interface::return_type read(const rclcpp::Time & time, const rclcpp::Duration & period) override;ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIChardware_interface::return_type write(const rclcpp::Time & time, const rclcpp::Duration & period) override;private:// Parameters for the RRBot simulationdouble hw_start_sec_;double hw_stop_sec_;double hw_slowdown_;// Store the command for the simulated robotstd::vector<double> hw_commands_;std::vector<double> hw_states_;
};}  // namespace ros2_control_demo_example_1#endif  // ROS2_CONTROL_DEMO_EXAMPLE_1__RRBOT_HPP_
// Copyright 2021 ros2_control Development Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License./* This header must be included by all rclcpp headers which declare symbols* which are defined in the rclcpp library. When not building the rclcpp* library, i.e. when using the headers in other package's code, the contents* of this header change the visibility of certain symbols which the rclcpp* library cannot have, but the consuming code must have inorder to link.*/#ifndef ROS2_CONTROL_DEMO_EXAMPLE_1__VISIBILITY_CONTROL_H_
#define ROS2_CONTROL_DEMO_EXAMPLE_1__VISIBILITY_CONTROL_H_// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
//     https://gcc.gnu.org/wiki/Visibility#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define ROS2_CONTROL_DEMO_EXAMPLE_1_EXPORT __attribute__((dllexport))
#define ROS2_CONTROL_DEMO_EXAMPLE_1_IMPORT __attribute__((dllimport))
#else
#define ROS2_CONTROL_DEMO_EXAMPLE_1_EXPORT __declspec(dllexport)
#define ROS2_CONTROL_DEMO_EXAMPLE_1_IMPORT __declspec(dllimport)
#endif
#ifdef ROS2_CONTROL_DEMO_EXAMPLE_1_BUILDING_DLL
#define ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIC ROS2_CONTROL_DEMO_EXAMPLE_1_EXPORT
#else
#define ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIC ROS2_CONTROL_DEMO_EXAMPLE_1_IMPORT
#endif
#define ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIC_TYPE ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIC
#define ROS2_CONTROL_DEMO_EXAMPLE_1_LOCAL
#else
#define ROS2_CONTROL_DEMO_EXAMPLE_1_EXPORT __attribute__((visibility("default")))
#define ROS2_CONTROL_DEMO_EXAMPLE_1_IMPORT
#if __GNUC__ >= 4
#define ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIC __attribute__((visibility("default")))
#define ROS2_CONTROL_DEMO_EXAMPLE_1_LOCAL __attribute__((visibility("hidden")))
#else
#define ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIC
#define ROS2_CONTROL_DEMO_EXAMPLE_1_LOCAL
#endif
#define ROS2_CONTROL_DEMO_EXAMPLE_1_PUBLIC_TYPE
#endif#endif  // ROS2_CONTROL_DEMO_EXAMPLE_1__VISIBILITY_CONTROL_H_

attribute((visibility(“default”))) 是 GCC(GNU 编译器集合)中的一个特性,它允许程序员控制特定部分的代码的可见性。在 C 和 C++ 中,代码的可见性是指其他源文件能否访问特定的函数或变量。

当你在一个函数或变量声明中使用 attribute((visibility(“default”))),表示这个函数或变量默认对所有其他源文件可见。也就是说,这个函数或变量可以在其他源文件中被调用,或者被其他源文件中的变量间接引用。

这种特性在编写库和模块时非常有用,因为它允许程序员更灵活地组织和隐藏代码。例如,你可以创建一个库,其中包含一些默认可见的函数和变量,这些函数和变量可以被其他源文件调用,但不被直接暴露给用户。这种方式可以隐藏库的内部实现细节,同时仍然允许用户使用库的功能。

需要注意的是,attribute((visibility(“default”))) 并不是 C 或 C++ 标准的一部分,而是 GCC 编译器的一个特性。这意味着不是所有的编译器都会支持这个特性,特别是那些不支持 GCC 的编译器。此外,不同的编译器可能对 attribute((visibility)) 的行为有微小的差异,所以在使用这个特性时需要特别小心。

# robot.cpp// Copyright 2020 ros2_control Development Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.#include "ros2_control_demo_example_1/rrbot.hpp"#include <chrono>
#include <cmath>
#include <limits>
#include <memory>
#include <vector>#include "hardware_interface/types/hardware_interface_type_values.hpp"
#include "rclcpp/rclcpp.hpp"namespace ros2_control_demo_example_1
{
hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_init(const hardware_interface::HardwareInfo & info)
{if (hardware_interface::SystemInterface::on_init(info) !=hardware_interface::CallbackReturn::SUCCESS){return hardware_interface::CallbackReturn::ERROR;}// BEGIN: 这一段是出测试使用考虑,请勿拷贝至实际生产环境hw_start_sec_ = stod(info_.hardware_parameters["example_param_hw_start_duration_sec"]);hw_stop_sec_ = stod(info_.hardware_parameters["example_param_hw_stop_duration_sec"]);hw_slowdown_ = stod(info_.hardware_parameters["example_param_hw_slowdown"]);// END: 这一段是出测试使用考虑,请勿拷贝至实际生产环境hw_states_.resize(info_.joints.size(), std::numeric_limits<double>::quiet_NaN());hw_commands_.resize(info_.joints.size(), std::numeric_limits<double>::quiet_NaN());for (const hardware_interface::ComponentInfo & joint : info_.joints){// RRBotSystemPositionOnly 只有一种状态和命令(state,command)if (joint.command_interfaces.size() != 1){RCLCPP_FATAL(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),"Joint '%s' has %zu command interfaces found. 1 expected.", joint.name.c_str(),joint.command_interfaces.size());return hardware_interface::CallbackReturn::ERROR;}if (joint.command_interfaces[0].name != hardware_interface::HW_IF_POSITION){RCLCPP_FATAL(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),"Joint '%s' have %s command interfaces found. '%s' expected.", joint.name.c_str(),joint.command_interfaces[0].name.c_str(), hardware_interface::HW_IF_POSITION);return hardware_interface::CallbackReturn::ERROR;}if (joint.state_interfaces.size() != 1){RCLCPP_FATAL(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),"Joint '%s' has %zu state interface. 1 expected.", joint.name.c_str(),joint.state_interfaces.size());return hardware_interface::CallbackReturn::ERROR;}if (joint.state_interfaces[0].name != hardware_interface::HW_IF_POSITION){RCLCPP_FATAL(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"),"Joint '%s' have %s state interface. '%s' expected.", joint.name.c_str(),joint.state_interfaces[0].name.c_str(), hardware_interface::HW_IF_POSITION);return hardware_interface::CallbackReturn::ERROR;}}return hardware_interface::CallbackReturn::SUCCESS;
}hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_configure(const rclcpp_lifecycle::State & /*previous_state*/)
{// BEGIN: 这一段是出测试使用考虑,请勿拷贝至实际生产环境RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Configuring ...please wait...");for (int i = 0; i < hw_start_sec_; i++){rclcpp::sleep_for(std::chrono::seconds(1));RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "%.1f seconds left...",hw_start_sec_ - i);}// END: 这一段是出测试使用考虑,请勿拷贝至实际生产环境// 在切换状态到configure时总是初始化所有值for (uint i = 0; i < hw_states_.size(); i++){hw_states_[i] = 0;hw_commands_[i] = 0;}RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Successfully configured!");return hardware_interface::CallbackReturn::SUCCESS;
}std::vector<hardware_interface::StateInterface>
RRBotSystemPositionOnlyHardware::export_state_interfaces()
{std::vector<hardware_interface::StateInterface> state_interfaces;for (uint i = 0; i < info_.joints.size(); i++){state_interfaces.emplace_back(hardware_interface::StateInterface(info_.joints[i].name, hardware_interface::HW_IF_POSITION, &hw_states_[i]));}return state_interfaces;
}std::vector<hardware_interface::CommandInterface>
RRBotSystemPositionOnlyHardware::export_command_interfaces()
{std::vector<hardware_interface::CommandInterface> command_interfaces;for (uint i = 0; i < info_.joints.size(); i++){command_interfaces.emplace_back(hardware_interface::CommandInterface(info_.joints[i].name, hardware_interface::HW_IF_POSITION, &hw_commands_[i]));}return command_interfaces;
}hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_activate(const rclcpp_lifecycle::State & /*previous_state*/)
{// BEGIN: 这一段是出测试使用考虑,请勿拷贝至实际生产环境RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Activating ...please wait...");for (int i = 0; i < hw_start_sec_; i++){rclcpp::sleep_for(std::chrono::seconds(1));RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "%.1f seconds left...",hw_start_sec_ - i);}// END: 这一段是出测试使用考虑,请勿拷贝至实际生产环境// command和state开始时应该是相同的for (uint i = 0; i < hw_states_.size(); i++){hw_commands_[i] = hw_states_[i];}RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Successfully activated!");return hardware_interface::CallbackReturn::SUCCESS;
}hardware_interface::CallbackReturn RRBotSystemPositionOnlyHardware::on_deactivate(const rclcpp_lifecycle::State & /*previous_state*/)
{// BEGIN: 这一段是出测试使用考虑,请勿拷贝至实际生产环境RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Deactivating ...please wait...");for (int i = 0; i < hw_stop_sec_; i++){rclcpp::sleep_for(std::chrono::seconds(1));RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "%.1f seconds left...",hw_stop_sec_ - i);}RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Successfully deactivated!");// END: 这一段是出测试使用考虑,请勿拷贝至实际生产环境return hardware_interface::CallbackReturn::SUCCESS;
}hardware_interface::return_type RRBotSystemPositionOnlyHardware::read(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/)
{// BEGIN: 这一段是出测试使用考虑,请勿拷贝至实际生产环境RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Reading...");for (uint i = 0; i < hw_states_.size(); i++){// 模拟RRBot的运动hw_states_[i] = hw_states_[i] + (hw_commands_[i] - hw_states_[i]) / hw_slowdown_;RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Got state %.5f for joint %d!",hw_states_[i], i);}RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Joints successfully read!");// END: 这一段是出测试使用考虑,请勿拷贝至实际生产环境return hardware_interface::return_type::OK;
}hardware_interface::return_type RRBotSystemPositionOnlyHardware::write(const rclcpp::Time & /*time*/, const rclcpp::Duration & /*period*/)
{// BEGIN: 这一段是出测试使用考虑,请勿拷贝至实际生产环境RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Writing...");for (uint i = 0; i < hw_commands_.size(); i++){// 仿真发送命令到hardwareRCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Got command %.5f for joint %d!",hw_commands_[i], i);}RCLCPP_INFO(rclcpp::get_logger("RRBotSystemPositionOnlyHardware"), "Joints successfully written!");// END: 这一段是出测试使用考虑,请勿拷贝至实际生产环境return hardware_interface::return_type::OK;
}}  // namespace ros2_control_demo_example_1#include "pluginlib/class_list_macros.hpp"PLUGINLIB_EXPORT_CLASS(ros2_control_demo_example_1::RRBotSystemPositionOnlyHardware, hardware_interface::SystemInterface)

hardware_interface::SystemInterface类的说明:1

rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface类的说明:2

也可通过上一篇博客《 ROS2 LifecycleNode讲解及实例》中的介绍学习。

在这里插入图片描述

在这里插入图片描述

三、测试运行

在这里插入图片描述

总结

先把当前完成部分更新到博客,运行结果截图如上所示,这两天继续完善。


  1. ROS2 Control: hardware_interface::SystemInterface Class Reference ↩︎

  2. Class LifecycleNodeInterface ↩︎

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/231244.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何访问AWS私有网络中的RDS (Mysql)

文章目录 小结问题及解决连接问题如何使用本地的Mysql Workbench对RDS进行访问 参考 小结 在AWS私有网络中部署了RDS (Mysql), 尝试通过外网成功地进行了访问. 问题及解决 连接问题 在AWS私有网络中部署了RDS (Mysql), 进行外网进行访问碰到了各种问题. 以下连接超时&…

Go标准包之flag命令行参数解析

1.介绍 在 Go中&#xff0c;如果要接收命令行参数&#xff0c;需要使用 flag 包进行解析。不同的参数类型可以通过不同的方法接收。 2.参数接受 2.1 接受方式 使用flag接收参数&#xff0c;可以由以下三种方式接受&#xff1a; 方式一: flag.Type(name,defaultVal,desc)方…

【精选】计算机网络教程(第6章应用层)

目录 前言 第6章应用层 1、URL的格式 2、HTTP请求报文的一些方法 3、HTTPS和HTTP的区别 4、电子邮件 5、文件传送协议&#xff08;FTP&#xff09; 前言 总结计算机网络教程课程期末必记知识点。 第6章应用层 1、URL的格式 定义格式 <协议>&#xff1a;//<主…

计算机毕业设计 基于SpringBoot的大学生创新创业项目管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解

博主介绍&#xff1a;✌从事软件开发10年之余&#xff0c;专注于Java技术领域、Python人工智能及数据挖掘、小程序项目开发和Android项目开发等。CSDN、掘金、华为云、InfoQ、阿里云等平台优质作者✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精…

关联规则 FP-Growth算法

FP-Growth算法 FP-growth 算法思想 FP-growth算法是韩家炜老师在2000年提出的关联分析算法&#xff0c;它采取如下分治策略: 将提供频繁项集的数据库压缩到一棵频繁模式树 (FP-Tree)但仍保留项集关联信息。FP-growth算法是对Apriori方法的改进。生成一个频繁模式而不需要生成…

mysql 索引场景 大于>为什么失效

可以先看这个&#xff1a;Mysql查询条件为大于时&#xff0c;不走索引失效场景-CSDN博客 改为> &#xff0c;可双看到key_len减少了&#xff0c;从90变到了86&#xff0c;也就是说联合索引(a b c) &#xff0c;只有(a b) 起了效果,c 没有。 可以不查c看看结果&#xff0c;还…

深度学习项目实战:垃圾分类系统

简介&#xff1a; 今天开启深度学习另一板块。就是计算机视觉方向&#xff0c;这里主要讨论图像分类任务–垃圾分类系统。其实这个项目早在19年的时候&#xff0c;我就写好了一个版本了。之前使用的是python搭建深度学习网络&#xff0c;然后前后端交互的采用的是java spring …

LibreOffice Online安装

LibreOffice Online安装 环境&#xff1a;Liunx 通过docker拉取 LibreOffice Online 主干镜像&#xff1a; docker pull libreoffice/online:master启动容器&#xff0c;根据实际情况替换&#xff1a; docker run -dit -p 9980:9980 --name libreoffice-online -e "us…

vivado 创建实施约束

创建实施约束 在您有了一个合成的网表之后&#xff0c;您可以将它与XDC文件一起加载到内存中&#xff0c;或者Tcl脚本已启用以进行实现。当加载XDC以便验证和更正任何不能应用的约束。在某些情况下&#xff0c;合成网表中的对象名称与精心设计。如果是这种情况&#xff0c;则必…

每日一题:LeetCode-LCR 016. 无重复字符的最长子串

每日一题系列&#xff08;day 15&#xff09; 前言&#xff1a; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f308; &#x1f50e…

《PySpark大数据分析实战》-14.云服务模式Databricks介绍基本概念

&#x1f4cb; 博主简介 &#x1f496; 作者简介&#xff1a;大家好&#xff0c;我是wux_labs。&#x1f61c; 热衷于各种主流技术&#xff0c;热爱数据科学、机器学习、云计算、人工智能。 通过了TiDB数据库专员&#xff08;PCTA&#xff09;、TiDB数据库专家&#xff08;PCTP…

docker-compose介绍和用法

docker-compose介绍和用法详解 1、docker-compose介绍2、docker-compose build3、docker-compose down4、docker-compose up -d 1、docker-compose介绍 Docker Compose是一个用于快速配置多个Docker容器的工具。它是一个定义和运行多容器的Docker应用工具&#xff0c;通过YAML…

redis之五种基本数据类型

redis存储任何类型的数据都是以key-value形式保存&#xff0c;并且所有的key都是字符串&#xff0c;所以讨论基础数据结构都是基于value的数据类型 常见的5种数据类型是&#xff1a;String、List、Set、Zset、Hash 一) 字符串(String) String是redis最基本的类型&#xff0c;v…

【线性代数】期末速通!

1. 行列式的性质 1.1 求一个行列式的值 特殊地&#xff0c;对角线左下全为0&#xff0c;结果为对角线乘积。行 r 列 c 1.2 性质 某行&#xff08;列&#xff09;加上或减去另一行&#xff08;列&#xff09;的几倍&#xff0c;行列式不变某行&#xff08;列&#xff09;乘 …

C++学习笔记(十二)------is_a关系(继承关系)

你好&#xff0c;这里是争做图书馆扫地僧的小白。 个人主页&#xff1a;争做图书馆扫地僧的小白_-CSDN博客 目标&#xff1a;希望通过学习技术&#xff0c;期待着改变世界。 提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参考 文章目录 前言 一、继承关系…

Pipelined-ADC设计一:序言

现在是2023年12月18日&#xff0c;准备开新帖&#xff0c;设计一个 流水线型 模数转换器&#xff08; Pipelined-ADC &#xff09;。记录帖&#xff0c;后续会放在咸鱼。同步记录&#xff0c;谨防盗用。 初定指标&#xff1a;12位50Mhz&#xff0c;采用2.5bit每级结构&#xff…

使用DTS将自建MySQL迁移至PolarDB MySQL引擎,探索DTS全量数据校验

1. 领取免费的ECS和PolarDB资源 一旦您注册了阿里云账号并填写了您的账号和支付信息&#xff0c;您就可以申请免费试用我们的产品&#xff08;如ECS、PolarDB、RDS等服务&#xff09;。 1.1. 申请 ECS 免费试用 1. 在 阿里云免费试用中心&#xff0c;找到ECS&#xff0c;单击…

可视化 | 基于CBDB的唐代历史人物分析

文章目录 &#x1f4da;人口统计&#x1f407;唐朝历年人数统计&#x1f407;唐朝人口金字塔&#x1f407;唐朝历年出生死亡人数统计&#x1f407;唐朝人口分布&#x1f407;享年数据分布 &#x1f4da;唐朝人口迁徙&#x1f407;人口迁徙&#x1f407;生卒地变迁 &#x1f4da…

IDEA代码补全不能导入某个类了

问题 今天写单元测试时&#xff0c;突然发现idea自动补全代码时不能自动导入类了&#xff0c; 比如在编辑器中输入Test&#xff0c;正常情况下通过快捷键atl/智能补全提示后可以自动生成导入import org.junit.Test &#xff0c;但是现在不行了。 解决办法 由于在导入Test时不小…

【JavaWeb学习笔记】11 - WEB工程路径专题

一、工程路径问题 1.引入该问题 通过这几个去访问很麻烦 二、工程路径解决方案 1.相对路径 1.说明:使用相对路径来解决&#xff0c;一 个非常重要的规则:页面所有的相对路径&#xff0c;在默认情况下&#xff0c;都会参考当前浏览器地址栏的路径http:/ /ip:port/工程名/来进…