when i use “output.name[0]="Tjoint” there is a error Segmentation fault
The code is as follows:
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "sensor_msgs/JointState.h"
#include <sstream>
class SubscribeAndPublish
{
public:
SubscribeAndPublish()
{
//topic you want to publish
pub_=n.advertise<sensor_msgs::JointState>("/arm/joint_states",1000);
//subscribe
sub_=n.subscribe("/joint_states",1000,&SubscribeAndPublish::callback,this);
}
void callback(const sensor_msgs::JointState::ConstPtr& msg)
{
sensor_msgs::JointState output;
output.name=msg->name; // output.name[0]="Tjoint
output.position=msg->position;
output.header=msg->header;
pub_.publish(output);
}
private:
ros::NodeHandle n;
ros::Publisher pub_;
ros::Subscriber sub_;
};
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
SubscribeAndPublish SAPobject;
ros::spin();
return 0;
}
This is not a question.
Please format your code properly (use the Preformatted text button) and explain what you are trying to do, what doesn't work and why you think that doesn't work.
thx for your advice ,i try to write a node to subscribe the topic “joint-states” , this topic have messages of 6 joints ,but what i need is only the message of “joint0” and publish the message of “joint0” to topic “arm/joint_states”
i want to use the “void callback“” to filter the message
I've provided an answer to your question, and reformatted your original question. I was only able to do this because I had already answered your original question; so I knew what you were asking. As @gvdhoorn indicated, please put more effort into writing clear and nicely formatted questions