std_msgs/msg/Header
# Standard metadata for higher-level stamped data types.
# This is generally used to communicate timestamped data
# in a particular coordinate frame.
# Two-integer timestamp that is expressed as seconds and nanoseconds.
#stamp--时间戳,两个成员:秒和纳秒
builtin_interfaces/Time stamp
int32 sec
uint32 nanosec
# Transform frame with which this data is associated.
#
string frame_id
作用:
sensor/msg/JointState
# This is a message that holds data to describe the state of a set of torque controlled joints.
#
# The state of each joint (revolute or prismatic) is defined by:
# * the position of the joint (rad or m),
# * the velocity of the joint (rad/s or m/s) and
# * the effort that is applied in the joint (Nm or N).
#
# Each joint is uniquely identified by its name
# The header specifies the time at which the joint states were recorded. All the joint states
# in one message have to be recorded at the same time.
#
# This message consists of a multiple arrays, one for each part of the joint state.
# The goal is to make each of the fields optional. When e.g. your joints have no
# effort associated with them, you can leave the effort array empty.
#
# All arrays in this message should have the same size, or be empty.
# This is the only way to uniquely associate the joint name with the correct
# states.
std_msgs/Header header
builtin_interfaces/Time stamp
int32 sec
uint32 nanosec
string frame_id
string[] name
float64[] position
float64[] velocity
float64[] effort
- `string[] name`:机器人关节的名称,为一个字符串数组;
- `float64[] position`:机器人关节的位置,为一个双精度浮点数数组;
- `float64[] velocity`:机器人关节的速度,为一个双精度浮点数数组;
- `float64[] effort`:机器人关节的力/扭矩,为一个双精度浮点数数组。
std_srvs/srv/empty.hpp
什么都不需要传递的空服务。
#include <memory>
#include "rclcpp/rclcpp.hpp"
#include "std_srvs/srv/empty.hpp"
using namespace std::placeholders;
namespace cb_group_demo
{
class ServiceNode : public rclcpp::Node
{
public:
ServiceNode() : Node("service_node")
{
service_ptr_ = this->create_service<std_srvs::srv::Empty>(
"test_service",
std::bind(&ServiceNode::service_callback, this, _1, _2, _3)
);
}
private:
rclcpp::Service<std_srvs::srv::Empty>::SharedPtr service_ptr_;
void service_callback(
const std::shared_ptr<rmw_request_id_t> request_header,
const std::shared_ptr<std_srvs::srv::Empty::Request> request,
const std::shared_ptr<std_srvs::srv::Empty::Response> response)
{
(void)request_header;
(void)request;
(void)response;
RCLCPP_INFO(this->get_logger(), "Received request, responding...");
}
}; // class ServiceNode
} // namespace cb_group_demo
int main(int argc, char* argv[])
{
rclcpp::init(argc, argv);
auto service_node = std::make_shared<cb_group_demo::ServiceNode>();
RCLCPP_INFO(service_node->get_logger(), "Starting server node, shut down with CTRL-C");
rclcpp::spin(service_node);
RCLCPP_INFO(service_node->get_logger(), "Keyboard interrupt, shutting down.\n");
rclcpp::shutdown();
return 0;
}