PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Behaviour mit SRF08



PocketPc
25.04.2010, 12:00
Hallo und nen Guten.

Kleines Problem bittet um anregung zur Lösung.

Ich hab das Program Example_05_Move_05 um ein weiteres Verhalten erweitert. Zwischen Cruise und Avoid sollen nun die Daten (distance) eines SRF08 verarbeitet werden.

RP6 soll mit Speed 160 fahren und vor einem Hindernis das 1 m entfernt ist soll der Speed auf 100 gesetzt werden, um sich dann mit Avoid und Escape ran zutasten.

Die Distance greife ich vom ExampleI²C_Master_03 ab.

Das Problem ist nun das ich keine saubere distance rein bekomme.
Ich hab einen Stopwatch implementiert aber der scheint mir nix zu bringen.

Momentaner Stand:
RP6 fährt mit Speed 160 los und auf dem Weg zum Hindernis regelt er ab und an auf 100 und gibt dann wieder Gas. Ab einen Meter vorm Hindernis fährt er konstant 100 und Avoid und Escape springen dann mit ein.

Also der Weg ist mein Ziel :-k

Hier ist mein code Segment


/************************************************** ***************************/
// Slow Behaviour:

#define SLOW_SPEED_FWD 40

#define SLOW 3
#define RANGE_MAX 100
behaviour_command_t slow = {0, 0, FWD, false, false, 0, IDLE};

void behaviour_slow(void)
{
switch(slow.state)
{
case IDLE:
if(distance>=0)
{
setStopwatch8(0);
startStopwatch8();
slow.state = SLOW;
}
break;
case SLOW:

if((getStopwatch8()>100) && (distance > RANGE_MAX))
{
slow.speed_left = CRUISE_SPEED_FWD;
slow.speed_right = CRUISE_SPEED_FWD;
}

else
{
slow.speed_left = SLOW_SPEED_FWD;
slow.speed_right = SLOW_SPEED_FWD;
}
break;
}
}

Magelan1979
25.04.2010, 14:03
Lass Dir mal während der Fahrt die distance-Werte ausgeben und plotte diese mit. Auf dem ersten Blick kann ich mir nur vorstellen, dass es daran liegt.

Gruß Magelan

roboter14
25.04.2010, 14:34
Hast du mit em Ultraschallsensor son andre "Testfahrten" gemacht.

PocketPc
25.04.2010, 15:31
@Magelan1979: Die Werte Bekomme ich raus.
So sauber schaut es leider nicht aus.



Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 0 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance IF : 310 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 86 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |
Distance ELSE : 85 cm |


@roboter14: Andere Test Fahrten hab ich noch nicht gemacht.
Hab noch nix anderes Progamiert wo der SRF zum einsatz kommt.

Magelan1979
25.04.2010, 15:45
Die gute Nachricht ist, dass der Quellcode nicht falsch ist. Stellt sich jetzt die Frage, warum der auf einmal den Sprung macht. Könnte zum Beispiel etwas mit dem Umgebungslicht zu tun haben. Kannst es ja mal nach möglichkeit in einem "dunklen" Raum machen und nochmals messen.

PocketPc
25.04.2010, 17:10
Ultraschall und Dunkles Licht? Ist doch Licht unabhänig.

Ich hab die Messung und die Behaviour in 2 verschiedene Header dateien.

Ich denke das da dadurch etwas bei der Übergabe schief geht.



Main Code hier

#include "RP6RobotBaseLib.h"
#include "SRF.h"
#include "Verhalten.h"

int main (void)
{ uint8_t button = 0;

initRobotBase();

setLEDs(0b111111);
mSleep(2500);
setLEDs(0b100100);

I2CTWI_initMaster(100);
I2CTWI_setRequestedDataReadyHandler(I2C_requestedD ataReady);

BUMPERS_setStateChangedHandler(bumpersStateChanged );

ACS_setStateChangedHandler(acsStateChanged);
powerON();

startStopwatch1();
setACSPwrMed();

while(true)
{
task_RP6System();
task_SRF();
task_I2CTWI();
behaviourController();
}

return 0;
}

SRF Code

#ifndef SRF_H
#define SRF_H

#include "RP6RobotBaseLib.h"

#include "RP6I2CmasterTWI.h" // Include the I²C-Bus Slave Library

/************************************************** ***************************/
// SRF08/SRF10:

#define SRF_ADR 0xE2



/************************************************** ***************************/
// I2C Event handlers:


// I2C Data request IDs:
#define MEASURE_US_LOW 0
#define MEASURE_US_HIGH 1

// The measured distance:
uint16_t distance;

void I2C_requestedDataReady(uint8_t dataRequestID)
{
uint8_t messageBuf[8];
static uint8_t dist_tmp;
switch(dataRequestID)
{
case MEASURE_US_HIGH: // High data register
// get received data ...
I2CTWI_getReceivedData(messageBuf, 2);
dist_tmp = (messageBuf[0]);
// ... and request low data byte:
I2CTWI_transmitByte(SRF_ADR, 3);
I2CTWI_requestDataFromDevice(SRF_ADR, MEASURE_US_LOW, 1);
break;
case MEASURE_US_LOW: // low data byte:
I2CTWI_getReceivedData(messageBuf, 2);
distance = messageBuf[0] + (dist_tmp << 8);
// ----------------------------------
// Output measured distance:
//writeString_P("Distance: ");
//writeInteger(distance, DEC);
//writeString_P(" cm | ");
// show a simple text bargraph:
//uint16_t dist_count;
//for(dist_count = distance; dist_count > 4; dist_count-=2)
// writeChar('#');
//writeChar('\n');
// ... of course you can also use "distance" as a normal
// variable everywhere else in your program!
// ----------------------------------
break;
}
}

/*
* The SRF needs some time to perform the measurements - here we use Stopwatch1
* to time the measurement actions.
*/
void task_SRF(void)
{
static uint8_t measureInProgress = false;
if(!measureInProgress) // Start measurement ONCE only
{
if(TWI_operation == I2CTWI_NO_OPERATION) // If there is no request in progress...
{
I2CTWI_transmit2Bytes(SRF_ADR, 0, 81); // 81 means return distance in cm
measureInProgress = true;
setStopwatch1(0);
}
}
else if(getStopwatch1() > 70) // 70ms (measurement delay)
{
I2CTWI_transmitByte(SRF_ADR, 2); // range register high byte
I2CTWI_requestDataFromDevice(SRF_ADR, MEASURE_US_HIGH, 1); // receive it
measureInProgress = false; // allow to start new measurement
setStopwatch1(0);
}
}

#endif

Magelan1979
25.04.2010, 18:37
Du definierst

#define SRF_ADR 0xE2
gemäß Handbuch ist das der Wert des Ergebnis in Mikrosekunden vielleicht gibt es dadurch irgendeinen Überlauf.

Des weiteren solltest Du mal schauen ob Du auch immer die richtigen Register ausliest.

4. Normale Weitenmessung:
Es gibt 3 Befehle (80 to 82) um eine Messung zu starten und den Messwert in Zoll, cm oder
μs zu bekommen. Nach einer Wartezeit von normalerweise 65ms können die Messwerte
aus den Registern ausgelesen werden. Die Messwert-Register werden mit Beginn einer
jeden Messung zurückgesetzt. Der erste Messwert steht in Register 2,3 der zweite in
Register 4,5, usw. Wenn ein Messwertregister den Wert 0 hat (beide Bytes), dann gibt es
keine nachfolgenden Werte mehr. Die Lichtsensor Daten in Register 1 werden ebenfalls
nach einer Weitenmessung erneuert.

PocketPc
25.04.2010, 19:24
#define SRF_ADR 0xE2

Ist die Addresse meines SRF die stimmt schon und am register liegt es leider auch nicht.

In der ExampleI²C_Master_03 (bei mir die SRF.h) funktioniert die distance auszulesen super. Nur bei der Übergabe an meine verhalten.h bekomme ich manche falsche werte. ](*,)

Magelan1979
25.04.2010, 20:33
Dann schleif doch mal einfach testhalber ein paar Zahlen in die verhalten.h. Vielleicht erkennt man, ab welchen Werten die Sprünge kommen

PocketPc
25.04.2010, 21:19
Ich hab ne Variable hochzählen lassen und die wurde ganz normal übertragen.

Danke für den Tip.

Hm woran kann es denn dann liegen das er ab und zu stockt beim fahren???