G60 G60
+  Foro x-plane.es
|-+  Foro General» X-Plane 11» HELP
Usuario: Recordar
Contraseña:
Tags
Páginas: [1]   Ir Abajo
  Imprimir  
Autor Tema: HELP  (Leído 1401 veces)
0 Usuarios y 1 Visitante están viendo este tema.
27 Julio, 2022, 17:54:17
Uriel_jisa
Usuario reciente
**
Desconectado Desconectado

Mensajes: 3



En línea
HELP

Buen día para todos, espero puedan ayuadarme. Necesito utilizar un encoder rotatorio de 3 pines para modificar algún comando de XPlane 11, sin embargo no puedo hacer que mi código haga que gire en ambos sentidos el comando del altímetro, solo suma al conteo pero en ningun momento baja así le esté girando en sentido antihorario.
#include <arduino.h>
#include <XPLDirect.h>
#include <stdio.h>
XPLDirect Xinterface(&Serial);

const int PinA = 2;
const int PinB = 3;
float Up;
float Down;

const int timeThreshold = 50;
long timeCounter = 0;

const int pasosMax = 255;
volatile int ISRCounter = 0;
int contador = 0;

bool giroCW = true;
bool vueltaCW = true;

void setup()
{
   pinMode(PinA, INPUT);
   pinMode(PinB, INPUT);
   attachInterrupt(digitalPinToInterrupt(PinA), doEncodeA, CHANGE);
  // attachInterrupt(digitalPinToInterrupt(PinB), doEncodeB, CHANGE);
   
   Serial.begin(XPLDIRECT_BAUDRATE); // start serial interface.  Baudrate is specified in the header, dont change   
   Xinterface.begin(\"XPLDirect Command Demo\");
 


//Xinterface.registerCommand(\"sim/instruments/barometer_down\", XPL_READ, 100, 0, &verticalSpeed);
 Xinterface.registerCommand(\"sim/instruments/barometer_copilot_down\", &Down);
//Xinterface.registerCommand(\"sim/instruments/barometer_copilot_up\", &Up);


}
void loop()

{
  Xinterface.xloop();
   if (contador != ISRCounter)
   {
      contador = ISRCounter;
      Serial.println(contador);
   }
   delay(10);
}

void doEncodeA()
{
   if (millis() > timeCounter - timeThreshold)
   {
      if (digitalRead(PinA) == digitalRead(PinB))
      {
         giroCW = true;
         if (ISRCounter + 1 <= pasosMax) ISRCounter++, Up++;
      }
   }
     /* if (digitalRead(PinB) != digitalRead(PinA))
      {
         giroCW = false;
         if (ISRCounter - 1 <= 0) ISRCounter--, horizDown++;
      }*/
      timeCounter = millis();     
    }
 


/*void doEncodeB()
{
   if (millis() > timeCounter + timeThreshold)
   {
      if (digitalRead(PinA) != digitalRead(PinB))
      {
         giroCW = true;
         if (ISRCounter + 1 <= pasosMax) horizUp++;
      }
      else
      {
        giroCW = false;
         if (ISRCounter - 1 > 0) horizDown--;
      }
      timeCounter = millis();
   }
}




//sim/instruments/barometer_down
//sim/instruments/barometer_up

sim/instruments/barometer_copilot_up
sim/instruments/barometer_copilot_down*/

27 Julio, 2022, 19:38:02 #1
grrr05
Superusuario
*******
Desconectado Desconectado

Mensajes: 4344


If it ain't broke don't fix it


WWW
En línea
Re: HELP

Aunque el C y todos sus derivados me suenan a chino, veo un par de cosas;

- ¿De donde sacas las variables horizUp y horizDown? Sólo tienes declaradas Up y Down.
- en doEncodeA, para el giro antihorario (el cual tienes comentado) la condicional debería ser (ISRCounter - 1 > 0) en vez de menor o igual que 0 - entiendo que ISRCounter sólo puede ir de 0 a 255.

Veo mas correcto doEncodeB (comentado completamente) que doEncodeA, salvo por las variables horiz*, pero tampoco me hagas mucho caso...

Citar
[...]

float Up;
float Down;

[...]

void doEncodeA()
{
   if (millis() > timeCounter - timeThreshold)
   {
      if (digitalRead(PinA) == digitalRead(PinB))
      {
         giroCW = true;
         if (ISRCounter + 1 <= pasosMax) ISRCounter++, Up++;
      }
   }
     /* if (digitalRead(PinB) != digitalRead(PinA))
      {
         giroCW = false;
         if (ISRCounter - 1 <= 0) ISRCounter--, horizDown++;
      }*/
      timeCounter = millis();    
    }
 


/*void doEncodeB()
{
   if (millis() > timeCounter + timeThreshold)
   {
     if (digitalRead(PinA) != digitalRead(PinB))
      {
         giroCW = true;
         if (ISRCounter + 1 <= pasosMax) horizUp++;
      }
      else
      {
        giroCW = false;
         if (ISRCounter - 1 > 0) horizDown--;
      }
      timeCounter = millis();
   }
}


Por cierto estaría bien que cambiases el título de tu hilo para que describa mejor tu problema, un hilo que se llama simplemente "help" o "ayuda" sin más no suele despertar mucho interes y puede acabar perdido fácilmente.
« Última modificación: 28 Julio, 2022, 00:08:05 por grrr05 »




Albert Ràfols
www.spainuhd.es
Tags:
Páginas: [1]   Ir Arriba
  Imprimir  
 
Ir a:  

www.x-plane.es.
Página creada en 0.055 segundos con 19 queries.