ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Why isn't rviz2 responding to my publisher node?

asked 2022-12-22 21:05:25 -0500

lucach gravatar image

Hi, I'd like to write a publisher node that outputs messages of type JointState and then is read by rviz2, displaying the moving joints of my robot onto its display. I followed the nav2 docs up to this stage which go through how to use the joint_state_publisher_gui to move the joints in rviz2. This worked correctly and it seemed as if these messaged were being published onto the /joint_states topic as when I echoed them into my terminal it was displaying messages that made sense.

My logic was to then write a publisher node as seen below, that would publish messages of type JointState, onto the /joint_state topic and that would cause rviz2 to show the movement. I made the node and it seemed to work, as again, when I echoed it into another terminal it was displaying the correct messages, however the joints of my robot on rviz2 was not showing any movement.

Have I made an error in judgement, or is my code incorrect?

Publisher node:

> #!/usr/bin/env python3
> 
> import rclpy import math from
> rclpy.node import Node import random
> 
> from sensor_msgs.msg import JointState
> 
> 
> class MinimalPublisher(Node):
> 
>     def __init__(self):
>         super().__init__('joint_publisher')
>         self.publisher_ = self.create_publisher(JointState,
> 'joint_states', 10)
>         timer_period = 2  # seconds
>         self.timer = self.create_timer(timer_period,
> self.timer_callback)
>         self.i = 0.0
> 
>     def timer_callback(self):
>         msg = JointState()
>         msg.name = ['shoulder_fr_twist_joint',
> 'shoulder_fl_twist_joint',
> 'shoulder_br_twist_joint',
> 'shoulder_bl_twist_joint',
> 'shoulder_fr_joint',
> 'shoulder_fl_joint',
> 'shoulder_br_joint',
> 'shoulder_bl_joint',
> 'forearm_fr_joint',
> 'forearm_fl_joint',
> 'forearm_br_joint',
> 'forearm_bl_joint']
>         # pick random int between the limits
>         msg.position = [random.uniform(-0.4, 0.4),
> random.uniform(-0.4, 0.4),
> random.uniform(-0.4, 0.4),
> random.uniform(-0.4, 0.4),
> random.uniform(-0.8, 0.8),
> random.uniform(-0.8, 0.8),
> random.uniform(-0.8, 0.8),
> random.uniform(-0.8, 0.8),
> random.uniform(-0.8, 1),
> random.uniform(-0.8, 1),
> random.uniform(-0.8, 1),
> random.uniform(-0.8, 1)]
>         msg.velocity = []
>         msg.effort = []
>         
>         self.publisher_.publish(msg)
>         self.get_logger().info('Publishing:
> "%s"' % self.i)
>         self.i += 0.1
> 
> 
> def main(args=None):
>     rclpy.init(args=args)
> 
>     minimal_publisher = MinimalPublisher()
> 
>     rclpy.spin(minimal_publisher)
> 
>     # Destroy the node explicitly
>     # (optional - otherwise it will be done automatically
>     # when the garbage collector destroys the node object)
>     minimal_publisher.destroy_node()
>     rclpy.shutdown()
> 
> 
> if __name__ == '__main__':
>     main()

Please let me know if you would like any further information, I've been stuck on this for a few days and would love for this to be cleared up!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-12-24 10:15:47 -0500

ChuiV gravatar image

RVIz in and of itself doesn't really know how to display the angle of an arbitrary joint. Typically you have a robot_state_publisher (https://github.com/ros/robot_state_pu...) node that reads in the urdf robot description and subscribes to joint states. Then it publishes the tfs for each of the robot links base on their joint_states.

So instead of

[joint_publisher] -> (/joint_states) -> [rviz]

we would have something like

[joint_publisher] -> (/joint_states) -> [robot_state_publisher] -> (/tf, /tf_static, /robot_description)) -> [rviz]
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-12-22 21:05:25 -0500

Seen: 359 times

Last updated: Dec 24 '22