go_away

Author Topic: $50 dollar robot Programming problems?  (Read 1472 times)

0 Members and 1 Guest are viewing this topic.

Offline jdub247Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
$50 dollar robot Programming problems?
« on: March 26, 2009, 07:40:45 AM »
First of all I am only assuming it is programming..........

 I just finished building the 50$ robot. I didnt build the body i have just built the electronics portion. I made my own PCB from the PDF supplied in one of the links I think by WEBBOT. Anyways programming went fine. I had to change the output port from 0 and 1 to 2 and 3 because of the way the PCB is laid out. When I power up everything the servos move slightly in one direction. Then if i move the sensors around, cover them etc... the servos only move slightly again, these movements occur for different amounts of time and in different directions and there is no movement other than when i move the sensors around. So basically there is no motion (if it was sitting on a body that is.) has anyone encountered problems like this? Any solutions?

Offline blackheart

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
Re: $50 dollar robot Programming problems?
« Reply #1 on: March 26, 2009, 10:49:40 AM »
Can we see your code?

I think your problem is in the value you output to the servos. Try giving the servos a higher value, see if they move.

I didn't understand what exactly is your problem!



Oh, and welcome to Society Of Robots!


Enjoy!
I'm out of ideas!

Offline jdub247Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: $50 dollar robot Programming problems?
« Reply #2 on: March 26, 2009, 01:20:53 PM »
Here is the source code I am using.


#include "SoR_Utils.h" //includes all the technical stuff


int main(void)
   {
   //declare variables here
   //int i=250;//a 'whatever' variable
   int sensor_left=0;//left photoresistor
   int sensor_right=0;//right photoresistor
   int threshold=8;//the larger this number, the more likely your robot will drive straight
   

   /****************INITIALIZATIONS*******************/
   //other stuff Im experimenting with for SoR
   //uartInit();  // initialize the UART (serial port)
   //uartSetBaudRate(9600);// set the baud rate of the UART for our debug/reporting output
   //rprintfInit(uartSendByte);// initialize rprintf system

   //timerInit(); // initialize the timer system
   
   configure_ports(); // configure which ports are analog, digital, etc.
   a2dInit(); // initialize analog to digital converter (ADC)
   a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling
   a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage

   //rprintf("Initialization Complete\r\n");
   /**************************************************/

   
   /*********ADD YOUR CODE BELOW THIS LINE **********/
   LED_off();//turn LED on


   while(1)
      {
      //store sensor data
      sensor_left=a2dConvert8bit(5);
      sensor_right=a2dConvert8bit(4);


      //detects more light on left side of robot
      if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold)
         {//go left
         servo_left(44);
         servo_right(44);
         }

      //detects more light on right side of robot
      else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold)
         {//go right
         servo_left(25);
         servo_right(25);
         }

      //light is about equal on both sides
      else
         {//go straight
         servo_left(25);
         servo_right(44);
         }


      /* Servo Test Code
      int i=0;
      i=250;
      while(i>0)
         {
         servo_left(40);
         i--;
         }

       i=250;
      while(i>0)
         {
         servo_left(24);
         i--;
         }*/
      

      //rprintf("Initialization Complete\r\n");
      
      //output message to serial (use hyperterminal)
      //print("Hello, World! Read My Analog: %u\r\n", sensor_0);

      delay_cycles(500);//a small delay to prevent crazy oscillations
      }
   /*********ADD YOUR CODE ABOVE THIS LINE **********/

   return 0;
   }


/*********************COMMAND LIST*************************

delay_cycles(cycles);
Delays - you can make your robot wait for a certain amount of time with this function.
Put the number of computational cycles to delay in the ().
23 cycles is about .992 milliseconds
to calculate: 23/.992*(time in milliseconds to delay) = cycles
Check servo datasheet where it says: 'Direction: Clockwise/Pulse Traveling 1500 to 1900usec'


servo_left(speed); and servo_right(speed);
Commands your servos to rotate at a certain speed.
Vary speed (which represents a delay in cycles) from 20 to 50.
Left is for port D0 and right is for port D1.


LED_on(); and LED_off();
Turns on and off your LED. The LED is on port D4.
By bringing port D4 low, you are turning on the LED.


variable=a2dConvert8bit(pin);
Reads analog pin. For example, set 'pin' to 5 to read PC5.
'variable' will store the value.

***********************************************************/

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: $50 dollar robot Programming problems?
« Reply #3 on: April 14, 2009, 12:09:50 AM »
So this problem occurs without modifying the code in any other way except the ports?

Get out a multimeter and take measurements everywhere. It sounds like voltages aren't correct.

What battery are you using to power the servos and mcu?

 


Get Your Ad Here

data_list