Society of Robots - Robot Forum

Software => Software => Topic started by: Trumpkin on January 27, 2008, 07:59:56 PM

Title: programming problem
Post by: Trumpkin on January 27, 2008, 07:59:56 PM
Code: [Select]
#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_on();//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
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.

***********************************************************/
Ok so I basically comented out everything on Admins Photovore code but led on and the servo right and left. I got it to compile and download to the robot. But when I turn the 'bot on it doesn't do anything except for the jerk of the servos. The modify a servo .hex code did work.
Title: Re: programming problem
Post by: airman00 on January 27, 2008, 08:12:12 PM
did you modify the servos correctly

what do you mean , by the jerk of the servos?
Title: Re: programming problem
Post by: Trumpkin on January 27, 2008, 08:20:43 PM
when you first give power to the servos they jerk
Title: Re: programming problem
Post by: Trumpkin on January 27, 2008, 08:25:25 PM
And yes I followed Admins directions for modifying servos exactly.
Title: Re: programming problem
Post by: Trumpkin on February 01, 2008, 09:36:26 AM
I changed my code a little bit by putting in a delay will some1 please tell me if this will work?
Code: [Select]
//SoR Include
#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_on();//turn LED on
    delay_cycles(1000);

//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);
delay_cycles(500);
}

//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
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.

***********************************************************/
Title: Re: programming problem
Post by: bukowski on February 01, 2008, 10:48:22 AM
It's doing exactly what you are telling it to do.
You put the entire body of the program in comments.
Title: Re: programming problem
Post by: Trumpkin on February 01, 2008, 12:05:33 PM
no i didn't
Code: [Select]
servo_left(44);
servo_right(44);
delay_cycles(500);
}
:P the same with the LED, anyways if i'm doing something wrong plz some 1 tell me how to do it right. all i want it to do is move right and left servos and turn on the LED. What I really want is if someone can just post code for the $50 robot to make the servos move and the LED turn on.thx
Title: Re: programming problem
Post by: bukowski on February 01, 2008, 12:10:28 PM
You already have that code. it's the "servo test code" lines.
Title: Re: programming problem
Post by: Admin on February 16, 2008, 05:59:54 PM
this is your code:
servo_left(44);
servo_right(44);
delay_cycles(500);

your servo is jerking because your code is telling it to jerk! (notice how you say 'go left' then suddenly say 'go right')

as for the LED code . . . you just posted it ;)
(at the bottom, where it says 'COMMAND LIST')
Title: Re: programming problem
Post by: Trumpkin on February 19, 2008, 05:07:57 PM
the LED on code does not work. also my microcontroller does not program reliably  :'(. It works sometimes and then it doesn't work other times.
Title: Re: programming problem
Post by: Admin on February 23, 2008, 02:18:45 PM
Quote
the LED on code does not work
perhaps your LED is soldered wrong, or is broken? several people have had it fry on them, including me . . .
Title: Re: programming problem
Post by: Trumpkin on February 23, 2008, 03:38:34 PM
nope i tested it. I know it is connected right.
Title: Re: programming problem
Post by: paulstreats on February 23, 2008, 07:16:32 PM
just a quickie reply.

If code will compile, then it will work on the mcu like you instructed it to. If it wont work on the mcu then it wont compile.

Have you compiled your code?

Are your solder joints okay, they may look it but have you checked? using multimeter at least, sometimes breakages in solder dont conduct even if they look like they do.

If your code compiles and downloads onto your mcu then it is an electronic/hardware problem
Title: Re: programming problem
Post by: Trumpkin on February 24, 2008, 03:00:20 PM
the code compiles fine. the solder joints are ok. when it does download to my Atmega it works. i just recently changed to the atmega 168 and made all the changes in the code.