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 Download Package Now!
  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 here. Do not following these rules will lead to permanent exclusion from this website: Read the forum rules.

Showroom My new 3dof, 4motors, arduinoMéga + Sabertooth

Discussion in 'DIY Motion Simulator Projects' started by ericRacer, Nov 18, 2013.

  1. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    Hi, first of all,
    I want to thank everyone who helped me and especially those who created X-sim, Simtool (my favorite) and plugins ..

    DSC00232.JPG

    Here is some pictures of the frame :

    DSC00184.JPG
    DSC00198.JPG

    DSC00194.JPG DSC00195.JPG DSC00223.JPG

    I didn't use a spring for the dead load , i transformed a jack into air cylinder.

    Attached Files:

    • Like Like x 3
    Last edited: Nov 18, 2013
  2. Ads Master

    Ads Master

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

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    the result of the air cylinder. It is adjustable with my air compressor close to the sim. And i can move it backward or forward for best balancing the dead load.

    DSC00226.JPG

    For the sensor i used the hall effect (allegro A1301) . i follow this thread for building my own ;
    http://simhq.com/forum/ubbthreads.php/topics/3674791/DIY_Sealed_Minature_Hall_Pots_.html#Post3674791

    here is mine :

    DSC00203.JPG
    DSC00204.JPG

    DSC00205.JPG
    DSC00206.JPG DSC00207.JPG DSC00208.JPG DSC00209.JPG DSC00214.JPG DSC00209.JPG
    DSC00212.JPG

    it works very great but ......after built it , i realised that cost me almost the same price this one : 1560935-40.jpg

    around 20 dollars from digikey.

    Attached Files:

    • Like Like x 2
    Last edited: Jan 14, 2014
  4. prilad

    prilad Well-Known Member SimAxe Beta Tester SimTools Developer

    Joined:
    Apr 29, 2012
    Messages:
    381
    Location:
    Dubna, Russia
    Balance:
    9,074Coins
    Ratings:
    +483 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    Hi, very interesting project! Have you any videos?
  5. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    my first test with X-sim..
  6. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    thanks....and yes
  7. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    second test.....with wood frame
    • Like Like x 2
  8. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    third test ...

    In those videos , i was using two arduino uno with x-sim , my sabertooth was settled in analogue mode with low-pass filter from arduino's pwm and the result was not as good as i was looking for.

    Recently (after this video), i replaced both arduinos uno against arduinoMéga 2560 because it has 3 mores serial port, with these comport i am able to use my Sabertooth in serial mode with better result.

    My last video will come soon.... with SimTool and my new code....
    • Like Like x 5
    Last edited: Nov 19, 2013
  9. eaorobbie

    eaorobbie Well-Known Member Staff Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,593
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    19,693Coins
    Ratings:
    +1,655 / 22 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Would have to totally agree a nice interestingly different build. Sweet.
  10. bsft

    bsft

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Hello Eric, welcome. Nice build and hopefully we are more helpful than the "other" forum.
  11. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
  12. hooshang

    hooshang Active Member Gold Contributor

    Joined:
    Jul 6, 2011
    Messages:
    251
    Balance:
    195Coins
    Ratings:
    +145 / 3 / -0
    My Motion Simulator:
    2DOF, DC motor, AC motor, Arduino, 6DOF
    @ericRacer
    congratulation for the nice job and innovative pivot and also tidy assemble.
    iam also going to upgrade my sim board to Arduino Uno,what firmware do you used for
    your Arduino Eric?
    regards
    Hooshang
  13. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    Hi Hooshang,

    thanks, :),

    I replaced Arduino Uno by Méga because it has 3 mores serial comport and it was easier for me to write my code for using Sabertooth in "Simplified Serial packetized " mode (i am not a programmer o_O)

    In those video i was using Uno with X-Sim and Xpid but the performance was not as good as i wanted. :sos

    then , i wrote my code (Xpid , inspiring me a lot ! :thumbs) and tried SimTool that i adopted ! It is wonderfull !

    Now the performance is really as good as i was looking for.

    here is my code and if someone has good idea to improve it >> don' be shy ! :grin
    Eric
    • Like Like x 1
    Last edited: Nov 21, 2013
  14. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    Code:
    // pinning overview :
    //
    //                  +-\/-+
    //            PC6  1|    |28  PC5 (AI 5)
    //      (D 0) PD0  2|    |27  PC4 (AI 4)
    //      (D 1) PD1  3|    |26  PC3 (AI 3)
    //      (D 2) PD2  4|    |25  PC2 (AI 2)
    // PWM+ (D 3) PD3  5|    |24  PC1 (AI 1)
    //      (D 4) PD4  6|    |23  PC0 (AI 0)
    //            VCC  7|    |22  GND
    //            GND  8|    |21  AREF
    //            PB6  9|    |20  AVCC
    //            PB7 10|    |19  PB5 (D 13)
    // PWM+ (D 5) PD5 11|    |18  PB4 (D 12)
    // PWM+ (D 6) PD6 12|    |17  PB3 (D 11) PWM
    //      (D 7) PD7 13|    |16  PB2 (D 10) PWM
    //      (D 8) PB0 14|    |15  PB1 (D 9) PWM
    //                  +----+
    
    // Copyright (c) 2012 Dimension Engineering LLC
    // See license.txt for license details.        // We'll name the Sabertooth object ST.
    #include <SabertoothSimplified.h>
    SabertoothSimplified ST1(Serial3);    // RX (unused), TX on pin 14 (serial2)to S1 of M1,M2
    SabertoothSimplified ST2(Serial2);    // RX (unused), TX on pin 16 (serial2)to S1 of M3,M4
                                        // Connections to make:
                                        //  Arduino TX->1  ->  Sabertooth S1
                                        //  Arduino GND    ->  Sabertooth 0V
                                        //  Arduino VIN    ->  Sabertooth 5V (OPTIONAL, if you want the Sabertooth to power the Arduino)
                                  //
                                  // If you want to use a pin other than TX->1, see the SoftwareSerial example.
    
    
    
    #if defined(ARDUINO) && ARDUINO >= 100
    #include "Arduino.h"
    #else
    #include "WProgram.h"
    #endif
    
    #define FASTADC  1                    //Hack to speed up the arduino analogue read function
    
    // defines for setting and clearing register bits
    #ifndef cbi
    #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
    #endif
    #ifndef sbi
    #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
    #endif
    
    double KP = 8.0;
    double KI = 6.0;
    double KD;
    double sampletime = .1;      // 1 mSec.
    
    //Define Variables we'll be connecting to
    double currentanalogue1 = A9;
    double currentanalogue2 = A8;
    double currentanalogue3 = A11;
    double currentanalogue4 = A10;
    
    double target1;
    double target2;
    double target3;
    double target4;
    
    int ledPin=13;          // for debugging
    
    int outMax = 127;
    int outMin = -126;
    double lastError_1, lastError_2, lastError_3, lastError_4;
    double error_1, error_2, error_3, error_4;
    double Output_1, Output_2, Output_3, Output_4;
    unsigned long lastTime;
    
    //Specify the links and initial tuning parameters PID
    int buffer            = 0;                    // Mémoire tampon pour les variables de comm.
    int disable;
    int buffercount        =-1;
    int commandbuffer[6];
    
    ///////////////////////////////////////////////////////////////////
    
    void setup() {
      Serial.begin(115200);                // Initialise la communication à 38400 bauds
      Serial2.begin(38400); // This is the baud rate you chose with the DIP switches. (dip SW 2, 4 et 5 => OFF)
      Serial3.begin(38400);
    
      pinMode(ledPin, OUTPUT);            // for debugging only
      disable=0;
    
    #if FASTADC
      // set analogue prescale to 16
      sbi(ADCSRA,ADPS2) ;
      cbi(ADCSRA,ADPS1) ;
      cbi(ADCSRA,ADPS0) ;
    #endif
    }
    
    ////////////////////////////////////////////////////////////////////
    
    void FeedbackPotWorker()
    {
      /*  convertion du pot 0-1023 en radian + calibration:
    
        motors(pot) :      Min  :  Max    :    Différence          degré -> radian
      ------------------------------------------------------------------------------------------
                1    :      123  :  884    :      761    :    761/3.14159(radian) = 242.2340
                2    :      175  :  824    :      649    :    649/3.14159(radian) = 206.5833
                3    :      174  :  842    :      668    :    668/3.14159(radian) = 212.6311
                4    :      338  :  700    :      362    :    362/3.14159(radian) = 115.2283
              
                la différence équivaut à 180°, donc 769/180° donnerait = 4.27 et égaliserait 1° mais ici le COS() doit être en radian donc
                769/3.14159(radian) = 244.78
      */
    
      float currentanalog1 = (analogRead(A9)-123)/242.2340;      
      float currentanalog2 = (analogRead(A8)-175)/206.5833;
      float currentanalog3 = (analogRead(A11)-174)/212.6311;
      float currentanalog4 = (analogRead(A10)-338)/115.2283;
    
      currentanalogue1 = (127*cos(currentanalog1))+127;        // conversion linéaire et transformation de 0 - 255 (127=milieu)
      currentanalogue2 = (127*cos(currentanalog2))+127;
      currentanalogue3 = (127*cos(currentanalog3))+127;
      currentanalogue4 = (127*cos(currentanalog4))+127;
      // pour 0-255 : (127*cos((float)A0/81.17))+127 -> degré en radian
      // pour 0-1023 : (512*cos((float)A0/325.9437))+512 -> degré en radian
      disable=0;
    }
    
    void ParseCommand()
    {
      if ( commandbuffer[0]=='R')                // "R" for data Receiving
      {
        target1=commandbuffer[1];              // target must be between 0-255 (only 1 byte)
        target2=commandbuffer[2];
        target3=commandbuffer[3];
        target4=commandbuffer[4];
      }
    
      if ( commandbuffer[0]=='P')                // P for PID => kp , ki , kd ans sampleTime
      {
        KP=commandbuffer[1];              // target must be between 0-255 (only 1 byte)
        KI=commandbuffer[2];
        KD=commandbuffer[3];
        sampletime=commandbuffer[4];
      }
    }
    
    bool CheckChecksum()                  // Check for "E" as the packet end byte
    {
        byte checksum = commandbuffer[5];
        if(checksum =='E'){return true;}
        return false;
    }
    
    void SerialWorker()
    {
      while(Serial.available())
      {
        if(buffercount==-1)
        {
          buffer = Serial.read();
          if(buffer != 'X'){
            buffercount=-1;
          }
          else{
            buffercount=0;
          }
        }
        else
        {
          buffer = Serial.read();
          commandbuffer[buffercount]=buffer;
          buffercount++;
          if(buffercount > 6)
          {
            if (CheckChecksum()==true){ParseCommand();}
            buffercount=-1;
          }
        }
      }
      disable=1;
    }
    
    void CalculatePID()
    {
      unsigned long now = millis();
      int timeChange = (now - lastTime);
      if(timeChange>=sampletime)
      {
        error_1 = target1 - currentanalogue1;
        Output_1 = (KP * error_1) - (KI * lastError_1);
        if(Output_1 > outMax) Output_1 = outMax;
        else if(Output_1 < outMin) Output_1 = outMin;
      
      
        error_2 = target2 - currentanalogue2;
        Output_2 = (KP * error_2) - (KI * lastError_2);
        if(Output_2 > outMax) Output_2 = outMax;
        else if(Output_2 < outMin) Output_2 = outMin;
    
      
        error_3 = target3 - currentanalogue3;
        Output_3 = (KP * error_3) - (KI * lastError_3);
        if(Output_3 > outMax) Output_3 = outMax;
        else if(Output_3 < outMin) Output_3 = outMin;
      
      
        error_4 = target4 - currentanalogue4;
        Output_4 = (KP * error_4) - (KI * lastError_4);
        if(Output_4 > outMax) Output_4 = outMax;
        else if(Output_4 < outMin) Output_4 = outMin;
    
        /*Remember some variables for next time*/
        lastError_1 = error_1;
        lastError_2 = error_2;
        lastError_3 = error_3;
        lastError_4 = error_4;
        lastTime = now;
      }
      disable=0;
      }
    
    void Stop_Motors()
    {
        ST1.motor(1, 0);                      // Tx is on Serial_2 pin 14  to S1 of sabertooth M1 & M2
        ST1.motor(2, 0);
        ST2.motor(1, 0);                      // Tx is on Serial_2 pin 16  to S1 of sabertooth M3 & M4
        ST2.motor(2, 0);
    disable=1;
    }
    
    void SetCommand()
    {
              
      ST1.motor(1, Output_1);                              // motor 1 , output pin connected on S1
      ST1.motor(2, Output_2);
      ST2.motor(1, Output_3);            // motor 3
      ST2.motor(2, Output_4);              // motor 4
    }
    
    void loop()  {
      while (1==1)      //Important hack: Use this own real time loop code without arduino framework delays
      {
        FeedbackPotWorker();
        SerialWorker();
        CalculatePID();
        if(disable==0)
        {
          SetCommand();
        }
            else
        {
        Stop_Motors();
        }
      }  
    }
    
    • Like Like x 2
  15. bartez81

    bartez81 i like amps

    Joined:
    Feb 11, 2012
    Messages:
    38
    Location:
    Kraków
    Balance:
    58Coins
    Ratings:
    +14 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, AC motor, SCN6, Arduino, JRK, Motion platform
    Hi when i try to compile i get these error:
    sketch_dec18a:23: error: 'SabertoothSimplified' does not name a type
    sketch_dec18a:24: error: 'SabertoothSimplified' does not name a type
    sketch_dec18a.ino: In function 'void Stop_Motors()':
    sketch_dec18a:230: error: 'ST1' was not declared in this scope
    sketch_dec18a:232: error: 'ST2' was not declared in this scope
    sketch_dec18a.ino: In function 'void SetCommand()':
    sketch_dec18a:240: error: 'ST1' was not declared in this scope
    sketch_dec18a:242: error: 'ST2' was not declared in this scope
    ?
  16. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    3,657
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    29,871Coins
    Ratings:
    +3,693 / 10 / -0
    • Like Like x 1
  17. eaorobbie

    eaorobbie Well-Known Member Staff Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,593
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    19,693Coins
    Ratings:
    +1,655 / 22 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    To me thats saying the sabertooth libary is not installed into the Ard IDE. This is needed to compile the code.
    • Like Like x 1
  18. bartez81

    bartez81 i like amps

    Joined:
    Feb 11, 2012
    Messages:
    38
    Location:
    Kraków
    Balance:
    58Coins
    Ratings:
    +14 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, AC motor, SCN6, Arduino, JRK, Motion platform
    u are right boss. :)
  19. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    here is the library :
    http://www.dimensionengineering.com/info/arduino

    and you don't really need Arduino Mega, I tried with Duemilanove with the "SoftwareSerial" who is a library and that works very well too. :grin

    sorry for the wrong info but i am newbie and learning ! :confused:
    thanks
    • Like Like x 1
    Last edited: Dec 20, 2013
  20. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    226
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    - 1Coins
    Ratings:
    +137 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    my last video, but sorry for the poor quality :( :
  21. eaorobbie

    eaorobbie Well-Known Member Staff Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,593
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    19,693Coins
    Ratings:
    +1,655 / 22 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Motion not bad considering its Ard run and 3DOF , going off track looks very scary, well done.
    • Like Like x 1