Jump to content

Johan4668

Members
  • Posts

    89
  • Joined

  • Last visited

Everything posted by Johan4668

  1. Where is that? The mapping what line? And this stepper is not moving 315 degrees I just don't understand that.. I thought that when you expand or make the rotation smaller you need to reduce the steps... The speedo is around 400 degrees then the steps to the end is more? 480 for around 140 degrees 630 for 315 degrees 1000 for 400 degrees... like the speedindicator I know the steps are not exactly correct but for me to understand..
  2. When I leave it on 630 the disk goes to the end and keeps pushing to the end for more them a second.. that's a horrible sound and the km is going faster then dcs on disk on 4 k and dcs 2.2 I'll make a movie of it... now it is on point.. the 0 on the stwpper is not the 0 written on the disk... I need to remake the disk that 0 stepper is also the 0 on the disk.. The needle is only doing that when you go up.. and after the ir detection.. when it sees the gap on 0 the needle when going up goes back 0.05 and that is there right place.. and passes the detection no problem.. and on the 0.05 it hops back to 1.. so strange.. the gap I already made that so small that its detection I 2 degrees a mm before and a mm after 0.. so the 0n 0.01 the ir is off.. and stays off till the zero.. When I come home I shall test it when after detection I take the detection wire out of the aeduino and see what it does.. the only thing I can think of is a reflection... but that is slimm.. Thanks again Vince you are a great help.. can't say it enough..
  3. #define DCSBIOS_IRQ_SERIAL #include <AccelStepper.h> #include "DcsBios.h" // sea level knob DcsBios::RotaryEncoder altPressSet("ALT_PRESS_SET", "-3200", "+3200", A1, A2); struct StepperConfig { unsigned int maxSteps; unsigned int acceleration; unsigned int maxSpeed; }; class Vid60Stepper : public DcsBios::Int16Buffer { private: AccelStepper& stepper; StepperConfig& stepperConfig; inline bool zeroDetected() { return digitalRead(irDetectorPin) == 1; } unsigned int (*map_function)(unsigned int); unsigned char initState; long currentStepperPosition; long lastAccelStepperPosition; unsigned char irDetectorPin; long zeroOffset; bool movingForward; bool lastZeroDetectState; long normalizeStepperPosition(long pos) { if (pos < 0) return pos + stepperConfig.maxSteps; if (pos >= stepperConfig.maxSteps) return pos - stepperConfig.maxSteps; return pos; } void updateCurrentStepperPosition() { // adjust currentStepperPosition to include the distance our stepper motor // was moved since we last updated it long movementSinceLastUpdate = stepper.currentPosition() - lastAccelStepperPosition; currentStepperPosition = normalizeStepperPosition(currentStepperPosition + movementSinceLastUpdate); lastAccelStepperPosition = stepper.currentPosition(); } public: Vid60Stepper(unsigned int address, AccelStepper& stepper, StepperConfig& stepperConfig, unsigned char irDetectorPin, long zeroOffset, unsigned int (*map_function)(unsigned int)) : Int16Buffer(address), stepper(stepper), stepperConfig(stepperConfig), irDetectorPin(irDetectorPin), zeroOffset(zeroOffset), map_function(map_function), initState(0), currentStepperPosition(0), lastAccelStepperPosition(0) { } virtual void loop() { if (initState == 0) { // not initialized yet pinMode(irDetectorPin, INPUT); stepper.setMaxSpeed(stepperConfig.maxSpeed); stepper.setSpeed(200); initState = 1; } if (initState == 1) { // move off zero if already there so we always get movement on reset // (to verify that the stepper is working) if (zeroDetected()) { stepper.runSpeed(); } else { initState = 2; } } if (initState == 2) { // zeroing if (!zeroDetected()) { stepper.runSpeed(); } else { stepper.setAcceleration(stepperConfig.acceleration); stepper.runToNewPosition(stepper.currentPosition() + zeroOffset); // tell the AccelStepper library that we are at position zero stepper.setCurrentPosition(0); lastAccelStepperPosition = 0; // set stepper acceleration in steps per second per second // (default is zero) stepper.setAcceleration(stepperConfig.acceleration); lastZeroDetectState = true; initState = 3; } } if (initState == 3) { // running normally // recalibrate when passing through zero position bool currentZeroDetectState = zeroDetected(); if (!lastZeroDetectState && currentZeroDetectState && movingForward) { // we have moved from left to right into the 'zero detect window' // and are now at position 0 lastAccelStepperPosition = stepper.currentPosition(); currentStepperPosition = normalizeStepperPosition(zeroOffset); } else if (lastZeroDetectState && !currentZeroDetectState && !movingForward) { // we have moved from right to left out of the 'zero detect window' // and are now at position (maxSteps-1) lastAccelStepperPosition = stepper.currentPosition(); currentStepperPosition = normalizeStepperPosition(stepperConfig.maxSteps + zeroOffset); } lastZeroDetectState = currentZeroDetectState; if (hasUpdatedData()) { // convert data from DCS to a target position expressed as a number of steps long targetPosition = (long)map_function(getData()); updateCurrentStepperPosition(); long delta = targetPosition - currentStepperPosition; // if we would move more than 180 degree counterclockwise, move clockwise instead if (delta < -((long)(stepperConfig.maxSteps/2))) delta += stepperConfig.maxSteps; // if we would move more than 180 degree clockwise, move counterclockwise instead if (delta > (stepperConfig.maxSteps/2)) delta -= (long)stepperConfig.maxSteps; movingForward = (delta >= 0); // tell AccelStepper to move relative to the current position stepper.move(delta); } stepper.run(); } } }; /* modify below this line */ /* define stepper parameters multiple Vid60Stepper instances can share the same StepperConfig object */ struct StepperConfig stepperConfig = { 720, // maxSteps 8000, // acceleration 4000 // maxSpeed }; // define AccelStepper instance AccelStepper stepper1(AccelStepper::FULL4WIRE , 8, 7, 9, 10); // define Vid60Stepper class that uses the AccelStepper instance defined in the line above // v-- arbitrary name Vid60Stepper alt100ftPointer(0x424a, // DCS Bios address For stepper data stepper1, // name of AccelStepper instance stepperConfig, // StepperConfig struct instance 12, // IR Detector Pin (must be HIGH in zero position) 0, // zero offset [](unsigned int newValue) -> unsigned int { /* this function needs to map newValue to the correct number of steps */ return map(newValue, 0, 65535, 0, stepperConfig.maxSteps-1); }); //Stepper 2 AccelStepper stepper0(AccelStepper::FULL4WIRE , 4, 3, 5, 6); // Altimeter kilometer disk (0-13.000 m) void onAltimeterCoarseptrChange(unsigned int newValue) { stepper0.runToNewPosition(map(newValue, 0, 65535, 0, 460)); } DcsBios::IntegerBuffer altimeterCoarseptrBuffer(0x424c, 0xffff, 0, onAltimeterCoarseptrChange); void zero_stepper0(){ stepper0.setMaxSpeed(4000); // maximum speed in steps per second. Must be > 0. stepper0.setAcceleration(8000); // desired acceleration in steps per second per second. Must be > 0.0 stepper0.runToNewPosition(460); // go to the upper end stop delay(250); stepper0.setCurrentPosition(460); // set max steps stepper0.runToNewPosition(12); // go to the lower end stop delay(250); stepper0.setCurrentPosition(0); // set steps to zero } void setup() { DcsBios::setup(); zero_stepper0(); } void loop() { PORTB |= (1<<5); PORTB &= ~(1<<5); DcsBios::loop(); } this is my code now
  4. It looks good.. no hops just a small glitch.. when you pass in flight or turning the knob and you passen up 0.05 the leedle hops.. and keeps a 0.05 offset and down it resets on 0.. see vid.. Thanks this is so helpfull and I learn a lot.. 20230329_130841.mp4
  5. the disk has new end points... as you can see on the picture.. Off set is about 15 I think disk
  6. Thanks for taking the time to explain.. it makes more sens now.. i was changing thins on trial and error.. and was getting to celebrating on the wrong site.. the angle of the disk is 145 degrees.. so it is on fullwire 290 stepper0.runToNewPosition(map(newValue, 0, 65535, 0, 290)); // for the km disk in FULL4WIRE mode void zero_stepper0(){ stepper0.setMaxSpeed(4000); // maximum speed in steps per second. Must be > 0. stepper0.setAcceleration(8000); // desired acceleration in steps per second per second. Must be > 0.0 stepper0.runToNewPosition(290); // go to the upper end stop delay(250); stepper0.setCurrentPosition(290); // set max steps stepper0.runToNewPosition(0); // go to the lower end stop delay(250); stepper0.setCurrentPosition(0); // set steps to zero } But the lower stop is not on the 0 mark (offset).. do i need to change this? to get it on 0? stepper0.setCurrentPosition(0); // set steps to zero
  7. Here the ide file as it is now Alititude_Gauge.ino
  8. https://youtu.be/WD5B8DAC2xY See youtube
  9. No, every time it passes 0 it goes everywhere. even with the RotaryEncoder up is ok.. then to 0 it goes everywhere
  10. Callibrated, and works but see video.. it goes wacky on the 0 detection... 20230327_194852.mp4
  11. Yes, I changed it to FULLWIRE and it went a little better.. then i changed the pins.. when i use pin 13 it goes rough and 9-10-11-12 it goes around smooth.. so that is 1 thing solved using only the script of the needle. )not tsted yet on DCS. now iam going to do only the disk, and combine it when it works perfect.. and the rs458 i used the RS485Master.ino on the Mega but that is for later... keep you updated Johan
  12. i see that the disk is not on zero and the disk is faster then the KM alt in dcs.. what are the parameters to change that on what row...
  13. Here what it does now.. https://youtu.be/dwX_dm5ip8g
  14. and the rs485 This in the Master.. and pin 2 ---------------------------------------------------------------------------- /* The following #define tells DCS-BIOS that this is a RS-485 slave device. It also sets the address of this slave device. The slave address should be between 1 and 126 and must be unique among all devices on the same bus. */ #define DCSBIOS_RS485_SLAVE 1 /* The Arduino pin that is connected to the /RE and DE pins on the RS-485 transceiver. */ #define TXENABLE_PIN 2 #include "DcsBios.h" /* paste code snippets from the reference documentation here */ void setup() { DcsBios::setup(); } void loop() { DcsBios::loop(); } -------------------------------------------------------------------------------- this in the slave also on pin2.. ------------------------------------------------------------------------ #define RS485 // default is USB mode, uncomment for using at the RS485 bus #ifndef RS485 #define DCSBIOS_IRQ_SERIAL // use for Arduino UNO, NANO and MEGA // #define DCSBIOS_DEFAULT_SERIAL // use for other boards like ESP32 or Raspberry Pi Pico #endif #ifdef RS485 #define DCSBIOS_RS485_SLAVE 1 // change according your slave number (1 to 128) #define TXENABLE_PIN 2 #endif #include <AccelStepper.h> #include "DcsBios.h" // sea level knob DcsBios::RotaryEncoder altPressSet("ALT_PRESS_SET", "-3200", "+3200", A1, A2); ------------------------------------------------------------------------- do i miss something that it is not working?
  15. Something is not right in the code.. the stepper of the needle is going with noise and not smooth and the disk is going fast and smooth no noise.. when i exchange the stepper connection numbers in the Sketch it si the other way around.. so it looks that the needle code is something not right
  16. Vinc can you help me understand the above?
  17. this is for the nano.. #ifdef RS485 #define DCSBIOS_RS485_SLAVE 1 // change according your slave number (1 to 128) #define TXENABLE_PIN 2 #endif ------------------------------------ What can i use for the Mega?
  18. because the stepper is turning.. but not smooth
  19. this is sometime confusing.. just to be sure... this code says stepper1(AccelStepper::HALF4WIRE , 10, 11, 13, 12) that means the stepper must connected like this to the nano?
  20. Hi, trying to learn and to get to understand the script... so i came up with some questions. Can you help me through the script above. line 33 -------------------------------------------------------------------- void updateCurrentStepperPosition() { // adjust currentStepperPosition to include the distance our stepper motor // was moved since we last updated it long movementSinceLastUpdate = stepper.currentPosition() - lastAccelStepperPosition; currentStepperPosition = normalizeStepperPosition(currentStepperPosition + movementSinceLastUpdate); lastAccelStepperPosition = stepper.currentPosition(); } --------------------------------------------------------------------- What can i do here? is this to set the offset of like,. void updateCurrentStepperPosition(100) and where does i see what stepper it is.. or.. Line 78 -------------------------------------------------------------------- stepper.setAcceleration(stepperConfig.acceleration); stepper.runToNewPosition(stepper.currentPosition() + zeroOffset); // tell the AccelStepper library that we are at position zero stepper.setCurrentPosition(0); lastAccelStepperPosition = 0; // set stepper acceleration in steps per second per second // (default is zero) stepper.setAcceleration(stepperConfig.acceleration); lastZeroDetectState = true; initState = 3; ----------------------------------------------------------------------------- can we do something here... 133 ------------------------------------------------------------------------------- /* modify below this line */ /* define stepper parameters multiple Vid60Stepper instances can share the same StepperConfig object */ struct StepperConfig stepperConfig = { 1440, // maxSteps 4000, // maxSpeed 8000 // acceleration }; // define AccelStepper instance AccelStepper stepper1(AccelStepper::HALF4WIRE , 10, 11, 13, 12); // define Vid60Stepper class that uses the AccelStepper instance defined in the line above // v-- arbitrary name Vid60Stepper AltimeterFineptr(0x424a, // address of stepper data DCS stepper1, // name of AccelStepper instance stepperConfig, // StepperConfig struct instance 9, // IR Detector Pin (must be HIGH in zero position) 0, // zero offset [](unsigned int newValue) -> unsigned int { /* this function needs to map newValue to the correct number of steps */ return map(newValue, 0, 65535, 0, stepperConfig.maxSteps-1); }); ------------------------------------------------------------------------------------------------- This is for stepper 1 0-1000.. Max steps.. is there a calculation for that? Max speed.. speed what range? 4000 is ok in this case.. Acceleration.. dont know how to see that.. 185------------------------------------------------------------------------------- stepper0.runToNewPosition(1260); // go to the upper end stop delay(250); stepper0.setCurrentPosition(1260); // set max steps stepper0.runToNewPosition(0); // go to the lower end stop delay(250); ------------------------------------------------------------------------------------- What can we do here? sorry for all those questions.. i really interested. Johan
  21. It's the code you send me..
  22. the lower is ok.. the startup.. the upper is in DCS flight.. the 0 - 1000 meter needle is not moving and the km disk is moving fast.. on climbing 500 meters
  23. 20230322_114216.mp4 20230322_114057.mp4 It stops that is good.. I see the meter needle not moving and the km is and fast.. And on encoder the km disk moves.. Do we mis something here?
  24. Can i ask where to buy this? i made the KG13c and like it in there..
×
×
  • Create New...