Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Not able to control motor wheels in RVIZ through Python Publisher

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="right_wheel_holder_link">

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

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

    <inertial>
      <mass value="1"/>
      <inertia ixx="0.011" ixy="0.0" ixz="0.0" iyy="0.0067" iyz="0.0" izz="0.011"/>
    </inertial>

  </link>

  <link name="left_wheel_holder_link">

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

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

    <inertial>
      <mass value="1"/>
      <inertia ixx="0.011" ixy="0.0" ixz="0.0" iyy="0.0067" iyz="0.0" izz="0.011"/>
    </inertial>

  </link>

  <link name="right_wheel_link">

    <visual>
      <origin rpy="0 0 0" xyz="0 0 0"/>
      <geometry>
        <cylinder length="0.05" radius="0.25"/>
      </geometry>
      <material name="grey"/>
    </visual>

    <collision>
      <geometry>
        <cylinder length="0.05" radius="0.25"/>
      </geometry>
    </collision>

    <inertial>
      <mass value="1"/>
      <inertia ixx="0.00021" ixy="0.0" ixz="0.0" iyy="0.0" iyz="0.0" izz="0.00021"/>
    </inertial>

  </link>

  <link name="left_wheel_link">

    <visual>
        <origin rpy="0 0 0" xyz="0 0 0"/>
      <geometry>
        <cylinder length="0.05" radius="0.25"/>
      </geometry>
      <material name="grey"/>
    </visual>

    <collision>
      <geometry>
        <cylinder length="0.05" radius="0.25"/>
      </geometry>
    </collision>

    <inertial>
      <mass value="1"/>
      <inertia ixx="0.00021" ixy="0.0" ixz="0.0" iyy="0.0" iyz="0.0" izz="0.00021"/>
    </inertial>

  </link>

  <joint name="base_to_right_wheel_holder" type="fixed">
    <parent link="base_link"/>
    <child link="right_wheel_holder_link"/>
    <origin rpy="0 0 0" xyz="0.4 0.2 -0.2"/>
  </joint>

  <joint name="base_to_left_wheel_holder" type="fixed">
    <parent link="base_link"/>
    <child link="left_wheel_holder_link"/>
    <origin rpy="0 0 0" xyz="-0.4 0.2 -0.2"/>
  </joint>

  <joint name="left_wheel_holder_to_left_wheel" type="continuous">
    <axis xyz="0 0 1"/>
    <parent link="left_wheel_holder_link"/>
    <child link="left_wheel_link"/>
    <origin rpy="0 -1.57075 0" xyz="-0.15 0 0"/>
  </joint>

  <joint name="right_wheel_holder_to_right_wheel" type="continuous">
    <axis xyz="0 0 1"/>
    <parent link="right_wheel_holder_link"/>
    <child link="right_wheel_link"/>
    <origin rpy="0 1.57075 0" xyz="0.15 0 0"/>
  </joint>

  <transmission>
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="left_wheel_holder_to_left_wheel">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
    </joint>
    <actuator name="motor_left">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>

    <joint name="right_wheel_holder_to_left_wheel">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
    </joint>
    <actuator name="motor_right">
      <hardwareInterface>EffortJointInterface</hardwareInterface>
      <mechanicalReduction>1</mechanicalReduction>
    </actuator>

  </transmission>


</robot>

I also did not modify my CMakeLists file, I wonder if I have to though...