1. For downloading SimTools plugins you need a Download Package. Get it with virtual coins that you receive for forum activity or Buy Download Package - We have a zero Spam tolerance so read our forum rules first.

    Buy Now a Download Plan!
  2. Do not try to cheat our system and do not post an unnecessary amount of useless posts only to earn credits here. We have a zero spam tolerance policy and this will cause a ban of your user account. Otherwise we wish you a pleasant stay here! Read the forum rules
  3. We have a few rules which you need to read and accept before posting anything here! Following these rules will keep the forum clean and your stay pleasant. Do not follow these rules can lead to permanent exclusion from this website: Read the forum rules.
    Are you a company? Read our company rules

Mover Simulated Wind Arduino Sketch

Discussion in 'FlyPt Mover' started by pmvcda, Mar 21, 2020.

  1. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,306
    Location:
    Portugal
    Balance:
    10,222Coins
    Ratings:
    +1,348 / 13 / -0
    My Motion Simulator:
    6DOF

    So, here's some code to control the fans with the Arduino.
    Needs to be adapted to your controller.
    That's what @SilentChill is using.

    The code expects 8 bit values, so use the following simple direct module:
    upload_2020-3-21_21-37-26.png
    We are mapping 0 m/s to bit value 0
    70 m/s (+-250 km/h) to bit value 255 (the maximum speed)
    Any speed above 70 m/s will always output bit 255.

    I'm using Speed as the value. But in DCS for example, we have the wind value also.
    The wind value in DCS looks for the amount of the cockpit open and calculates the amount of wind from that.
    So not all values are available.

    Add a serial output with:
    upload_2020-3-21_21-35-48.png
    Select the correct port

    Moderator Edit: Raw code in case the zip file does not work correctly:
    Code:
    #define BRAKEVCC 0
    #define CW   1
    #define CCW  2
    #define BRAKEGND 3
    #define CS_THRESHOLD 100
    
    int inApin[2] = {7, 4};  // INA: Clockwise input
    int inBpin[2] = {8, 9}; // INB: Counter-clockwise input
    int pwmpin[2] = {5, 6}; // PWM input
    int cspin[2] = {2, 3}; // CS: Current sense ANALOG input
    int enpin[2] = {0, 1}; // EN: Status of switches output (Analog pin)
    int statpin = 13;
    
    
    void setup()
    {
      Serial.begin(115200);
      pinMode(statpin, OUTPUT);
    
      // Initialize digital pins as outputs
      for (int i=0; i<2; i++)
      {
        pinMode(inApin[i], OUTPUT);
        pinMode(inBpin[i], OUTPUT);
        pinMode(pwmpin[i], OUTPUT);
        pinMode(pwmpin[i], 0);
        analogWrite(pwmpin[i], 0);
      }
     
      // Initialize braked
      for (int i=0; i<2; i++)
      {
        digitalWrite(inApin[i], LOW);
        digitalWrite(inBpin[i], LOW);
      }
    }
    
    void loop()
    {
    //TCCR0B = TCCR0B & B11111000 | B00000001;    // set timer 0 divisor to     1 for PWM frequency of 62500.00 Hz
      TCCR0B = TCCR0B & B11111000 | B00000010;    // set timer 0 divisor to     8 for PWM frequency of  7812.50 Hz
    
      if (Serial.available())
      {
        uint8_t Speed=Serial.read();
        if(Speed>0)
        {     
          motorGo(0, CW, Speed);     
          motorGo(1, CW, Speed);   
        }
        else if(Speed==0)
        {
          motorOff(0);
          motorOff(1);
        }
      }
    }
    
    void motorOff(int motor)
    {
      digitalWrite(inApin[motor], LOW);
      digitalWrite(inBpin[motor], LOW);
      analogWrite(pwmpin[motor], 0);
    }
        
    void motorGo(uint8_t motor, uint8_t direct, uint8_t Speed)
    {
      if (motor <= 1)
      {
        if (direct <=4)
        {
          // Set inA[motor]
          if (direct <=1) digitalWrite(inApin[motor], HIGH);
          else digitalWrite(inApin[motor], LOW);
        
          // Set inB[motor]
          if ((direct==0)||(direct==2)) digitalWrite(inBpin[motor], HIGH);
          else digitalWrite(inBpin[motor], LOW);
        
          analogWrite(pwmpin[motor], Speed);
        }
      }
    }

    Attached Files:

    • Winner Winner x 3
    Last edited by a moderator: Mar 30, 2020
  2. Ads Master

    Ads Master

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  3. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    15,374
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    113,009Coins
    Ratings:
    +9,090 / 46 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
  4. Historiker

    Historiker Dramamine Adict Staff Member Moderator Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    1,930
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,463Coins
    Ratings:
    +1,820 / 13 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    • Like Like x 2
  5. djbart82

    djbart82 New Member

    Joined:
    Nov 6, 2019
    Messages:
    21
    Occupation:
    Operador
    Location:
    28029, Madrid
    Balance:
    145Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    3DOF, Motion platform
    good

    I am trying to open the program code with Arduino IDE and it gives me an error

    Cannot create program

    Failed to open the sketch

    can you check it please

    thanks
  6. Historiker

    Historiker Dramamine Adict Staff Member Moderator Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    1,930
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,463Coins
    Ratings:
    +1,820 / 13 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    It worked for me a few days ago and the file has not changed since.

    Make sure the sketch is in its own folder, double check that you have Arduino IDE correctly installed.

    EDIT: Just checked with my office PC and found that I am getting the same error. I will grab the version from my SimpitPC later today and double check that one.
    • Informative Informative x 1
    Last edited: Mar 30, 2020
  7. Historiker

    Historiker Dramamine Adict Staff Member Moderator Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    1,930
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,463Coins
    Ratings:
    +1,820 / 13 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    You should be able to copy and paste the code into the Arduino IDE and run it. I did that and it passed the check. @djbart82



    Code:
    
    #define BRAKEVCC 0
    #define CW   1
    #define CCW  2
    #define BRAKEGND 3
    #define CS_THRESHOLD 100
    
    int inApin[2] = {7, 4};  // INA: Clockwise input
    int inBpin[2] = {8, 9}; // INB: Counter-clockwise input
    int pwmpin[2] = {5, 6}; // PWM input
    int cspin[2] = {2, 3}; // CS: Current sense ANALOG input
    int enpin[2] = {0, 1}; // EN: Status of switches output (Analog pin)
    int statpin = 13;
    
    
    void setup()
    {
      Serial.begin(115200);
      pinMode(statpin, OUTPUT);
    
      // Initialize digital pins as outputs
      for (int i=0; i<2; i++)
      {
        pinMode(inApin[i], OUTPUT);
        pinMode(inBpin[i], OUTPUT);
        pinMode(pwmpin[i], OUTPUT);
        pinMode(pwmpin[i], 0);
        analogWrite(pwmpin[i], 0);
      }
     
      // Initialize braked
      for (int i=0; i<2; i++)
      {
        digitalWrite(inApin[i], LOW);
        digitalWrite(inBpin[i], LOW);
      }
    }
    
    void loop()
    {
    //TCCR0B = TCCR0B & B11111000 | B00000001;    // set timer 0 divisor to     1 for PWM frequency of 62500.00 Hz
      TCCR0B = TCCR0B & B11111000 | B00000010;    // set timer 0 divisor to     8 for PWM frequency of  7812.50 Hz
    
      if (Serial.available())
      {
        uint8_t Speed=Serial.read();
        if(Speed>0)
        {      
          motorGo(0, CW, Speed);      
          motorGo(1, CW, Speed);    
        }
        else if(Speed==0)
        {
          motorOff(0);
          motorOff(1);
        }
      }
    }
    
    void motorOff(int motor)
    {
      digitalWrite(inApin[motor], LOW);
      digitalWrite(inBpin[motor], LOW);
      analogWrite(pwmpin[motor], 0);
    }
         
    void motorGo(uint8_t motor, uint8_t direct, uint8_t Speed)
    {
      if (motor <= 1)
      {
        if (direct <=4)
        {
          // Set inA[motor]
          if (direct <=1) digitalWrite(inApin[motor], HIGH);
          else digitalWrite(inApin[motor], LOW);
         
          // Set inB[motor]
          if ((direct==0)||(direct==2)) digitalWrite(inBpin[motor], HIGH);
          else digitalWrite(inBpin[motor], LOW);
         
          analogWrite(pwmpin[motor], Speed);
        }
      }
    }
    
    • Useful Useful x 1
  8. djbart82

    djbart82 New Member

    Joined:
    Nov 6, 2019
    Messages:
    21
    Occupation:
    Operador
    Location:
    28029, Madrid
    Balance:
    145Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    3DOF, Motion platform
    ok, thank you
    i try, thank you
  9. djbart82

    djbart82 New Member

    Joined:
    Nov 6, 2019
    Messages:
    21
    Occupation:
    Operador
    Location:
    28029, Madrid
    Balance:
    145Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    3DOF, Motion platform
    it's great now if it works properly

    this afternoon I will mount the fans and test

    thanks
  10. djbart82

    djbart82 New Member

    Joined:
    Nov 6, 2019
    Messages:
    21
    Occupation:
    Operador
    Location:
    28029, Madrid
    Balance:
    145Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    3DOF, Motion platform
    I've already tried it, it works luxury

    I have to test with a 12V source instead of a 5V to test the 1700rpm noctua at 100% and see how it is

    Thanks for the help
  11. djbart82

    djbart82 New Member

    Joined:
    Nov 6, 2019
    Messages:
    21
    Occupation:
    Operador
    Location:
    28029, Madrid
    Balance:
    145Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    3DOF, Motion platform
    Tested with a 12V source and works great with 1700rpm pwm fans

    now to adjust the speed output

    thanks for the sketch
  12. Flymen

    Flymen Flymen Gold Contributor

    Joined:
    May 19, 2018
    Messages:
    244
    Location:
    Montreal, Canada
    Balance:
    1,830Coins
    Ratings:
    +136 / 2 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF

    Thanks @pmvcda and @SilentChill, I have 2 Fans 120 v AC and with modules M012 and M150 , works perfectly!!

    Module M150 et M012 control 120 AC.png
    • Like Like x 1
  13. C1500

    C1500 Member

    Joined:
    Nov 19, 2018
    Messages:
    86
    Balance:
    452Coins
    Ratings:
    +55 / 0 / -0
    My Motion Simulator:
    Arduino, 6DOF
    Hi
    it works perfectly for me.

    Has someone a good idea what kind of ventilator we can use?
    At the moment 1 tried 2x 14cm PC-case fans. but you can feel only a light breeze over 150km/h ;o)
    It would be great if they are not to noisy

    kind regards
    Peer
  14. Historiker

    Historiker Dramamine Adict Staff Member Moderator Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    1,930
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,463Coins
    Ratings:
    +1,820 / 13 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    @C1500 I use two Seaflo bilge fans. 12V, high volume. Connected to a 12v LED power supply.





    41ra764GMEL._AC_.jpg
  15. Historiker

    Historiker Dramamine Adict Staff Member Moderator Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    1,930
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,463Coins
    Ratings:
    +1,820 / 13 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    @SilentChill using the arduino code above it works perfectly in DCS. One issue I have though: When I start my PC and until I start the serial output in Mover the fans run full speed. Is there a way to change the code to initialize the motors and then set them to zero until I start serial output?
  16. Historiker

    Historiker Dramamine Adict Staff Member Moderator Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    1,930
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,463Coins
    Ratings:
    +1,820 / 13 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    Unfortunately I had to solve the issue by mechanical means. I added a DPST toggle switch before the fans so I can simply turn them off. I was hoping for a more elegant solution though. :(

    Still, thanks again for creating the sketch in the first place.
  17. Flymen

    Flymen Flymen Gold Contributor

    Joined:
    May 19, 2018
    Messages:
    244
    Location:
    Montreal, Canada
    Balance:
    1,830Coins
    Ratings:
    +136 / 2 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    Hi, @pmvcda
    I give you a exemple ( shema) of my situation with my wind simulater .
    To 0- 150 bytes I have no wind but over 150 to 255 you can see its progressif curve !
    Q- How I can fitre this curve to have a strait line ( constant line ) and more stretched ?
    08362EE4-1D9C-4B82-8B86-761239391987.jpeg
  18. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,306
    Location:
    Portugal
    Balance:
    10,222Coins
    Ratings:
    +1,348 / 13 / -0
    My Motion Simulator:
    6DOF
    You can use a logistic filter to generate a compensation.
    Give me some time, I will show you the filter when I'm near the pc
    • Like Like x 1
    Last edited: Sep 25, 2020 at 10:15
  19. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,306
    Location:
    Portugal
    Balance:
    10,222Coins
    Ratings:
    +1,348 / 13 / -0
    My Motion Simulator:
    6DOF
    OK, I said cubic, but I meant logistic.
    I just edited the above post.

    We should act in the bit output, not in the speed value, because the problem you have is at hardware level.
    But we can't do that, so we have to act in the range of values we are using (would be good to do the correction at hardware level, in the code of the controller).

    So I'm using an 8 bit output here (0 to 255).
    And a maximum speed of 70 m/s (around 250 km/h).
    So, I'm mapping the 0 to 70 speed to the 0 to 255 bits.
    But has you said, there's a deadzone under around bit value of 100.
    So I add 30 m/s (around bit value 108 without filter) to the received value.

    upload_2020-9-25_9-50-1.png

    So now we have value 30 m/s up to 70 m/s we want to transform with a logistic to compensate the curve you have.
    So we make a logistic with maximum value of 40 (40+30=70).
    The 1.6 is the "gain" of the logistic and in your case, to compensate the curve it should be above 1.0.

    Now, if you look at the input/output graph, you can see that at speed zero, the output is 30 and above it, it increases on the logistic curve up to 70. All this is remapped to bits 0 to 255.

    For now, this is what you can do in Mover.
    I can add a logarithm filter, (i have it done but not exposed) that might make it easier, but I also consider an editable curve for the future (but not soon).

    Also note that the actuator filter, acts over the value and not the bit value!
    I already considered the possibility to change it, but might cause more confusion, although in this module it seems the more correct to do, in linear actuators, it makes more sense to use real measures.
    • Like Like x 1
  20. Flymen

    Flymen Flymen Gold Contributor

    Joined:
    May 19, 2018
    Messages:
    244
    Location:
    Montreal, Canada
    Balance:
    1,830Coins
    Ratings:
    +136 / 2 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    Thanks a lot again !! You make my day !!hug:
    Fast and full instructions !!
    You are my Tony Stark ( Ironman)/ simulator. :grin
    My set up is :
    CB0E1063-DE7A-4FA1-9097-C7AF866893A4.jpeg