ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
It might seem a bit redundant, but that's how I would do it.
(I'm assuming you want to keep everything except the position array)
1- Define a new message. I'm defining it in package myPkg
and calling it newMsg
.
Header header
string[] name
float64[] velocity
float64[] effort
2- Write a node that on receiving a message (callback), publishes the data you want.
import rospy
from myPkg.msg import newMsg
from sensor_msgs.msg import JointState
def callback(msg):
out.header = msg.header
out.velocity = msg.velocity
out.effort = msg.effort
pub.publish(out)
rospy.init_node('Scraper')
sub = rospy.Subscriber('in', JointState, callback)
pub = rospy.Publisher('out', newMsg)
2 | No.2 Revision |
It might seem a bit redundant, but that's how I would do it.
(I'm assuming you want to keep everything except the position array)
1- Define a new message. I'm defining it in package myPkg
and calling it newMsg
.
Header header
string[] name
float64[] velocity
float64[] effort
2- Write a node that on receiving a message (callback), publishes the data you want.
import rospy
from myPkg.msg import newMsg
from sensor_msgs.msg import JointState
def callback(msg):
out.header = msg.header
out.velocity = msg.velocity
out.effort = msg.effort
pub.publish(out)
rospy.init_node('Scraper')
sub = rospy.Subscriber('in', JointState, callback)
pub = rospy.Publisher('out', newMsg)
newMsg)
rospy.spin()
Note: If concerned about performance, implement this in the node you're subscribing to.