fbpx

Expresate

Si además quieres enviarnos un Artículo para el Blog y redes sociales, pulsa el siguiente botón:

Moviendo servos
 
Avisos
Vaciar todo

Moviendo servos

3 Respuestas
3 Usuarios
0 Reactions
1,578 Visitas
freire
Respuestas: 12
Topic starter
(@freire)
Active Member
Registrado: hace 19 años

Hola a todos, estoy intentando hacer una secuencia de movimientos con los servos, pero nose como hacerla, hasta ahora lo k hago es prefigarle el valor de los pulsos, pero nose como hacer una secuencia de movimientos, alguien me puede ayudar?? gracias

#define PIN_SERVO1 PIN_B7
#define PIN_SERVO2 PIN_B6
#define PIN_SERVO3 PIN_B5
#define ANT_DER PIN_B3
#define ANT_IZQ PIN_B2
#define LED_DER PIN_B1
#define LED_IZQ PIN_B0

const int PULSO_MINIMO = (48+16);
const int PULSO_MEDIO = (48+48);
const int PULSO_MAXIMO = (48+80);

int contRTCC = 0;
int1 flagRTCC1 = 0;
int1 flagRTCC2 = 0;
int1 flagRTCC3 = 0;
int1 flagSERVO1 = 0;
int1 flagSERVO2 = 0;
int1 flagSERVO3 = 0;
int valTIMER01=0;
int valTIMER02=0;
int valTIMER03=0;

int tSERVO1;//Posicion del servo 1
int tSERVO2;//Posicion del servo 2
int tSERVO3;//Posicion del servo 3

void CONTROL_SERVO1(int tSERVO1){

// DISPARO DEL PULSO PWM 1

if(flagRTCC1==1){
output_high(PIN_SERVO1);
flagSERVO1=1;
flagRTCC1=0;
}

// CONTROL DE ANCHO DEL PULSO PWM 1

if(flagSERVO1==1){
valTIMER01 = get_TIMER0();
if(valTIMER01>tSERVO1){
flagSERVO1=0;
output_low(PIN_SERVO1);
}
}
}

void CONTROL_SERVO2(int tSERVO2){

// DISPARO DEL PULSO PWM 2

if(flagRTCC2==1){
output_high(PIN_SERVO2);
flagSERVO2=1;
flagRTCC2=0;
}

// CONTROL DE ANCHO DEL PULSO PWM 2

if(flagSERVO2==1){
valTIMER02 = get_TIMER0();
if(valTIMER02>tSERVO2){
flagSERVO2=0;
output_low(PIN_SERVO2);
}
}
}

void CONTROL_SERVO3(int tSERVO3){

// DISPARO DEL PULSO PWM 3

if(flagRTCC3==1){
output_high(PIN_SERVO3);
flagSERVO3=1;
flagRTCC3=0;
}

// CONTROL DE ANCHO DEL PULSO PWM 3

if(flagSERVO3==1){
valTIMER03 = get_TIMER0();
if(valTIMER03>tSERVO3){
flagSERVO3=0;
output_low(PIN_SERVO3);
}
}
}

//indica que la sgte. funcion se ejecuta cuando
#int_TIMER0 //hay interrupcion de timer0 (rtcc)

void TIMER0_isr() {

++contRTCC;
if(contRTCC==1){
flagRTCC1=1;
}

if(contRTCC==2){
flagRTCC2=1;
}

if(contRTCC==3){
flagRTCC3=1;
contRTCC=0;
}
set_timer0(50);
}

void main()
{

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER0);
set_timer0(50);

do {

CONTROL_SERVO1(PULSO_MINIMO);
CONTROL_SERVO2(PULSO_MEDIO);
CONTROL_SERVO3(PULSO_MAXIMO);

} while (TRUE);

}

Responder
2 respuestas
Lorth
Respuestas: 188
(@lorth)
Estimable Member
Registrado: hace 17 años

Te puedes montar una maquina de estados del tipo:

switch(Estado){
case 1:
-movimeinto_1();
- si (pasa x tiempo) Estado =2;
case 2:
- movimiento_2();
- si (pasa x tiempo) Estado =3;
case 3:
....
}

Responder
luison
Respuestas: 495
(@luison)
Reputable Member
Registrado: hace 17 años

haciéndolo de forma MUY sencilla:
servo(1)=100 '100 es la posición que quieres que tengo el servo, en tu código no me he mirado que medidas usas.
servo(2)=150
servo(3)=150
Call Posicionar_servos 'Coloca todos los servos en la posición dicha, si lo tienes por interrupciones ni lo tienes que poner
Delay(1.0) 'tiempo que quieres esperar mientras los servos se mueven.

'y ahora repite lo anterior. Lo dicho, Fácil fácil.

Responder
Compartir: