Thursday, February 27, 2014

48. Robotics with PiBot. III - Running the Test Programs

12,000 page views!!
We're nearly at the point where we can start doing some exciting robotics!  There are currently four test programs for the PiBot - python programs which put the current system through its paces, to make sure all the hardware is working as it should. 

Firstly here is a listing of the firmware, which has to be running on the Bot Board's Arduino:

Notice that I have embedded these code listings from my Gist account on GitHub, which is where the open source software from the PiBot Team is published. These are my versions of the PiBot Team's software. Hopefully my future versions, on following Blog posts, will be advanced versions of these. As these are embedded, any changes I make to these on GitHub will be reflected in these listings, so I must be careful to generate new Gists.

The four python programs are:
1. drive_in_square.py,
2. monitor_ultrasonic.py,
3. robot_teleop.py and 

4. test_pibot_hardware.py.  
The code listings that I will give here contain some small adjustments which I made to suit my particular needs.

drive_in_square.py

This test program allows the PiBot to proceed in a straight line for a fixed time, make a right-angled turn, do a straight line, do a right angle, do a straight line and do a right angle - making a square shaped track.  The program continues indefinitely, so it has to be interrupted by performing a Ctrl-Z on the Pi's remote terminal on the PCfollowed by touching together the two flying leads on the PiBot to do an Arduino reset

You've seen this program in action in the last post, but here's the version with a shortened square:

OK - it's not quite a square - when I changed the speed, I should have adjusted the delay times too - anyway you get the gist! (where have I heard that word before?).

Here's the code:

Notice that the speed can be specified in the command line which runs the program.  Lines 11 and 12 pick up the argument if you put it in, and otherwise it assigns a default value. For example, if you enter the command:

python drive_in_square.py
the default value of speed at line 9 will be used, while the command
python Drive_in_square.py 255
will enable the command line argument with the value 255 to be picked up, and this value will override line 9.

monitor_ultrasonic.py
This program causes the ultrasonic transceiver to transmit and receive, so that the estimated distance to a solid object can be printed on the remote terminal.  The PiBot doesn't move.

Here it is running:


It may be a little difficult to see, but the screen gives a continuous readout of the distance from the ultrasound detector to a solid object - for example, my hand.

Here's the code:


robot_teleop.py
The teleop program makes the PiBot respond to 1-character keyboard commands - f for forward, b for backward, l for left, r for right turn and s for stop, each followed by an Enter

Here it is running:


It's not very slick, but remember that these are only test programs for checking that the hardware works properly.  The glamour comes later!

Here's the code:


test_pibot_hardware.py
This program tests all hardware connected to the PiBot.  Currently the final kit parts have not been fitted - the panning step motor and the tilting servo for aiming the PiCam, but the code for some of these functions is already there, ready for connection.

Here it is running:


The sound at the start is of bongos, followed by a 'drum-roll', and at the end of the routine there are 4 sounds - a klaxon sound, followed by a 'ding', followed by 2 cat meeows.  The distance estimated by the ultrasound transducer is displayed on the computer terminal, as in the previous program, monitor_ultrasonic.py.  The hardware that is attached appears to be working properly, including the 8-neopixel strip.   

The stepper motor and servo software is included, but this hardware hasn't been attached yet.

Here's the code:

Notice that I am using a couple of mp3 sound bites downloaded from the internet, including one of a cat meeow, hoping to stimulate some interest in our cat, but it doesn't fool her - she just ignores it!

What's next - I hear you say - well, some tidying up of the above, and dreaming up what I could make it do etc.

Some observations so far - the 4 x AA rechargeable batteries work a treat, and for a surprisingly long time.  I have 2 sets of 4 x 2400 mA-h AAs, so one set can be charging while I'm running the PiBot with the other set.  I haven't timed the workload available, but so far I have only had one episode (the Pi wouldn't boot) where the only remedy seemed to be to replace the batteries, and that worked.

Presumably by the time I start running the PiCam, the system will start to eat up batteries.  I'm happy that the Pi I'm using is a Model A because the power consumption is less (1.5W) than that of the Model B (3.5W).

Things I would like to do?

  1. I assume that I will be able to use the ultrasound distance system to prevent the PiBot from colliding with things - my SD card is getting an awful battering!
  2. Experimenting with combinations of colours of the neopixels.
  3. Of course, mounting the camera and transmitting images would be great. (ref HERE).
  4. I also have a successful XBee pair system working away (ref HERE), so I will try to think how that could be included in the PiBot.
  5. An IR receiver would be great, to smarten up the remote control. (ref HERE).
  6. I saw some code for a thermistor, and I would like to incorporate my previously-built thermopile system (ref HERE), which is still working away on my desk, telling me how cold a bag of ice is, or how hot my tea is.
  7. Another project which is working away on my desk very successfully, is the recently built light follower (ref HERE) - it works a treat and I would like to somehow incorporate that into the PiBot.
  8. I would like to put a powerful headlamp system on.  This could be self-powering like a high-power LED flashlight (or two?) (ref HERE).
  9. A talking system would be good.
  10. Get it to make my tea, wash the car.........

But first, I will try to fully understand and maybe explain, the current software.

No comments:

Post a Comment