Das wäre klasse. Merkwürdig, ich hatte das Gefühl, das Turn(...) nicht funktioniert. OK, werde ich nochmals genauer testen.
Druckbare Version
Das wäre klasse. Merkwürdig, ich hatte das Gefühl, das Turn(...) nicht funktioniert. OK, werde ich nochmals genauer testen.
hi ehenkes,
habe nun den folgenden code versucht:
wenn ich die auskomentiertn zeilen aktiviere wird auch in etwa die gemessene entfernung geschrieben (der asuro ist dabei hochgebockt). Wenn ich ihn mit dem originalprogramm einschalte (und in der hand halte) reagiert er auch entsprechend auf verkleinerung der entfernung mit wenden und weiterfahren. Wenn ich ihn aber normal fahren lasse dreht er sich eigentlich nur im kreis (stück drehend zurück, stück vor usw.) liegt es nun am programm - was ich nicht glaube - oder an den fahrgeräuschen, die die US-messung stören?Code:#include "asuro.h"
#include "inka.h"
int dist;
int abstand=0;
int i;
int main(void)
{
Init();
WaitforStart();
while(1)
{
{
/*SerWrite("\r\n --- georgs ultrasonic test ---",32);
Msleep(1000);*/
do
{
BackLED(ON,OFF);
abstand=Chirp();
/*SerWrite("\r\n distanz in cm: ",16);
SerWrite("\r\n",5);
Msleep(500);
StatusLED(RED);
PrintInt(abstand);*/
BackLED(OFF,ON);
if(abstand > 20) {
StatusLED(GREEN);
MotorDir(FWD, FWD);
MotorSpeed(200, 200);
}
else {
StatusLED(RED);
MotorDir(FWD, RWD);
MotorSpeed(0, 200);
for(i = 0; i<150; i++) { Sleep(200); }
}
}
while(1);
}
}
return 0;
}
Ich mache das so, dass ich die Bremsleuchten bediene, wenn der Abstand zu niederig ist. Dann kann man verfolgen, woher das Taumeln kommt. Geradeaus fahren gehört ja wirklich nichtn zu den Stärken des ASURO. Man kann aber Odometrie und US-Echolot mischen, z.B. so:
Du kannst das ja mal bei Dir testen. Die Werte in myasuro.h für die Odometrie anpassen.Code:#include "asuro.h"
#define L_DIR ((PORTD & RWD) ? -1 : 1)
#define R_DIR ((PORTB & RWD) ? -1 : 1)
typedef int (*FunctionPointer) (int);
FunctionPointer actionList[];
int slow=60;
int fast=80;
unsigned char currentTask;
int leftSpeed=0;
int rightSpeed=0;
long motorTime=0;
int delta=100, Kp=20; // entspricht Kp=0.2
int wait(int msTime)
{
long t1=Gettime()+msTime;
unsigned char newTask, savedTask=currentTask;
int sensor, action=0;
do
{
for(newTask=0; newTask<savedTask; )
{
sensor=(*actionList[2*newTask])(newTask);
if(sensor)
{
currentTask=newTask;
action|=(*actionList[2*newTask+1])(sensor);
newTask=0;
}
else ++newTask;
}
}
while(t1 > Gettime());
currentTask=savedTask;
return action;
}
void drive(int leftSpeed_, int rightSpeed_)
{
leftSpeed = leftSpeed_;
rightSpeed = rightSpeed_;
}
int regel(int pwm, int e)
{
int y= (Kp * e)/100;
pwm+=y;
return (pwm>127)? 127 : ((pwm<-127) ? -127 : pwm);
}
int blink_SecTimer(int idx)
{
static int t1=0;
int t0=t1;
t1 = (Gettime()/1000) & 0x1;
return t0^t1; // bei Sekundenwechsel ==> 1 sonst 0
}
int blink_Action(int sensor)
{
static int led=GREEN;
if(led==GREEN)
led=RED;
else
led=GREEN;
StatusLED(led);
return 0x0;
}
int motor_Awake(int idx)
{
return Gettime()>motorTime;
}
int motor_Control(int sensor)
{
static int lpwm=0;
static int rpwm=0;
int l_ticks, r_ticks;
int Ta=Gettime()-motorTime+delta;
l_ticks=encoder[LEFT];
r_ticks=encoder[RIGHT];
EncoderSet(0,0); //Encoder Reset ();
motorTime=Gettime()+delta;
lpwm=regel(lpwm, leftSpeed -1240*L_DIR*l_ticks/Ta);
rpwm=regel(rpwm, rightSpeed-1240*R_DIR*r_ticks/Ta);
SetMotorPower(lpwm, rpwm);
return 0x1;
}
int avoid_Obstacle(int idx)
{
int abstand = Chirp();
if (abstand<10)
{
BackLED(ON,ON);
return abstand;
}
else
{
BackLED(OFF,OFF);
return 0;
}
}
int avoid_Action(int sensor)
{
static int flag;
drive(-slow, -slow); // 0,5 sec zurueck
wait(500);
if(flag)
{
drive(-slow, 0);
flag=0;
}
else
{
drive(0, -slow);
flag=1;
}
wait(200); // 0,2 sec Rückwaertskurve (abwechselnd links und rechts)
return 0x2;
}
int cruise_Forever(int idx)
{
return 1;
}
int cruise_Action(int sensor)
{
drive(fast, fast); // fahr rum
return 0x3;
}
FunctionPointer actionList[] =
{
// sense , // action
blink_SecTimer, blink_Action ,
motor_Awake , motor_Control,
avoid_Obstacle, avoid_Action ,
cruise_Forever, cruise_Action,
};
int main(void)
{
Init();
EncoderInit();
EncoderStart();
drive(0,0);
Msleep(1000);
currentTask=sizeof(actionList)/sizeof(FunctionPointer)/2;
return wait(0);
}
hmmm,
die myasuro.h habe ich mit den gemessenen werten versehen, neu übersetzt, dann ein neues projekt in avr-studio angelegt, projekteinstellungen ok, compiliert (nur eine warnung wegen init chirp)und geflasht...
der asuro steht mit angezogener handbremse (beide back-led´s an), die status led blinkt hektisch gelb, aber sonst passiert nix???
kannst du mir bitte unter die arme greifen? Denn deinen code vestehe ich nicht. Vielleicht so - hmm - mal in 2 jahren?
Das ist schlecht, denn diese soll im 1-Sekunden-Takt rot und grün blinken. OK, dann müssen wir Segel um Segel hochziehen, bis Dein ASURO soweit ist. Wir checken zunächst Dein Ultraschallortungssystem:Zitat:
die status led blinkt hektisch gelb
Probiere mal, welche Werte bei Dir ankommen, und justiere Dein System so, dass die angegebenen Werte der Realität entsprechen. Vielleicht musst Du auch noch an dem 1MOhm-Trimmer des RC-Gliedes drehen. Bei mir steht der Widerstand etwa in der Mitte.Code:#include "asuro.h"
int abstand=0;
int main(void)
{
Init();
SerWrite("\r\n --- ultrasonic test ---",29);
Msleep(1000);
do
{
abstand=Chirp();
SerWrite("\r\n distanz in cm: ",20);
Msleep(500);
PrintInt(abstand);
}
while(1);
return 0;
}
Dann vielleicht das hier:
[/code]Code:#include "asuro.h"
#define MAXDIFF 90
int main(void)
{
int abstand, abstand_alt, diff, zaehler=0;
Init();
abstand = Chirp();
while(TRUE)
{
abstand_alt = abstand;
abstand = Chirp(); ++zaehler;
diff = abstand - abstand_alt;
if( (abstand>15) && (abs(diff)<MAXDIFF) )
{
StatusLED(GREEN);
MotorDir(FWD, FWD);
MotorSpeed(150, 150);
}
else if( (abstand>10) && (abstand<=15) && (abs(diff)<MAXDIFF) )
{
StatusLED(YELLOW);
MotorDir(FWD, FWD);
MotorSpeed(150, 100);
Msleep(10);
}
else
{
StatusLED(RED);
MotorDir(RWD, RWD);
MotorSpeed(150, 100);
Msleep(10);
}
if (zaehler > 800)
{
StatusLED(RED);
BackLED(ON,ON);
MotorDir(RWD, RWD);
MotorSpeed(200, 250);
Msleep(10);
BackLED(OFF,OFF);
}
if (zaehler > 810)
{
StatusLED(RED);
BackLED(ON,ON);
MotorDir(RWD, RWD);
MotorSpeed(250, 200);
Msleep(10);
BackLED(OFF,OFF);
if(zaehler > 820)
zaehler = 0;
}
}
return 0;
}
Subsumption und Behavior:
http://en.wikipedia.org/wiki/Behavior-based_robotics
http://en.wikipedia.org/wiki/Subsumption_architecture
danke ehenkes,
ich muss mich erstmal um die roots kümmern, go, turn und wie sie alle heissen mögen, sonst wird es nix...
Nur Geduld, das wird schon. :)
... Batterie leer? oder blinkt die anders?Zitat:
der asuro steht mit angezogener handbremse (beide back-led´s an), die status led blinkt hektisch gelb, aber sonst passiert nix???
die batterie war voll, ich habe halt das problem, dass ich manche software (noch) nicht verstehe und dann nicht weiss woran sowas liegt. Siehe auch weiterer verlauf des threads - back to the roots...:-)