Hi Leute,
ich hab mich mal wieder an meinen NIBO2 gewagt um etwas zu programmieren.
Das Programm, soll den Nibo solange geradeaus fahren lassen, bis der Wert des copro_distance[2] größer als 3 wird.
Aber, der Motor schaltet irgendwie nicht ab. (letztendlich geht es nur um den unteren teil des Programms).
Code:
#include <nibo/niboconfig.h>
#include <nibo/display.h>
#include <nibo/gfx.h>
#include <nibo/copro.h>
#include <nibo/delay.h>
#include <nibo/iodefs.h>
#include <nibo/bot.h>
#include <avr/interrupt.h>
#include <nibo/spi.h>
#include <stdio.h>
#include <nibo/leds.h>
#include <stdint.h>
#include <nibo/pwm.h>
int main() {
sei();
bot_init();
spi_init();
display_init();
leds_init ();
pwm_init ();
//-------------------------------------------------------
copro_ir_startMeasure();
//-------------------------------------------------------
leds_set_headlights (1024); //Frontlicht setzen
leds_set_status(LEDS_GREEN, 2);
leds_set_status(LEDS_GREEN, 3);
//-------------------------------------------------------
void blinker_links () { // Blinker Links definieren
int a = 1;
while (a<=10){
leds_set_status (LEDS_ORANGE, 0);
leds_set_status (LEDS_ORANGE, 1);
delay (100);
leds_set_status (LEDS_OFF, 0);
leds_set_status (LEDS_OFF, 1);
delay (100);
a++;
}
}
//-------------------------------------------------------
void blinker_rechts () {
int b = 1;
while(b<=10) // Blinker Rechts definieren
{
leds_set_status (LEDS_ORANGE, 4);
leds_set_status (LEDS_ORANGE, 5);
delay (100);
leds_set_status (LEDS_OFF, 4);
leds_set_status (LEDS_OFF, 5);
delay (100);
b++;
}
}
//-------------------------------------------------------
void warnblinker () {
int c = 1;
while(c<=10) // Warnblinker definieren
{
leds_set_status (LEDS_ORANGE, 0);
leds_set_status (LEDS_ORANGE, 1);
leds_set_status (LEDS_ORANGE, 4);
leds_set_status (LEDS_ORANGE, 5);
delay (100);
leds_set_status (LEDS_OFF, 0);
leds_set_status (LEDS_OFF, 1);
leds_set_status (LEDS_OFF, 4);
leds_set_status (LEDS_OFF, 5);
delay (100);
c++;
}
}
//-------------------------------------------------------
copro_ir_startMeasure();
copro_setSpeedParameters(5, 6, 7);
void motor_geradeaus (){
while(1==1){
copro_setSpeed(20, 20);
}
}
//-------------------------------------------------------
while(1==1){
delay(10);
char text[20]="-- -- -- -- --";
// Co-Prozessor
if (copro_update()) {
sprintf(text, "x x x x x",
(uint16_t)copro_distance[0]/256,
(uint16_t)copro_distance[1]/256,
(uint16_t)copro_distance[2]/256,
(uint16_t)copro_distance[3]/256,
(uint16_t)copro_distance[4]/256);
while(copro_distance[2]<3){
motor_geradeaus ();
}
}
}
return 0;
}
mfg freekwave
Lesezeichen