Unable to publish joint angles to gazebo using rostopic

asked 2019-07-14 05:23:54 -0500

microbot gravatar image

Hello,

I am a beginner to work with ros. I have developed a python based control plugin that I want to use to control my robot that is being spawned in gazebo. I have used roslaunch command to launch the world with the robot spawned in it and then in another terminal i have exported ROS_MASTER_URI and then used rosrun command to compile and run my plugin, the command I used exactly is

rosrun spider_control control.py

Here spider_control is the catkin package that contains control.py file. For sake of better understading I will also paste the copy of the talker that I am using to publish joint commands, i.e.

def talker(jointname , position):
pub1 = rospy.Publisher('joint_states', JointState, queue_size = 10)
rospy.init_node('joint_state_publisher')
rate = rospy.Rate(10)
while not rospy.is_shutdown():
    robot_configuration = JointState()
    robot_configuration.header = Header()
    robot_configuration.header.stamp = rospy.Time.now()
    robot_configuration.name = [jointname]
    robot_configuration.position = [position]
    robot_configuration.velocity = []
    robot_configuration.effort = []
    pub1.publish(robot_configuration)
rate.sleep()

and this is how I am calling the talker function in my main syntax,

initial_angles = np.random.normal(0.1, 1.5, size=24)
number = 0
for spiderJoint1Name in spiderJoint1Names:
    talker(spiderJoint1Name, initial_angles[number])
    number+=1
for spiderJoint2Name in spiderJoint2Names:
    talker(spiderJoint2Name, initial_angles[number])
    number+=1
for spiderJoint3Name in spiderJoint3Names:
    talker(spiderJoint3Name, initial_angles[number])
    number+=1
for spiderJoint4Name in spiderJoint4Names:
    talker(spiderJoint4Name, initial_angles[number])
    number+=1
for spiderJoint5Name in spiderJoint5Names:
    talker(spiderJoint5Name, initial_angles[number])
    number+=1
for spiderJoint6Name in spiderJoint6Names:
    talker(spiderJoint6Name, initial_angles[number])
    number+=1
for spiderJoint7Name in spiderJoint7Names:
    talker(spiderJoint7Name, initial_angles[number])
    number+=1
for spiderJoint8Name in spiderJoint8Names:
    talker(spiderJoint8Name, initial_angles[number])
    number+=1

Where I am creating 24 random numbers and then publishing them as joint angle for the joints. When I run this file, I am not getting any error but at the same time these specified joint_angles are also not being published. Can anyone help me with where I am going wrong ? I am using ROS melodic and gazebo 9 with python 3.5.7. Thanks in advance

In case needed here is the copy of my control.launch file

<launch>

<!-- Load joint controller configurations from YAML file to parameter server -->
<rosparam file="$(find spider_control)/config/spider_control.yaml" command="load"/>

<!-- load the controllers -->
<node name="controller_spawnner" pkg="controller_manager" type="spawner" respawn="false"
  output="screen" ns="/spider"      args="joint_1_1_position_controller
                                                joint_1_2_position_controller
                                      joint_1_3_position_controller
                                      joint_2_1_position_controller
                                      joint_2_2_position_controller
                                      joint_2_3_position_controller
                                      joint_3_1_position_controller
                                      joint_3_2_position_controller
                                      joint_3_3_position_controller
                                      joint_4_1_position_controller
                                      joint_4_2_position_controller
                                      joint_4_3_position_controller
                                      joint_5_1_position_controller
                                      joint_5_2_position_controller
                                      joint_5_3_position_controller
                                      joint_6_1_position_controller
                                      joint_6_2_position_controller
                                      joint_6_3_position_controller
                                      joint_7_1_position_controller
                                      joint_7_2_position_controller
                                      joint_7_3_position_controller
                                      joint_8_1_position_controller
                                      joint_8_2_position_controller
                                      joint_8_3_position_controller
                                      joint_state_controller"/>

<!-- convert joint states to TF transforms for rviz, etc -->
<node name="rob_st_pub" pkg="robot_state_publisher" type="robot_state_publisher"
  respawn="false" output="screen" >
<remap from="robot_description" to="robot_description" />
  <remap from="/joint_states" to="/spider/joint_states" />

  </node>

</launch>

I have also loaded gazebo_ros_control in gazebo reference as following

  <gazebo>
  <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">
    <robotNamespace>spider</robotNamespace>
    <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
    <legacyModeNS>true</legacyModeNS>
  </plugin>
</gazebo>

<plugin name="joint_state_publisher" filename="libgazebo_ros_joint_state_publisher.so">
  <robotNamespace>spider</robotNamespace>
  <jointName> 
    joint_1_1, joint_1_2, joint_1_3, joint_2_1, joint_2_2, joint_2_3, joint_3_1, joint_3_2 ...
(more)
edit retag flag offensive close merge delete