Mecanumbot Ball Following December 10, 2013
I have updated my Mecanumbot code to the latest and greatest ROS distribution – Hydro. During the upgrade, I wrote a companion app to publish velocity commands based of of the output of my ball tracker. The result is that the Mecanumbot can follow a red ball around the room!
I wrote the ball tracking code itself back in college. The segmentation approach is pretty naive, but I only spent a few hours on it so I was pretty happy with the results. The code starts with the point cloud generated by the Kinect. The cloud is reduced by filtering out all points that are not red. A statistical outlier filter is used next to clean up residual noise points. Finally, the cloud is segmented into clusters (small clouds) based on distance. The largest cluster is then considered the point cloud of the ball. A transform between the Kinect and average position of the ball’s point code is broadcasted using the tf library. As a bonus usability features, when at least one cluster is present, the Mecanumbot’s lights turn green!
In order have the robot actually move, a simple controller was created to listen to the aforementioned transform and to publish Twist messages on the cmd_vel topic. A barely did any tuning of the proportional gain here. Since I only made tiny movement in the video, it is hard to see, but the current gain is actually a little strong. When coupled with the low refresh rate of the ball’s position (all processing is done onboard the Mecanumbot’s computer), the robot often oscillates rotationally even when the ball isn’t moving.
The tracking algorithm presented here is pretty fragile. Here are some ideas which could make it a little more robust:
- segment using HSV color space instead of RGB – this will allow more robust color matching in different light scenarios while simultaneously lowering the number of false positives
- use additional properties of the ball to improve segmentation – for example, filter clusters against the balls size and the known curvature
- pass the output through a Bayes filter to clean out infrequent false positives
- add a derivative component to the controller to reduce oscillation
- add an integral component to the controller to fix small offsets long term (would be useful for the carpet I was on)