Maker Pro

Nano Class Sumo Robot – PICAXE

Autonomous Nano Sumo Robot - Code and schematic are included.

Project Log

Well all the projects I have had going recently have either been finished, or they are on hold waiting for a china order to come in. So I needed a cheap project to occupy my time. I decided to build a Nano Sumo Robot. The Nano class Sumo Robots have to be smaller than 2.5 centimeters2 and weigh less than or equal to twenty-five grams. Getting the robot to be 2.5 centimeters2 shouldn’t be that hard, but making the robot weigh less than or equal to twenty-five grams might be a problem (hopefully not).

Here’s the circuit I designed for it:

Schematic_Epsilon_Nano_12_5_14.jpg


Most of the H-Bridges I tried out before this robot didn’t work, so I did some searching on the internet on why they didn’t work and how to fix it. I found a nice article (namely Here) that explained some stuff about them and showed some H-Bridge designs that work quite well. So I picked one out and tried it on the breadboard, and sure enough: it worked like a charm!

The robot uses U2 (a TSOP4038) to sense its opponent. The way it works is: the MCU sends out a 38 KHz IR signal, and when the other robot is in front of it, it reflects back to the TSOP4038 and tells the MCU that the other robot is right there.

The Power supply is just two CR2032 3VDC batteries in series fed through a 1N4007 diode to get about 5.5VDC. I hope they last more than 15 minutes with the robot running!

Here’s the code (NOTE: it is going to need some timing adjustments when the robot is built, and I don’t know just how well it works):


Code:
;*********************************************************;
;*              <- START OF EPSILON CODE ->              *;
;*********************************************************;

;*********************************************************;
;* This program is for the 14M2 on board of the Epsilon  *;
;* Nano Class Sumo Robot. It checks the state of two     *;
;* edge sensors on the front of the robot and also keeps *;
;* track of one IR sensor. The IR sensor is a TSOP4038   *;
;* and it is mounted on the front of the robot. It is    *;
;* used for finding the other robot in the ring. The     *;
;* program also sends out a 38KHz signal for an IR LED.  *;
;*********************************************************;

;***********************PIN_LAYOUT************************;
;*  PIN___FUNCTION || PIN___FUNCTION || PIN___FUNCTION   *;
;*  C.4   HB1      || C.2   HB2      || C.1   HB3        *;
;*  C.0   HB4      || B.1   LDR1     || B.2   LDR2       *;
;*  B.3   TSOP4038 || B.4   IR LED   ||                  *;
;*********************************************************;

;*********************************************************;
;* This section is for renaming variables and constants  *;
;*********************************************************;
;**Pin renaming**;
symbol HB4=c.0
symbol HB3=c.1
symbol HB2=c.2
symbol HB1=c.4
symbol LDR_ONE=pinb.1
symbol LDR_TWO=pinb.2
symbol TSOP4038=pinb.3
symbol IR_LED=b.4
;**Lock out time renaming**;
symbol TURN_TIME_LDR1_LDR2_ONE=1000
symbol TURN_TIME_LDR1_LDR2_TWO=1000
symbol TURN_TIME_LDR1_ONE=1000
symbol TURN_TIME_LDR1_TWO=1000
symbol TURN_TIME_LDR2_ONE=1000
symbol TURN_TIME_LDR2_TWO=1000
;**Variables renaming**;
symbol ENDLESS=bit31
symbol ADC_RESULT_ONE=b4
symbol ADC_RESULT_TWO=b5
symbol LOCK_OUT_VAR=w3
;**Random renaming**;
symbol ADC_VALUE_ONE=128
symbol ADC_VALUE_TWO=128

;******************H-BRIDGE_TRUTH_TABLE*******************;
;*      |  HB1  |  HB2  |  HB3  |  HB4  |  Move  |       *;
;*      ------------------------------------------       *;
;*      |   0   |   1   |   0   |   0   |  Right         *;
;*      ------------------------------------------       *;
;*      |   1   |   0   |   0   |   0   |  Back Right    *;
;*      ------------------------------------------       *;
;*      |   0   |   0   |   0   |   0   |  None          *;
;*      ------------------------------------------       *;
;*      |   0   |   0   |   0   |   1   |  Left          *;
;*      ------------------------------------------       *;
;*      |   0   |   0   |   1   |   0   |  Back Left     *;
;*      ------------------------------------------       *;
;*      |   1   |   0   |   1   |   0   |  Back          *;
;*      ------------------------------------------       *;
;*      |   0   |   1   |   0   |   1   |  Forward       *;
;*      ------------------------------------------       *;
;*      |   0   |   1   |   1   |   0   |  Hard Left     *;
;*      ------------------------------------------       *;
;*      |   1   |   0   |   0   |   1   |  Hard Right    *;
;*      ------------------------------------------       *;
;*    NEVER!! Have HB1 and HB2 on at the same time!      *;
;*    NEVER!! Have HB3 and HB4 on at the same time!      *;
;*********************************************************;

;*********************************************************;
;* This section is used for keeping track of what        *;
;* variables have been used                              *;
;*********************************************************;
;* bit31/b3/w1 || b4/b5/w2 || b6/b7/w3                   *;
;*********************************************************;
;*********************************************************;
;* MAIN: the part of the program waits for five seconds  *;
;* before starting the robot (as required by the robot   *;
;* sumo rules). It also sets the system clock to 32MHz   *;
;* and it outputs a 38KHz PWM for the IR LED.            *;
;*********************************************************;
main:
    pwmout IR_LED, 210, 421 ; 38KHz at 50% @ 32MHz
    pause 5000 ;pause for 5 seconds
    setfreq m32 ;set system frequency to 32MHz.
    ;fall through
;*********************************************************;
;* START: this part of the program moves the robot until *;
;* it sees an edge or it see another robot. This is the  *;
;* default state.                                        *;
;*********************************************************;
start:
    do
    low HB1,HB3
    high HB2,HB4 ;move forward
    gosub CHECK_EDGE_SENSORS ;check the edge sensors
    if TSOP4038=1 then ;robot is facing other robot
        do ;start endless loop
        low HB1,HB3
        high HB2,HB4 ;move forward
        gosub CHECK_EDGE_SENSORS ;check the edge sensors
        if TSOP4038=0 then ;robot is no longer facing other robot so
            do ;start endless loop
            low HB2,HB3
            high HB1,HB4 ;take a hard right
            gosub CHECK_EDGE_SENSORS ;check the edge sensors
                  if TSOP4038=1 then ;the other robot moved right and this robot is
                             ;now facing it so
                    goto start ;move forward again
                endif
            loop until ENDLESS=1 ;endless loop
        endif
        loop until ENDLESS=1 ;endless loop
    endif
    gosub CHECK_EDGE_SENSORS ;check the edge sensors
    low HB2,HB3
    high HB1,HB4 ;robot is not facing other robot so take a hard right
    loop until ENDLESS=1 ;endless loop
;*********************************************************;
;* CHECK_EDGE_SENSORS: this function checks the edges    *;
;* sensors and if any of them are on, it moves the robot *;
;* away from the edge it is close to                     *;
;*********************************************************;
CHECK_EDGE_SENSORS:
    readadc ADC_RESULT_ONE,LDR_ONE ;read ADC from LDR1
    readadc ADC_RESULT_TWO,LDR_TWO ;read ADC from LDR2
    if ADC_RESULT_ONE>ADC_VALUE_ONE then ;if the LDR1 has detected a edge
        if ADC_RESULT_TWO>ADC_VALUE_TWO then ;both LDR1 and LDR2 have detected an edge
            do ;start delay loop
                low HB2,HB4
                high HB1,HB3 ;back up
                inc LOCK_OUT_VAR ;inc variable for delay loop
            loop until LOCK_OUT_VAR=TURN_TIME_LDR1_LDR2_ONE
            let LOCK_OUT_VAR=0 ;reset delay loop time variable
            do ;start delay loop
                low HB1,HB3,HB4
                high HB2 ;take a right
                inc LOCK_OUT_VAR ;inc variable for delay loop
            loop until LOCK_OUT_VAR=TURN_TIME_LDR1_LDR2_TWO
            let LOCK_OUT_VAR=0 ;reset delay loop time variable
            return
        endif
        do ;only LDR1 is on
                low HB2,HB4
            high HB1,HB3 ;back up
            inc LOCK_OUT_VAR ;inc variable for delay loop
        loop until LOCK_OUT_VAR=TURN_TIME_LDR1_ONE
        let LOCK_OUT_VAR=0 ;reset delay loop time variable
        do ;start delay loop
            low HB1,HB4
            high HB2,HB3 ;take a hard left
            inc LOCK_OUT_VAR ;inc variable for delay loop
        loop until LOCK_OUT_VAR=TURN_TIME_LDR1_TWO
        let LOCK_OUT_VAR=0 ;reset delay loop time variable
        return
    endif
    if ADC_RESULT_TWO>ADC_VALUE_TWO then ;only LDR2 is on
        do ;start delay loop
                low HB2,HB4
            high HB1,HB3 ;back up
            inc LOCK_OUT_VAR ;inc variable for delay loop
        loop until LOCK_OUT_VAR=TURN_TIME_LDR2_ONE
        let LOCK_OUT_VAR=0 ;reset delay loop time variable
        do ;start delay loop
            low HB2,HB3
            high HB1,HB4 ;take a hard right
            inc LOCK_OUT_VAR ;inc variable for delay loop
        loop until LOCK_OUT_VAR=TURN_TIME_LDR2_TWO
        let LOCK_OUT_VAR=0 ;reset delay loop time variable
    endif
    return
;*********************************************************;
;*               <- END OF EPSILON CODE ->               *;
;*********************************************************;

;*********************************************************;
;* Update History:                                       *;
;* 12/2/2014 - Code complete - Supercap2F                *;
;*********************************************************;

I have tried to make the code as self-explanatory as I could with comments… But I don’t know just how well that turned out.

And here’s the PCB (the orange layer is the top):

Top_PCB_Epsilon_Nano_12_3_14.JPG Bottom_PCB_Epsilon_Nano_12_3_14.JPG

Since the space was so small that I had, I cheated a little and put some components under the PICAXE 14M2 (I hope it doesn’t cause any noise issues!). The plan is to mount the PCB vertically, and put a tin sheet over the front to protect the components.

I’m going to solder some LDRs directly to the board (in the places labeled “LDR1” and “LDR2”), so that they will be pointed towards the ground. I’m also going to put the LEDs (D10 and D11) at an angle so they’re also pointed towards the ground. The LDRs will measure the light reflected off of the ground. So when the robot comes to an edge on the ring, it will since that the ground has changed from black to white and it will tell the MCU to move the other way. The LDRs are hooked up in a voltage divider configuration with some resistors (see schematic) and are fed into the PICAXEs ADC pins.

Here’s a 3D model of the PCB:

3D_PCB_Epsilon_Nano_12_3_14.JPG 3D_Bottom_PCB_Epsilon_Nano_12_3_14.JPG

I bought the PCBs already though OSH Park (they cost USD 5.90 just BTW), so that’s why the 3D model is in purple. I haven’t had time to model the robot in 3D yet, but I’m thinking about doing it later. For the motors, I bought some gear heads on Ebay (Here if you are interested). According to the listing they measure only 30 x 12 x 8 which will be just about perfect for this robot! They are also said to weigh three grams… But I have a hard time believing that.



Update on 12/15/14:


Well the PCBs came in on Saturday. Here's a photo of two of them:

IMG_9904.jpg

And here's a photo of one of them with the main trough-hole parts fitted (but not soldered yet):

IMG_9901.jpg

Unfortunately two drills where missed (the ones for the TSOP4038). Looking back on the preview of the board OSHPark gave me before ordering, shows that there are no drills there. I guess I some how made an error when I exported the board. With some fancy soldering I think I can fix it though...

Update on 1/1/15:

Well the motors finally came in, and to my great joy they were smaller than I thought they would be! And they only weigh 3.3 grams! Photo:
IMG_0182.JPG
That scale didn’t cost dirt though, so the extra 0.3 grams away from what the seller said is most likely just the scale. The motors have a little bit of extra plastic on the side of them, which I had to hack off to make them sit flat on the ground when they’re on the robot:
IMG_0231.JPG
Luckily it was cheap plastic so an x-acto took it right off! I was also able to finish the 3D model of the robot:
Full-3D-Epsilon-Robot-12-31-14.JPG.jpg

This model is rendered without the front metal on (I plan to use a thin sheet of tin to protect the front or the robot and to isolate the IR sensor from the detector). I’m still considering where I’m going to have the batteries mounted. I was originally going to have them on the top in a modified CR2032 battery holder, but when I put that on the model it looked quite awkward so I decided against it. Once the main part of the model is built, I will figure that out. :D

Update on 5/12/15

Well I found out why the motors where so cheap! After mounting them and doing a very slight mod, they fell apart. :mad: Oh well, I guess I will just have to try to find some other ones...
Dan

Item information

Added by
Supercap2F
Views
3,273
Watchers
1
Last update

More in Project Logs

More from Supercap2F

Share this item

Top