ROS General - ashBabu/Utilities GitHub Wiki

Case with multiple nodes publishing on a topic

from here

Set the node as anonymous by changing the line:

rospy.init_node("counter_publisher")

to:

rospy.init_node("counter_publisher", anonymous=True)

This would spawn as many “counter_publisher” nodes as you want, each one publishing on the “/counter” topic.

A simple color thresholding for object detection in ROS

  • The example can be found here

Some fixes to common errors (for simulation)

  • Action client not connected ; Controller spawner could not find the expected ROS controller interface

These issues are mainly because of the namespace in the controllers.yaml file and the libgazebo_ros_control package

    <gazebo>
        <plugin name="gazebo_ros_control" filename="libgazebo_ros_control.so">  <!-- libgazebo_ros_control.so is generated in devel/lib after compilation -->
            <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
            <legacyModeNS>true</legacyModeNS>
            <robotNamespace>${arm_type}</robotNamespace>
        </plugin>
    </gazebo>

If the controllers.yaml file is in namespace scara_arm as shown below, then ${arm_type} should be scara_arm as well

scara_arm:
   position_joint_trajectory_controller:
    type: "position_controllers/JointTrajectoryController"
    joints:
      - arm_joint_0
      - arm_joint_1
      - arm_joint_2
    state_publish_rate: 150

USB Camera integration in ROS

sudo apt-get install ros-melodic-usb-cam
roslaunch usb_cam usb_cam-test.launch

ROS lookup Transform

self.listener = tf.TransformListener()
self.listener.waitForTransform("base_link", "perception_link", rospy.Time(0), rospy.Duration(2.0))
self.trans, self.rot = self.listener.lookupTransform(target_frame="base_link",
                                                             source_frame="perception_link", time=rospy.Time(0))

NOTE: The above indicates:- self.trans = translation of the origin of perception_link from base_link
self.rot = rotation of the perception_link frame wrt the base_link frame

Install hrl-kdl

  • clone the hrl_kdl repository git clone https://github.com/gt-ros-pkg/hrl-kdl.git
  • install pykd_utils cd hrl-kdl/pykdl_utils python setup.py build sudo python setup.py install
  • install hrl_geom cd ~/catkin_ws/src/hrl-kdl/hrl_geom/ python setup.py build sudo python setup.py install
  • install urdf_parser and urdfdom-py sudo apt-get install ros-melodic-urdf-parser-plugin ros-melodic-urdfdom-py
  • build the catkin workspace cd ~/catkin_ws catkin build

The line from pykdl_utils.kdl_kinematics import KDLKinematics needs the folder pykdl_utils inside the root for this line to work

Note: might require sudo apt-get install ros-melodic-python-orocos-kdl

Gazebo error: Getting Error [Err] [REST.cc:205] Error in REST request

Solution: Inside ~/.ignition/fuel/config.yaml replace

url: https://api.ignitionfuel.org by url: https://api.ignitionrobotics.org

Same ROS Master in Multiple Machines

Case 1: If say two machines are running Linux

Master Machine Settings
  • In the .bashrc, add the following:
  • export ROS_MASTER_URI=http://192.xxx.1.yyy:11311
  • export ROS_IP=192.xxx.1.yyy where 192.xxx.1.yyy is the ip of the master machine obtained from running ifconfig
Rest of the linux machines
  • Fire up a terminal and run export ROS_MASTER_URI=http://192.xxx.1.yyy:11311 and export ROS_IP=192.xxx.1.zzz where zzz is the last number on the ip of the slave machines
  • The above has to be run in every terminals or update the .bashrc with those two commands

Case 2: Linux Master and Windows 10 slave

  • Set the linux master exactly as above
  • Set environment variables in Windows 10 as shown here
  • There's a chance that the ping ip address of windows machine wont work from linux master. If needed, reset the firewall settings as described here

Testing

  • In the terminal on the master machine, run roscore
  • Assuming ROS is set up in the slave machine, open a terminal, run rostopic list and should be able to see /rosout /rosout_agg. This establishes the basic connection
  • In the master machine, launch anything, for eg: roslaunch panda_moveit_config demo.launch (assuming franka_ros and MoveIt)
  • In the slave machine, run rostopic echo /tf. This should print the transform continuously on the terminal

Troubleshooting

  • rostopic list works on the slave machine but rostopic echo /topic does not show anything. Discussion here
$ rostopic info /gazebo/model_states

Type: gazebo_msgs/ModelStates

Publishers: 
 * /gazebo (http://my-workstation:42193/)

Subscribers: 
 * /rostopic_117_1574085827847 (http://132.11.11.111:40064/)

In the above, Publishers is coming from the master and Subscribers are the slaves. So the slaves are confused what my-workstation is because it was told the master is 132.11.11.111:40064. Solution is to add

132.11.11.111 my-workstation to the end of /etc/hosts.

  • Might have to disable firewall on the Ubuntu master sudo ufw disable

ROS2 Installation

Python 3 support for ROS

Edit .xacro file as per the DH Convention (need to look again)

<link name="${arm_id}_link2">
      <visual>
        <material name="blue"/>
        <geometry>
          <cylinder length="${l2}" radius="${radius}"/>
        </geometry>
         <origin rpy="0 ${pi/2} 0" xyz="${l2/2} 0 0"/>   
         ##################
         _**This rotation of 90 abt y will shift the cylinder axis to x. The translation of l2/2 will shift the CG of cylinder from its geometrical centre to the left edge**_ 
      ############
      </visual>
      <collision>
        <geometry>
          <cylinder length="${l2}" radius="${radius}"/>
        </geometry>
      </collision>
      <inertial>
        <mass value="${massL2}"/>
        <inertia ixx="${IL_xx}" ixy="0.0" ixz="0.0" iyy="${IL_yy}" iyz="0.0" izz="${IL_zz}"/>
      </inertial>
    </link>
    <joint name="${arm_id}_joint2" type="revolute">
      <safety_controller k_position="100.0" k_velocity="40.0" soft_lower_limit="-1.7628" soft_upper_limit="1.7628"/>
      <origin rpy="${pi/2} ${-5*pi/4} 0" xyz="0 0 ${l1+offset2}"/> 
      #########################
      _**Joint axis (i+1) is defined with respect to the previous joint axis (i). In this case, ```i+1```   coord sys is rotated by ```Rx(90)*Ry(-5pi/4)``` and translated along ```z``` by ```l1+offset2``` wrt ```i``` coord sys**_
       #############################
      <parent link="${arm_id}_link1"/>
      <child link="${arm_id}_link2"/>
      <axis xyz="0 0 1"/>
      <limit effort="87" lower="-1.7628" upper="1.7628" velocity="2.1750"/>
    </joint>

Install ros dependencies in catkin_ws

  1. rosdep install --from-paths src --ignore-src -r -y inside your catkin_ws

Display urdf file in rviz

  • sudo apt-get install ros-melodic-xacro
  • sudo apt-get install ros-melodic-urdf-tutorial
  • Create the robot.xacro file in your catkin_ws/src/package_folder/urdf/
  • Create the robot.urdf.xacro file which has the following structure
    <robot xmlns:xacro="http://www.ros.org/wiki/xacro" name="free_floating_spacecraft_manipulator_3dof">
    <xacro:include filename="$(find free_floating_3_dof_arm)/urdf/free_floating_3dof.xacro" />
    <xacro:spacecraft_arm />
    </robot>
  • Run the command rosrun xacro xacro --inorder -o free_floating_3dof.urdf free_floating_3dof.urdf.xacro to get the urdf file
  • check_urdf free_floating_3dof.urdf to check if your urdf file is successfully parsed
  • roslaunch urdf_tutorial display.launch model:='$(find free_floating_3_dof_arm)/urdf/free_floating_3dof.urdf' or roslaunch urdf_tutorial display.launch model:='/path_to_the_folder_containing_urdf/filename.urdf'

Note: Necessay packages need to be installed

To create catkin_packages

  • catkin_create_pkg simple_navigation_goals geometry_msgs move_base_msgs actionlib roscpp rospy std_msgs

To convert xacro to urdf

rosrun xacro xacro --inorder -o model.urdf model.urdf.xacro

To get the transformation between parent and child frame

rosrun tf tf_echo /parent /child_frame

To create a catkin_ignore

touch /path/to/catkin_ws/your/package/CATKIN_IGNORE

Some useful rqt functionalities for debugging

rosrun rqt_tf_tfree rqt_tf_tfree # to see the tf_tree

rosrun rqt_graph rqt_graph # to see the nodes publishing and subscribing to topics

rosrun rqt_logger_level rqt_logger_level # to debug nodes

⚠️ **GitHub.com Fallback** ⚠️