#include <ros/ros.h>
#include <geometry_msgs/Quaternion.h>
void orientationCallback(const geometry_msgs::Quaternion::ConstPtr& msg)
{
// 在这里处理接收到的物体方向信息
double x = msg->x;
double y = msg->y;
double z = msg->z;
double w = msg->w;
// 输出物体方向信息到终端
std::cout << "Received orientation:\n";
std::cout << "x: " << x << std::endl;
std::cout << "y: " << y << std::endl;
std::cout << "z: " << z << std::endl;
std::cout << "w: " << w << std::endl;
// 进行进一步的处理或操作
// ...
}
int main(int argc, char** argv)
{
ros::init(argc, argv, "orientation_subscriber");
ros::NodeHandle nh;
// 创建一个 Subscriber 对象来订阅 rostopic,指定回调函数
ros::Subscriber sub = nh.subscribe<geometry_msgs::Quaternion>("/wit/mag", 1000, orientationCallback);
ros::spin();
return 0;
}
这个代码在使用rosrun的时候会报错,报错如下:
/home/xx/xx/src/xx/scripts/seize_message.cpp: 行 4: 未预期的符号 `(' 附近有语法错误
/home/xx/xx/src/xx/scripts/seize_message.cpp: 行 4: `void orientationCallback(const geometry_msgs::Quaternion::ConstPtr& msg)'
请问这个问题怎么解决呢
