{"id":81,"date":"2017-04-20T09:24:41","date_gmt":"2017-04-20T13:24:41","guid":{"rendered":"http:\/\/commons.trincoll.edu\/trinityrobotics\/?p=81"},"modified":"2017-04-20T09:24:41","modified_gmt":"2017-04-20T13:24:41","slug":"modifying-sensor-data-with-ros","status":"publish","type":"post","link":"https:\/\/commons.trincoll.edu\/trinityrobotics\/modifying-sensor-data-with-ros\/","title":{"rendered":"Modifying Sensor Data with ROS"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>Here is a sample code that modifies sensor data with ROS:<\/p>\n<pre>import rospy\r\nfrom sensor_msgs.msg import Imu\r\n\r\ndef imu_callback(msg, pub):\r\n msg.linear_acceleration.z += 9.3\r\n pub.publish(msg)\r\n\r\ndef main():\r\n rospy.init_node('imu_without_g')\r\n pub = rospy.Publisher('imu_without_g', Imu, queue_size=10)\r\n rospy.Subscriber('imu\/data', Imu, imu_callback,callback_args=pub) \r\n rospy.spin()\r\n\r\nif __name__ == '__main__':\r\n main()<\/pre>\n<pre>def imu_callback(msg, pub):\r\n msg.linear_acceleration.z += 9.3\r\n pub.publish(msg)<\/pre>\n<p>The callback is whenever Imu msg arrive, with an additional argument of pub (which is specified in the rospy.Subscriber call). I can modify the msg using the dot notation (with names you can find out with command rosmsg show sensor_msgs\/Imu).<\/p>\n<pre>def main():\r\n rospy.init_node('imu_without_g')\r\n pub = rospy.Publisher('imu_without_g', Imu, queue_size=10)\r\n rospy.Subscriber('imu\/data', Imu, imu_callback,callback_args=pub) \r\n rospy.spin()<\/pre>\n<p>I initialize a publisher to publish modified IMU data. Since this modified data will be published onto a different topic, you&#8217;ll have to redirect the topic of the imu for each nodes that use IMU data in the future.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Here is a sample code that modifies sensor data with ROS: import rospy from sensor_msgs.msg import Imu def imu_callback(msg, pub): msg.linear_acceleration.z += 9.3 pub.publish(msg) def main(): rospy.init_node(&#8216;imu_without_g&#8217;) pub = rospy.Publisher(&#8216;imu_without_g&#8217;, Imu, queue_size=10) rospy.Subscriber(&#8216;imu\/data&#8217;, Imu, imu_callback,callback_args=pub) rospy.spin() if __name__ == &#8216;__main__&#8217;: main() def imu_callback(msg, pub): msg.linear_acceleration.z += 9.3 pub.publish(msg) The callback is whenever Imu msg &hellip; <a href=\"https:\/\/commons.trincoll.edu\/trinityrobotics\/modifying-sensor-data-with-ros\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Modifying Sensor Data with ROS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1933,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/posts\/81"}],"collection":[{"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/users\/1933"}],"replies":[{"embeddable":true,"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/comments?post=81"}],"version-history":[{"count":2,"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":83,"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/posts\/81\/revisions\/83"}],"wp:attachment":[{"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/commons.trincoll.edu\/trinityrobotics\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}