PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : SRF08 + Servo + avoid obstacle



arnob
02.03.2018, 06:15
Hello,
I have got a RP6 Base system. I have connected SRF08 in I2C (#define SRF_ADR 0xE2) and Servo to XBUS 2 (Servo out SDA).
I am getting data in RP6 loader terminal and servo is also moving quite nicely.

I am not so much good in programming. I have mounted srf08 with servo.
Now, I want to avoid obstacle with SRF08.

Could anybody provide the code for that?


Regards
Arnob

i_make_it
02.03.2018, 08:04
No code but principles.

So rc-servos don't give a feedback, you give a setpoint to the servo and has to wait a time so it is finish moving (typically rc-servos can turn 60°/s).
Then start ranging and read SRF08 til you don't get 0xFF anymore (ranging is finish).
Than you can read the echo register 1-17 (register 2-35), til a 16 bit register (8-bit high-byte and 8-bit low-byte) is 0, what means no further echos for this reading stored.

That is the principle of one measure cycle.

Description and example code you can find here:
http://coecsl.ece.illinois.edu/ge423/DevantechSRF08UltraSonicRanger.pdf

arnob
16.03.2018, 14:05
I am just a Beginner with RP6.
First thing first.
I have connected SRF08 to I2C.
and Servo to XBUS 2 ( Servo out SDA). I think it supposed to be changed because SRF already there.
Where should I Connect it and what change should do in the following Dirk's code.

#include "RP6RobotBaseLib.h"

#define SERVO_OUT SDA
#define LEFT_TOUCH 554
#define RIGHT_TOUCH 254
#define PULSE_ADJUST 8
#define PULSE_REPETITION 19

void initSERVO(void)
{
DDRC |= SERVO_OUT;
PORTC &= ~SERVO_OUT;
startStopwatch1();
}

void pulseSERVO(uint8_t position)
{
cli();
PORTC |= SERVO_OUT;
delayCycles(LEFT_TOUCH);
while (position--) {
delayCycles(PULSE_ADJUST);
}
PORTC &= ~SERVO_OUT;
sei();
}

void task_SERVO(void)
{static uint8_t pos;
if (getStopwatch1() > PULSE_REPETITION) {
pulseSERVO(pos);
if (getStopwatch2() > 48) {
pos++;
if (pos > RIGHT_TOUCH) {pos = 0;}
setStopwatch2(0);
}
setStopwatch1(0);
}
}

int main(void)
{
initRobotBase();

mSleep(2500);

setLEDs(0b111111);
mSleep(500);
setLEDs(0b000000);

initSERVO();
startStopwatch2();

while(true)
{
task_SERVO();
task_RP6System();
}
return 0;
}

Dirk
16.03.2018, 16:59
Hi arnob,

you may not use SDA for a servo, if you are using the I2C-Bus with SRF08.

You can use other I/O pins on the RP6 Base.

There is a RP6Base Servo Library (https://www.roboternetz.de/community/threads/40052-RP6Base-Library-f%C3%BCr-8-Servos?highlight=RP6+Base+servo).
With this library you can use other pins for your servo.