3.3 Programming the Robot

Now we need to program the robot.

 

At first, I started working on the PIC board. For odd reasons, it did not work. So I'll get back to you on that.

 

For the AVR board, I found the Axon would be the best candidate. So, Here's some of the programming I did:


//variable declaration for RC inputs

unsigned int L1=100; //Left motor output 1
//unsigned int L2=100;  //   "      "         "    2
//unsigned int R1=100; //  Right Motor output 1
//unsigned int R2=100; //     "        "       "     2
 
void refresh_ADC(void)        //Sensor Refresh Subroutine
    {
    L1=a2dConvert8bit(2); //ADC port 2, 3, 4, and 5
    //L2=a2dConvert8bit(3);
    //R1=a2dConvert8bit(4);
    //R2=a2dConvert8bit(5);
    }
 
void control(void)
    {
 
    while(1)
        {
        int Set_Value=100; //Set comparison value
 
        refresh_ADC();  //Refresh sensor Value
 
        if(L1>Set_Value)  
            {                        
            // Place custom code here
            //rprintf("Input Signal L1=%d ",L1);
             }
 
         else if(L1<Set_Value)
            {                        
            // Place custom code here
            //rprintf("Input Signal L1=%d ",L1);
            }
        }
    }

 

This is only a segment of the whole program which is meant to go in control.c That code only does the ADC conversion for you the section commented out that says "custom code here" is where your own robot code goes. For starters, I tested on moving a servo back and forth.

 

Something else about this set-up; it is helpful to use a pull-up or pull-down resistor. I discovered this first when testing out the program, making a servo do pre-sequenced movements. When the servo kept moving after having released the controls, I knew there was something wrong. I used the SoR Scope to monitor the outputs of the RC receiver. The voltage level would vary ~70-120 (on a scale from 0 to 255).

This has it's advantages in a sense that you could leave the controls and ignore the robot while it does it's task. The problems being that (1) Eventually, the voltage may drift below the "High" level, and (2) To compensate for the fluctuating voltage, you must turn the controls in the opposite direction in order to bring it back down.