Symbol dangerlevel = 70 ' how far away should thing be, before we react?
symbol turn = 300 ' this sets how much should be turned
symbol servo_turn = 700 ' This sets for how long time we should wait for the servo to turn (depending on it´s speed) before we measure distance
main: ' the main loop
readadc 1, b1 ' read how much distance ahead
if b1 < dangerlevel then
gosub nodanger ' if nothing ahead, drive forward
else
gosub whichway ' if obstacle ahead then decide which way is better
end if
goto main ' this ends the loop, the rest are only sub-routines
nodanger:' this should be your combination to make the robot drive forward, these you most likely need to adjust to fit the way you have wired your robots motors
high 5 : high 6 : low 4 : low 7
return
whichway:
gosub totalhalt ' first stop!
'Look one way:
gosub lturn ' look to one side
pause servo_turn ' wait for the servo to be finished turning
readadc 1, b1
gosub totalhalt
'Look the other way:
gosub rturn ' look to another side
pause servo_turn ' wait for the servo to be finished turning
readadc 1, b2
gosub totalhalt
' Decide which is the better way:
if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return
body_lturn:
high 6 : low 5 : low 7 : high 4 ' this should be your combination that turns the robot one way
pause turn : gosub totalhalt
return
body_rturn:
high 5 : low 6 : low 4 : high 7 ' this should be your combination that turns the robot the other way
pause turn : gosub totalhalt
return
rturn:
servo 0, 100 ' look to one side
return
lturn:
servo 0, 200 ' look to the other side
return
totalhalt:
low 4 : low 5 : low 6 : low 7 ' low on all 4 halts the robot!
Servo 0,150 ' face forward
wait 1 ' freeze all for one second
return
Tiago, não queres traduzir isto para C (Arduino) ?? :PFica para amanha ;)
ola a todos
alguem sabe qual e o codigo ou dicas do codigo p este robo? é tipo o "smalluino" mas com o sensor infravermelhos.
http://lab.guilhermemartins.net/?p=288 (http://lab.guilhermemartins.net/?p=288) ou http://lab.guilhermemartins.net/?p=288. (http://lab.guilhermemartins.net/?p=288.)
podem dar uma ajuda? sff
abracos
#define dangerlevel 70
#define turn 300
#define servo_turn 700
#define sensorPin 0
#define servo 10
int b1, b2;
void main (){
b1 = analogRead(sensorPin);
if (b1 < dangerlevel) nodanger();
else whichway();
}
void nodanger(){ //esta funçao parece-me que define a rotaçao dos motores, isto é, poe-nos a andar pa frente, 1 motor ligado aos pinos 5 e 4 e outro aos pinos 6 e 7
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
}
void wichway(){
totalhalt();
lturn();
delay(servo_turn);
b1 = analogRead(sensorPin);
totalhalt();
rturn();
delay(servo_turn);
b2 = analogRead(sensorPin);
totalhalt();
if(b1<b2) body_lturn();
else body_rturn();
}
void body_lturn(){
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(4, HIGH);
digitalWrite(7, LOW);
delay(turn);
totalhalt();
}
void body_rturn(){
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
digitalWrite(4, lOW);
digitalWrite(7, HIGH);
delay(turn);
totalhalt();
}
void rturn(){
analogWrite(servo, 102); // Estes valores podem e devem ser alterados dependendo da posiçao do servo e do tipo
}
void lturn(){
analogWrite(servo, 152); // Estes valores podem e devem ser alterados dependendo da posiçao do servo e do tipo
}
void totalhalt(){
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(4, lOW);
digitalWrite(7, LOW);
analogWrite(servo, 127); // Estes valores podem e devem ser alterados dependendo da posiçao do servo e do tipo
delay(1000);
}
sim eu sei mas como eu tenho 3 servos dois p as rodas e outro p o infravermelho ...
ja tirei uns erros do codigo mas ainda falta este:
error: two or more data types in declaration of 'main
consegues dar umas luzes?
void loop(){
b1 = analogRead(sensorPin);
if (b1 < dangerlevel) nodanger();
else whichway();
}
#include <ServoTimer1.h>
ServoTimer1 servo1;
void setup() {
Serial.begin(9600);
servo1.attach(9);
}
void loop() {
servo1.write(90);
delay(1000);
servo1.write(0);
delay(1000);
servo1.write(90);
delay(1000);
servo1.write(180);
delay(1000);
servo1.write(90);
delay(1000);
}
bem os meus servos modifiquei do tipo tirei o potenciometro depois coloquei fiz um divisor de tensao com duas resistencias de 10K.
eu vi esta modificacao na elector de agosto.
mas já agora, o 127 faz o quê??
eu acertei-os com o angulo de 90º..
int servo = 11;
void setup()
{
pinMode(servo, OUTPUT);
}
void loop()
{
digitalWrite(servo,127);
delay(1000);
}
Utiliza este código e liga o servo no pin 11 para o calibrar ;)
int servo = 11;
void setup()
{
pinMode(servo, OUTPUT);
}
void loop()
{
digitalWrite(servo,127);
delay(1000);
}
void setup() {
pinMode(10, OUTPUT);
}
void loop() {
analogWrite(10, 0);
delay(2000);
analogWrite(10,127);
delay(2000);
analogWrite(10,255);
delay(2000);
analogWrite(10,127);
delay(2000);
}
depois de uma hora a tentar parar o servo parei por completo.Boa sorte.. entretanto se encontrar melhores técnicas eu digo-te.
bem vou fazer uma pausa infelizmente.
??? ???