Search This Blog


Saturday, October 1, 2016

Ros Tutorials: Communications Node V1

Let's keep on moving...

Here is the next installment in the ROS Tutorials series. Today, we are going to be writing a ROS node to control the Mega from Twist messages. Last time we defined a serial protocol for communicating motor data. First, the computer sends 0x41 to start a new message. Then the computer sends two bytes, one for the linear axis, and one for the angular. This then gets translated to servo movements that are then sent to the Sabertooth.
So here is the code:

The next step is to calibrate it and make sure that everything works.
That's all for now!

Friday, September 30, 2016

Ros Tutorials: Failsafe and Control

I'm back!

Today, we are going to look at how to add a failsafe and make a program that communicates with the computer.

First a schematic.

This is the schematic for the failsafe controller. I put this inside a small box with a battery so I could carry it in my hand without cords. The XBee radio inside is paired to a Xbee on the robot, connected to the Serial2 port on the Mega. That step should be fairly simple. Now here is the code for the failsafe controller:

And here is the code for the Mega on-board the robot:

This sets the failsafe such that, when the failsafe is activated, the led on the controller goes on. The failsafe can be activated one of two ways:
1. The Mega doesn't hasn't received a command in the past 500ms.
2. The button on the controller was pushed.
When the failsafe deactivates, the robot stops, and the LED will go off.

That's all for now!

Thursday, August 25, 2016

Ros Tutorials: Getting started, again!

Let's dive right in.

The first step in our master plan is to program the Arduino to communicate with the robot base, so we can move. To interface between the motors and the Arduino, I am using a Sabertooth 2x12 motor controller. I configured it to run with mixed steering RC inputs using the DIP switch wizard here. My DIP switches were set to 011110. To connect the Arduino to the Sabertooth, connect wires from ground, S1, and S2 on the Sabertooth to the GND, P5 and P6 pins on the Arduino. The Sabertooth will act like a pair of servos, so it makes it a snap to program. Here is a basic program to test the base with(NOTE: make sure that either the robot is on blocks or the motors are set to freewheel so it can't go anywhere.):

A quick note about code: all code from this project will be going into the GitHub repository where you can download the latest repository as I work on it.

Back to work. Now try running the code. The robot should move forward and left. Here are a few troubleshooting points:
If the robot is...
  • moving backwards: the polarities on your motors are reversed. 
  • moving right: the motors are swapped in the ports.
  • not moving at all: check your power, circuit breakers, and make sure that the Sabertooth is on. 
If you are having problems, feel free to leave a comment and I'll see if I can help.
My time to write is getting short, so I'm going to wrap it up here. We covered how to hook up the Sabertooth to the Arduino and how to test the motors. Till next time...

Wednesday, August 24, 2016

Ros Tutorials: I'm back!

Let's just say that I got distracted with other things, but I'm back, for a while(I hope)... The major problem I was encountering when I began this project was that I couldn't figure out how to use encoders to publish to /odom(Note: until I get around to adding a code formatter, I will be using bold to denounce code).

After over a year in the corner, I brought the project back out, and I think I found the solution. I had been looking at using RGBD-Slam for publishing odom, but according to this answer on ROS Answers, it is overkill, instead the author suggested using laser_scan_matcher. I'm going to give that a try.

I have slightly refined my hardware and software setup, as the available items have improved. This is not set in stone, but I'm thinking of using a Odroid XU-4 as the computer on board, with the Arduino Mega interfacing to the motors. I'm still using the Sabertooth motor controller.

Let me outline where I think this project will be headed:
  • Use Python to write a node that communicates with the Arduino, and incorporate sufficient failsafes. 
  • Map the values that Python uses with the Arduino to the velocities used in ROS(specifically cmd_vel)
  • Test the Kinect to make sure that it works on the Odroid.
  • Setup the transforms and setup pointcloud_to_laserscan.
  • Make a package with a launch file to run all the needed nodes.
  • Test everything up to here.
  • Make a map.
  • Setup navigation stack.
  • Have fun!
 So, to make each post easy for me to complete and write, I will probably make each one of the above topics into a post or two.

I need your help! You, the reader, showing interest, keeps me motivated to continue. If you would like to help with software, feel free to comment and I'll get back to you. Thank you for your continued support and (I know, it's cheesy) remember to follow and comment.

Edit: I forgot to include the first, most basic, thing: setup the Arduino to run the robot base. This will be the topic of discussion for my first post.

Monday, October 12, 2015

ROS Tutorials: It's October Already...

Sorry for the 5 week now 3 month delay. I have more school than anticipated and I am doing FTC with some friends so that occupies most of my robot time. I thought I would give an update on the status of the RosBot as I am growing to call it...

There is a major changelist:
  1. I decided to ditch the current Ros_Arduino_Bridge software and
  2. Implement the RosSerial_ Arduino package as a replacement for the above.
  3. Remove the encoders. 
  4. Lower the frame height.
  5. Make a permanent(somewhat) Kinect stand.
  6. Remove the Nerf gun.
  7. Implement(Work In Progress) Hector_SLAM.
The reasons for each decisions were many and most changes were applied to: (A.) Reduce complexity in both hardware and software, and (B.) Leave room for growing.

The RosSerial_Arduino switch was made because I was just fed up with the Ros_
Arduino_Bridge software. The RosSerial_Arduino(or Rosserial as it shall be known from henceforth on) interface is programmed by the user entirely on the Arduino. I preferred that because I am more proficient in Arduino than in Python. Once the old software was gone, I didn't want to write the new code for the encoders, so I decided to ditch them too. They caused more confusion and chaos than help and as of yet I haven't figured out the code for how to get them to work properly. To add insult to injury, the physical mounts that I had them on were also quite lacking and kept breaking.

I decided on items 4, 5, and 6 based on two things, A. that base needs to have as low of a CoG(Center of Gravity) as possible. B. If SLAM needs to locate obstacles based on a 2D laserscan, it should be at the approximate table height.

Hector_SLAM seemed to be the best match I could find for my 'bot. It does SLAM with one obvious con: the Kinect data must be converted to a laser scan(a.k.a. a 2D line) to be fed to Hector_SLAM. Obviously this has a limitation over other programs as it only processes onen slice of many in the data stream.

More changes to come....
'Patience my young padawan'

Wednesday, July 29, 2015

Ros Tutorials: It takes time...

Sorry for the 5 week delay... I can't focus really well and being on travel doesn't help either as it is kind of hard to move a 200 pound robot through 3 different airports... Enough of that chatter...
I am going to be busy for the next two weeks and then I start school again so I will not be having as much time to devote to this project as I would like, but I will try and follow my own advice and go through all of the ROS tutorials as I discussed earlier. So don't expect anything new for at least a month... :-(
Happy learning,

Wednesday, June 17, 2015

ROS Tutorials: Configuring your robot

Welcome back to part 3 of our series on getting started in ROS. Today we will setup the robot that we will be using. For beginners I reccomend a 2 motor platform such as a electric wheelchair(That is what I am using) or a Roomba base. If you want to shell out the cash and get a premade kit, just get a turtlebot. They are pricey but they work out of the box with as little work on your part as possible. If you choose the turtlebot you have all the code done for you. It is preferable that the platform is large enough to hold a laptop and, if you choose, a Microsoft Kinect. We will use the Kinect later for SLAM(Simultaneous Localization And Mapping). My setup uses an electric wheelchair with custom control circuitry, some scrap wood, and a nightstand bolted onto the chair as a platform. I admit that is crude but it works for me.

My base started out like this:
(Sorry for the bad photo)

After a lot of modifying(See here) I got to something that was at least usable.

I have a power inverter for the laptop and Kinect and 12V, 5V, and 24V for all of my low voltage needs. Due to my blowing one of the fuses by reversing polarity, I am currently using just an extension cord  for power.

To start hack your motors.
First figure out how it gets powered. In my case the motors got 24V.

Then hack the safety measures(if any). On my robot I have brakes on the motors that will not disengage until they get 24V applied to them.

Once you've done that, figure out your batteries. The wheelchair I bought had dead batteries so I was able to choose what batteries I wanted. I settled on two 35AH 12V AGM batteries(Click links for definition of terms). The frame had Powerpole connectors on all of the electrical connections so I kept those and just soldered jumpers to them. The batteries are wired in series to produce 24V and each battery has a circuit breaker on the positive lead. A 20 Amp DPDT Switch disconnects both batteries from the circuit and I use a terminal block to route all of the connections.

Now enough of my bragging and showing off, let's get back to your robot. It really doesn't matter how you wire up your 'bot as long as your use the Sabertooth to run the motors. Oh yeah, I almost forgot. No really, I'm not kidding...

A word about encoders: Encoders are the heart of your robot. Without them you cannot drive your robot with ROS... I reccomend starting simple and working your way up. I have photointerrupters, which are as simple as can be. It is, in a nutshell, a light on one side and a light sensor on the other that senses when a toothed disc turns. It produces one pulse for every tooth on the wheel regardless of direction. It requires more coding than some other methods such as SPI drivers because you need to know the direction of rotation of the motors. I pulled my encoders from an old HP printer and used laminated paper wheels that I printed off the internet. I then attached the wheels directly to the wheels and made a wood boom to hold the encoders on the edge of the laminated wheel. You can just barely see them on both sides of the robot in the image above.

Enough of that, configure your Sabertooth with the tool I mentioned in a previous post to use microcontroller simple serial mode.

Now it's time to wire it all up! Connect the S1 port on the Sabertooth to pin TX2 on the Arduino Mega and connect the signal pins of your photo-interrupters to pins D2 and D3 for the right and left wheels respectively.

Now your robot is ready to roll!