Hello.
Sorry for English.
I’m making a robot for a championship, I’ve got the 3pi, but it was decided that we could not use robots purchased, and how this at the last minute of the championship does not have much time to program it, already built the robot using the baby orangutan QTR-1RC and sensors.
The position of the sensors is the same as the 3pi.
What must be the change of the code to be used in 3pi orangutan?
Following is the code that I have:
#include <pololu/3pi.h>
#include <pololu/orangutan.h>
#include <avr/pgmspace.h>
#include <avr/io.h>
const char welcome_line1[] PROGMEM = " Triton";
const char welcome_line2[] PROGMEM = " Robos";
const char demo_name_line1[] PROGMEM = "Seguidor";
const char demo_name_line2[] PROGMEM = "de Linha";
const char welcome[] PROGMEM = ">g32>>c32";
const char go[] PROGMEM = "L16 cdegreg4";
const char levels[] PROGMEM = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
void load_custom_characters()
{
lcd_load_custom_character(levels+0,0);
lcd_load_custom_character(levels+1,1);
lcd_load_custom_character(levels+2,2);
lcd_load_custom_character(levels+3,3);
lcd_load_custom_character(levels+4,4);
lcd_load_custom_character(levels+5,5);
lcd_load_custom_character(levels+6,6);
clear();
}
void display_readings(const unsigned int *calibrated_values)
{
unsigned char i;
for(i=0;i<5;i++) {
const char display_characters[10] = {' ',0,0,1,2,3,4,5,6,255};
char c = display_characters[calibrated_values[i]/101];
print_character(c);
}
}
void initialize()
{
unsigned int counter;
unsigned int sensors[5];
pololu_3pi_init(500);
load_custom_characters();
print_from_program_space(welcome_line1);
lcd_goto_xy(0,1);
print_from_program_space(welcome_line2);
play_from_program_space(welcome);
delay_ms(1000);
clear();
print_from_program_space(demo_name_line1);
lcd_goto_xy(0,1);
print_from_program_space(demo_name_line2);
delay_ms(1000);
while(!button_is_pressed(BUTTON_B))
{
int bat = read_battery_millivolts();
clear();
print_long(bat);
print("mV");
lcd_goto_xy(0,1);
print("Press B");
delay_ms(100);
}
wait_for_button_release(BUTTON_B);
delay_ms(1000);
for(counter=0;counter<80;counter++)
{
if(counter < 20 || counter >= 60)
set_motors(70,-70);
else
set_motors(-70,70);
calibrate_line_sensors(IR_EMITTERS_ON);
delay_ms(20);
}
set_motors(0,0);
while(!button_is_pressed(BUTTON_B))
{
unsigned int position = read_line_white(sensors,IR_EMITTERS_ON);
clear();
print_long(position);
lcd_goto_xy(0,1);
display_readings(sensors);
delay_ms(100);
}
wait_for_button_release(BUTTON_B);
clear();
print("Go!");
play_from_program_space(go);
while(is_playing());
}
int main()
{
unsigned int sensors[5];
unsigned int last_proportional=0;
long integral=0;
long m=0;
long y=0;
long x=0;
long w=0;
long a=0;
initialize();
DDRD &= ~(1 << PD0);
PORTD |= (1 << PD0);
DDRC &= ~(1 << PC5);
PORTC |= (1 << PC5);
while(1)
{
unsigned int position = read_line_white(sensors,IR_EMITTERS_ON);
int proportional = ((int)position) - 2000;
int derivative = proportional - last_proportional;
integral += proportional;
last_proportional = proportional;
int power_difference = proportional/20 + integral/10000 + derivative*3/2;
const int max = 190;
if(power_difference > max)
power_difference = max;
if(power_difference < -max)
power_difference = -max;
if(power_difference < 0)
set_motors(max+power_difference, max);
else
set_motors(max, max-power_difference);
lcd_goto_xy(0,1);
print_long(x);
if((PIND & (1 << PD0))&&(PINC & (1 << PC5))){
left_led(0);
right_led(0);
a=0;
w=0;
m=0;}
if(!(PINC & (1 << PC5))){
w=w+1;}
if(!(PIND & (1 << PD0))){
a=a+1;}
if ((a>40) && (w<1)){
left_led(1);
right_led(1);
if (m!=1){
x=x+1;
m=1;}
}
if (x == 3)
{
y=y+1;
if (y > 300){
set_motors(50,-50);
lcd_goto_xy(0,0);
print("FIM");
play_from_program_space(go);
while(is_playing());
}
}
}
}
Since already I thank you.
Agenor Flávio.