Wednesday, May 11, 2022

ROS Problems

 

When integrating a bunch of different components there are certainly some expected difficulties. The way that ROS nodes work is by sending each other messages that are published to certain topics.

A single node can have multiple subscribers and publishers in it that can send and receive messages.

Each message has a certain type and a definition file that controls what is sent in the message.

I ran into a problem when trying to send over a list of 4 integers that would represent velocities on the 4 motors.

ROS has a message type for a multi-dimensional array, but not a single array. To send a multiple dimension array message, you need to specify a bunch of parameters such as dimensions which I didn’t want to bother with.

So, I set out to create my own custom message type. To do so I first needed to create a package, then create a message file on my raspberry pi. This was relatively easy, however I quickly realized that I also needed to generate a header file for the Arduino to understand the message. This is where the trouble began.

I followed the tutorial for header file generation, but it didn’t work!

What I was missing is that instead of rosclient I should have used rosArduino in the command. And the destination needs to be empty of ros lib. After fixing a couple of other issues I was finally able to generate the h file.

Then I learned how to use scp to copy the file from the raspberry pi onto windows, so I could put it into the Arduino library.

After doing all that I was ready to test.

To my great disappointment, the raspberry pi couldn’t sync to the Arduino. Something about my custom message was messing it up, and I just kept the same error over and over again.

Finally, I gave up and decided to use the overkill MultiArrayFloat32 message. Float64 is not accepted by the Arduino!

When I tested before I just used the rospub command and published an empty message or a couple of integers, but MultiArray was a whole other beast.

I couldn’t figure out the format for the life of me. BUT. If you push tab it autocompletes it for you!

After I learned that I was able to publish a list of integers to the robot and it turned on the motors!

Huge success!

Next, I included a publisher node into my kinematics node, which published a Multi array message. Publishing messages that way was a lot easier as I was able to use the attributes of the message object.

PID tuning

One thing that is really important in robotics is PID. Which stand for proportional, integral, differential methods of control.

Essentially it is a method for controlling the system based on the error.  For me this was essential, because my motors spin even after you cut off the power. I started with making a PID controller to control position.

I created a controller function and started graphing the target position as well as the actual.

I frequently ran into the problem where the wheel would oscillate around zero, never fully stopping.

This was super annoying and disheartening because I wanted my robot to be really precise. Eventually I ended up putting in a tolerance of 5% and telling the robot to shut off the motors if it got within that margin. This improved the issue drastically.

However, the wheels performed differently. At this point I was considering making a controller for each individual wheel and creating their own constants, but that seemed too time consuming.

The good news was that on the ground the robot wheels didn’t oscillate, because of the friction. Although the robot didn’t really drive straight.

No comments:

Post a Comment

NEW Project Autonomous underwater vehicle!

  I have been more and more interested in Autonomous Underwater Vehicles and ocean exploration. I live on the coast with direct access to th...