Jump to content

Recommended Posts

Posted

I’m trying to build a tachometer gauge for the Spitfire. I’m using a X27.168 and a Easydriverboard to connect to the Arduino.

I found this code from The Simpit A10C YouTube and changed the address to match the output of the tachometer.

The output on the physical device is fine between 1000 RPM and 2000RPM, after which the gauge is showing less RPM than in the simulator, and it never reaches 3000 RPM.

In the line return map(newValue, 13107, 65535, 0, stepperConfig.maxSteps); the 0 is changed with 13107 because of the data from the simulator is never 0, but 20 % output as soon as the engine is running. And the gauge is still at it’s 0 point.

I hope someone has an idea to make the tachometer work from 0-100% RPM

 

#define DCSBIOS_IRQ_SERIAL
 
#include <AccelStepper.h>
#include "DcsBios.h"
 
struct StepperConfig {
  unsigned int maxSteps;
  unsigned int acceleration;
  unsigned int maxSpeed;
};
 
class Vid29Stepper : public DcsBios::Int16Buffer {
  private:
    AccelStepper& stepper;
    StepperConfig& stepperConfig;
    unsigned int (*map_function)(unsigned int);
    unsigned char initState;
  public:
    Vid29Stepper(unsigned int address, AccelStepper& stepper, StepperConfig& stepperConfig, unsigned int (*map_function)(unsigned int))
    : Int16Buffer(address), stepper(stepper), stepperConfig(stepperConfig), map_function(map_function), initState(0) {
    }
 
    virtual void loop() {
      if (initState == 0) { // not initialized yet
        stepper.setMaxSpeed(stepperConfig.maxSpeed);
        stepper.setAcceleration(stepperConfig.acceleration);
        stepper.moveTo(-((long)stepperConfig.maxSteps));
        initState = 1;
      }
      if (initState == 1) { // zeroing
        stepper.run();
        if (stepper.currentPosition() <= -((long)stepperConfig.maxSteps)) {
          stepper.setCurrentPosition(0);
          initState = 2;
          stepper.moveTo(stepperConfig.maxSteps/2);
        }
      }
      if (initState == 2) { // running normally
        if (hasUpdatedData()) {
          unsigned int raw = getData();        // Hent RAW-værdi
    Serial.print("RAW: ");               // Print label
    Serial.println(raw);                 // Print selve tallet
         
          unsigned int newPosition = map_function(getData());
          newPosition = constrain(newPosition, 0, stepperConfig.maxSteps);
          stepper.moveTo(newPosition);
        }
        stepper.run();
      }
    }
};
 
/* modify below this line */
 
/* define stepper parameters
   multiple Vid29Stepper instances can share the same StepperConfig object */
struct StepperConfig stepperConfig = {
  3900,  // maxSteps
  1000, // maxSpeed
  1000 // acceleration
  };
 
// note cs im testing with 8 going to step (middle on easy drier) and 7 doing to direction (right on easy driver)
// cs so in the code going on the basis that the first named number is step and the second is direction
// define AccelStepper instance
AccelStepper stepper(AccelStepper::DRIVER, 8, 7);
// define Vid29Stepper class that uses the AccelStepper instance defined in the line above
//           +-- arbitrary name
//           |   +-- Address of stepper data (from control reference)
//           |   |       +-- name of AccelStepper instance
//           v   v       v        v-- StepperConfig struct instance
Vid29Stepper apu(0x544e, stepper, stepperConfig, [](unsigned int newValue) -> unsigned int {
  /* this function needs to map newValue to the correct number of steps */
  return map(newValue, 13107, 65535, 0, stepperConfig.maxSteps);
});
 
void setup() {
  Serial.begin(115200);    // Starter seriel monitor
  DcsBios::setup();
}
 
void loop() {
  DcsBios::loop();
}
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...