Ask Your Question
0

Not able to control motor wheels in RVIZ through Python Publisher

asked 2019-11-04 22:57:47 -0600

vitsensei gravatar image

Hi, I'm running Ubuntu 18.04, melodic.

I'm very new to ROS in general (1 week new), so hopefully you guys can be a bit more patient. So anyway, I wrote a Python publisher for my (differential drive) car. It supposed to send the joint state of my two wheels to RVIZ, and in RVIZ, I supposed to see my car moving with the set speed coming from python side.

It didn't happen. I think maybe I'm missing something, or misunderstood something? If you guys can point that out, it would be great!

Here's my Python side:

Hi, I'm very new to ROS in general (1 week new), so hopefully you guys can be a bit more patient. So anyway, I wrote a Python publisher for my (differential drive) car. It supposed to send the joint state of my two wheels to RVIZ, and in RVIZ, I supposed to see my car moving with the set speed coming from python side.

It didn't happen. I think maybe I'm missing something, or misunderstood something? If you guys can point that out, it would be great!

Here's my Python side:

#!/usr/bin/env python

import rospy
from std_msgs.msg import Header
from sensor_msgs.msg import JointState

def talker():
    pub = rospy.Publisher('joint_states', JointState, queue_size=10)
    rospy.init_node('joint_state_publisher', anonymous = True)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        jointState_msg = JointState()
        jointState_msg.header = Header()
        jointState_msg.header.stamp = rospy.Time.now()
        jointState_msg.name = ['left_wheel_holder_to_left_wheel', 'right_wheel_holder_to_right_wheel']
        jointState_msg.position = []
        jointState_msg.velocity = [1, 1]
        jointState_msg.effort = []

        pub.publish(jointState_msg)

        rate.sleep()

if __name__ == '__main__':
try:
    talker()
except rospy.ROSInterruptException:
    pass

Here's my launch file:

<launch>
    <param name="robot_description" textfile="$(find rover_project)/rover_description/urdf/rover.urdf"/>

    <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />

    <node name="rviz" pkg="rviz" type="rviz" args="-d $(find rover_project)/rover_description/launch/rviz_config.rviz" />

    <node pkg="robot_state_publisher" type="robot_state_publisher" name="rob_st_pub">
        <param name="use_gui" value="True"/>
    </node>
    <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
        <param name="use_gui" value="True"/>
    </node>

</launch>

And most importantly, and this is where I think went wrong, my urdf file:

<?xml version="1.0"?>

<robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="Rover Platform">

  <material name="blue">
    <color rgba="0 0 0.8 1"/>
  </material>

  <material name="grey">
    <color rgba="0.2 0.2 0 1"/>
  </material>   

  <xacro:macro name="default_origin">
    <origin rpy="0 0 0" xyz="0 0 0"/>
  </xacro:macro>


  <link name="base_link">
    <visual>
      <geometry>
        <box size="1.0 1.0 0.2"/>
      </geometry>
      <xacro:default_origin />
      <material name="blue"/>

    </visual>

    <collision>
      <geometry>
        <box size="1.0 1.0 0.2"/>
      </geometry>
    </collision>

    <inertial>
      <mass value="5"/>
      <inertia ixx="0.83333" ixy="0.0" ixz="0.0" iyy="0.433333" iyz="0.0" izz="0.433333"/>
    </inertial>

  </link>

  <link name ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-11-05 01:36:59 -0600

gvdhoorn gravatar image

updated 2019-11-05 01:41:00 -0600

It supposed to send the joint state of my two wheels to RVIZ, and in RVIZ, I supposed to see my car moving with the set speed coming from python side.

RViz is not a simulator. It only visualises incoming data streams. From your question text it appears you are expecting your car to "move" relative to its starting position, based on time * velocity. That will not work, as again, RViz is not a simulator. It merely visualises (kinematic) state.

Objects are rendered by RViz with their origins at the origins of the associated TF frames (ie: Cartesian position). It would be possible to make your model "move", by writing a node that integrates velocity and updates the transform based on that, but it would still only be a visualisation (ie: not based on any real dynamics simulation).

You should probably take a look at Gazebo, V-REP or Webots if you're looking to simulate car-like behaviour based on physics.

Additionally: you appear to be using JointState messages for control purposes. As the name implies, JointState encodes state. It is not meant to be used for controlling something.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-11-04 22:57:47 -0600

Seen: 10 times

Last updated: Nov 05