ROS Essential Skills
ROS Naming Convention
Class name is still camelCase: class TrackerUI
Var names are small case underbared: var roi_window
Function names are small case verb front underbared: func get_roi_window
I feel it is comfy to do things in this way rather than the camelCase and just try to shorten every variable in one or two words, not too fancy.
ROS Workspace Structure
How to organize your packages & workspaces
-
If the project is based on a unique instance, for example, it will finally be applied to a robot then make it a separate
ws
named folder under the companyws
folder. In this case, you should make the whole project a repo. -
If this project is an implementation of a small function — a simple ROS package, put it in under the
catkin_ws/src
folder that under the companyws
folder. You can always put the non-ROS related project under this folder and treat them as a package. Make each single package a repo. I'll show how in the folder tree view below.
This is helpful to isolate the package functions and also help to use the find pkg
inline macro to merge packages together for a bigger project.
When you need to publish a product, for example, copy over all the function package you developed in the catkin_ws and make a commit, nothing needs to change.
Do this under the "git root" folder to link the folder to a remote
First, you should create the remote repo online. Then do
git remote add origin git@github.com:User/UserRepo.git
<COMPANY_NAME>_ws # manually create this folder, it should be a catkin ws
└── src # manually create this
│ └── <PROJECT_NAME> # your project root git(the root git folder name)
│ ├── install # not a ros package, install your robot
│ │ ├── rules
│ │ └── scripts
│ ├── <PROJECT_NAME>_description # your robot ROS package
│ ├── <PROJECT_NAME>_nav # your robot ROS package
│ ├── <PROJECT_NAME>_robot # your robot ROS package
│ ├── kinect_aux # 3rd party ROS package
│ ├── README.md
│ └── CMakeLists.txt
ROS [Joy] Using Guide
First, you need to install the package:
sudo apt-get install ros-<distro>-joy
Get the test
sudo jstest /dev/input/jsX
device to use- the default is js0.
roscore
rosparam set joy_node/dev "/dev/input/jsX"
Now we can start the joy node.
rosrun joy joy_node
Echo the /joy
topic to figure out the real date order. In general here is how the callback looks like.
ROS [Param Server] Get Parameters
rospy.get_param(param_name)
- Fetch value from the Parameter Server. You can optionally pass in a default value to use if the parameter is not set. Names are resolved relative to the node's namespace. If you use get_param() to fetch a namespace, a dictionary is returned with the keys equal to the parameter values in that namespace. KeyError is raised if the parameter is not set.
global_name = rospy.get_param("/global_name")
relative_name = rospy.get_param("relative_name")
private_param = rospy.get_param('~private_name') # `~` = `NODE_NAME/`
default_param = rospy.get_param('default_param', 'default_value')
# fetch a group (dictionary) of parameters
gains = rospy.get_param('gains')
p, i, d = gains['P'], gains['I'], gains['D']
so in this feature_type = rospy.get_param("~feature_type","SIFT")
you can actually set and get back the param at same time.
ROS Node Param
There are two param types, one is global, one is local. You will find the local param in ROS doc prefixed with ~
.
How to set local param from a terminal?
For example. In ROS joint state node:
~use_gui (Boolean, default: False)
- Whether to use the GUI or not
This should be used as :
rosrun joint_state_publisher joint_state_publisher _use_gui:=true
Where in a launch file you should do:
<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" output="screen"/>
<param name="use_gui" value="true"/>
ROS [Topic] Publish Once No data array
rostopic echo /front_cam/image_raw --noarr -n1
ROS [Service] Command Line Call
rosservice call /stop_motor "{}"
ROS [TF] View
rosrun tf view_frames
Wait for this to complete, and then type in:
evince frames.pdf
ROS [Navigation Stack] Cancel A Goal
To cancel a move_base planning
rostopic pub /move_base/cancel actionlib_msgs/GoalID -- {}