1. Do not share user accounts! Any account that is shared by another person will be blocked and closed. This means: we will close not only the account that is shared, but also the main account of the user who uses another person's account. We have the ability to detect account sharing, so please do not try to cheat the system. This action will take place on 04/18/2023. Read all forum rules.
    Dismiss Notice
  2. 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!
  3. 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
  4. 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

Tutorial SPS - Sabertooth Packet Serial PID motor driver sketch w/SoftStart

Discussion in 'SimTools compatible interfaces' started by BlazinH, Nov 10, 2016.

  1. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,145
    Location:
    Oklahoma City, USA
    Balance:
    16,568Coins
    Ratings:
    +1,830 / 32 / -1
    SPS (previously SMC3-SPS) is a modified version of RufusDufus’s fantastic SMC3 sketch.
    SPS = Sabertooth Packet Serial version.

    Features:

    *Support for one Sabertooth 2x32 or one Sabertooth 2x60. (controls 2 motors only but you can use additional Arduinos to add more motors if needed).

    *Support for Mega and Uno Arduinos (uses the same sketch for both)

    *Plug and Play Sabertooth 2x60 – on a new 2x60 just set dipswitches and wire up as shown in the wiring diagram. (note: A new 2x32 also requires use of DEscribe software to set the baud rate and serial timeout feature)

    *Packet Serial Mode – uses a checksum so a Sabertooth won’t act if there are transmission errors.

    *Serial Timeout feature – a Sabertooth will shut down motors if a new position command is not received within 100ms of the last one.

    *Double Motor Resolution - twice the resolution of Simple Serial mode.

    *Soft Start Motor startup (at top of sketch look for //SET SOFTSTART SPEED const int SSloop = 8;. Increase SSloop for a slower start and decrease for a faster start)

    *Self-configuring baud rate on 2x60’s – will automatically change the baud rate of a new 2x60 from its 9600 default setting to 115200 baud. This makes the use of Describe software from Dimension Engineering as well as the need to purchase a TTL line level converter for the 2x60 Sabertooth unnecessary.
    A baud rate change to 115200 on a Sabertooth 2x60 that has been previously set to 19200 or 38400 baud can be accomplished automatically also by adding a jumper wire from ground to the appropriate pin on the Arduino (see wiring diagram)

    *Full PID motor control via the original SMC3 sketch by RufusDufus.

    ===Many thanks to @Pit for his assistance and serving as a test dummy for the cause:)===


    wiring.jpg

    Initial Setup

    Make sure Simtools is NOT running.

    1. If you have a new 2x32 or a 2x32 that is not already set to 115200 baud, use DEscribe software to set its baud rate to 115200. (note: setting the baud on a new 2x60 with DEscribe is not necessary) https://www.dimensionengineering.com/info/describe
    2. If you wish to use serial timeouts on a 2x32 you must set them to 100ms using DEscribe also.
    3. Wire up your Arduino to your Sabertooth as shown above in the wiring diagram
    4. Connect your Arduino to your computer via USB.
    5. If not already done download and install the Arduino programming software
    6. Download and run SabertoothArduinoLibrary.exe attached below
    7. If not already done apply power to your Sabertooths motor inputs.
    8. Now use the Arduino programming software to install the SPS sketch attached below on your Arduino. Make sure you choose Uno or Mega and to set the comport number.
    9. Next download and run the Windows SMC3 Utility software attached below and make sure it communicates with your Arduino. Open the accompanying SMC3Utils.ini with notepad to change the comport if needed (see image below)
    10. Set Fpid to / 1. (If you experience motor twitching or other issues then try increasing it)
    11. Set Step to 100 and then set Kp, Ki, Kd, PWMmin, PWMmax, PWMrev to 0 (This will make sure the motors don’t move)
    12. Set Clip to 255 (you need to do this first) and Limit to 255 (This will give you plenty of margin if something goes wrong while setting up)
    13. Now click the -> M2 button to apply the same settings to motor 2 also
    14. Change Kp for motor 1 from 0 to about 400
    15. Set step back to 1
    16. Click the ON/OFF button for motor 1 to ON
    17. Now slowly, increase PWMmax… at some point the motor should start to move. When it does check the “Green” feedback line is moving toward the “Blue” target position.
      • If it is then that motor and feedback is wired correctly - proceed to test other motors.
      • If it is moving away turn off motor power immediately (or quickly reduce PWMmax again). In this case you need to either reverse the wires to the motor being tested –OR– reverse the +5V and GND wires to your feedback pot for the motor being tested (do not do both). Restart the test from the beginning.
      • If you are using a 2x60 and the motor doesn’t move, and assuming its wiring is correct, then its possible that your Sabertooths baud rate did not match what was expected when the sketch was run so it may not have autobauded. See the wiring diagram about setting jumpers to try a different baud rates.
    18. Set Step back to 100 and repeat steps #13, #14, #15, and #16 above for motor 2
    19. Motor driver setup is now complete but the PID controller will still need to be turned to work properly with your particular setup. This will be done later though and is not included in the scope of this tutorial
    20. Now start Simtools Game Engine (see image below)
    21. Open Interface Settings
    22. Now set up Interface1 as shown in the image below but substitute your arduino’s ComPort number if it is not on Com1.
    23. Click the SAVE button
    24. Simtools Game Engine Interface is now correctly configured to send data to the SPS motor driver sketch
    25. That’s all. You can now start testing your setup with Simtools.

    For further information regarding PID tuning and Windows SMC3 Utilities go here.
    SMC3 Arduino 3DOF Motor Driver and Windows Utilities



    SMC_ut.jpg

    simtinf.jpg
    Simtools2 requires you add an a or b to the end of each axis. Example [A<Axis1a>]


    Below is useful information regarding the Sabertooths power and wiring requirements


    2x32pow.jpg

    The Dimension Engineering Resistor Calculator can be found here: https://www.dimensionengineering.com/calculators/power-resistor

    2x60pow.jpg
    wireg.jpg

    UPDATE Beta5 to Beta 6 on Nov 12, 2016 - commented out motor3 to optimize serial execution speed and because it likely won't be used anyway since only one motor channel on a second sabertooth can be used.

    UPDATE Beta to RC on Jan 4, 2017 - Further optimized timing. Fpid can now be set as low as 1. Added soft start motor startup.

    UPDATE on Oct 10, 2019 - Fixed bug in softstart

    UPDATE on Nov 10, 2020 - SPS 8.2 - Fixed not saving PWMmax

    Attached Files:

    • Winner Winner x 18
    • Like Like x 8
    • Informative Informative x 4
    • Useful Useful x 2
    Last edited: Nov 10, 2020
  2. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,145
    Location:
    Oklahoma City, USA
    Balance:
    16,568Coins
    Ratings:
    +1,830 / 32 / -1
    Note: Due to everyone incorrectly referencing the name of this sketch it was changed to simply SPS to eliminate confusion on 6/3/2020.
    • Useful Useful x 1
    • Creative Creative x 1
    Last edited: Jun 4, 2020
  3. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,393Coins
    Ratings:
    +3,479 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    Awesome @BlazinH you must of read my mind as I am about to upgrade to these :D

    Thanks
    • Like Like x 2
  4. wannabeaflyer2

    wannabeaflyer2 Well-Known Member

    Joined:
    Jun 12, 2015
    Messages:
    724
    Location:
    london uk
    Balance:
    8,284Coins
    Ratings:
    +950 / 7 / -0
    My Motion Simulator:
    2DOF, Arduino, Motion platform, 6DOF
    Mr will you stop shifting the goal post LOL :) seriously once again thanks for the effort put into this , very informative and well laid out nicely done and will be a great help to a lot of us guys here .. massive respect @BlazinH :)
    • Like Like x 1
    • Funny Funny x 1
  5. wannabeaflyer2

    wannabeaflyer2 Well-Known Member

    Joined:
    Jun 12, 2015
    Messages:
    724
    Location:
    london uk
    Balance:
    8,284Coins
    Ratings:
    +950 / 7 / -0
    My Motion Simulator:
    2DOF, Arduino, Motion platform, 6DOF
    @SilentChill ya beat me by 2 seconds LOL great stuff all round ....things were good before on this forum these guys are stepping up big time , Am i loving it or what :)
    • Funny Funny x 1
  6. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,437
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    144,452Coins
    Ratings:
    +10,730 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Brilliant tutorial and a great option for using Sabertooths, which given the frustrations with MMs are likely to be used more often in demanding sims :thumbs
    • Agree Agree x 2
  7. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,145
    Location:
    Oklahoma City, USA
    Balance:
    16,568Coins
    Ratings:
    +1,830 / 32 / -1
    No mate, I can't read minds (thank god). But I can read posts (sometimes). :D Actually Pit and I have been working on this for a few months now when we had the time. As of a few days ago all that was left was to create a thread for the sketch. Since I saw you would be receiving 2x32's soon, I decided to spend the time to get this posted now for you and others.

    I'm still calling it a beta though because only Pit and I have tested it so far. And I only have 2x60's so I tested on it and Pit tested on his 2x32. I think issues are sorted now but with only two testers I can't say for sure that they all are. So all feedback is welcomed.hug:
    • Like Like x 4
    • Winner Winner x 1
  8. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,393Coins
    Ratings:
    +3,479 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    Can't thank you and @Pit enough I really appreciate the time you guys must of put into it. I'm just waiting for the damn drivers to arrive now. Hopefully I will get them before the weekend but at the moment they are still in France :(
    • Agree Agree x 1
    • Friendly Friendly x 1
  9. SeatTime

    SeatTime Well-Known Member

    Joined:
    Dec 27, 2013
    Messages:
    2,574
    Occupation:
    Retired
    Location:
    Brisbane Australia
    Balance:
    28,370Coins
    Ratings:
    +2,844 / 38 / -0
    My Motion Simulator:
    AC motor, Motion platform
    Excellent work @BlazinH and @Pit :thumbs , with the unreliable nature of MMs , these will be the goto controller/driver combination for any larger sized sim.
    • Agree Agree x 1
    • Friendly Friendly x 1
  10. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,393Coins
    Ratings:
    +3,479 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
  11. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,393Coins
    Ratings:
    +3,479 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    Ok got it working :D

    Ok got a problem lolol When I go into to simtools to test DOF I'm getting weird glitching on each motor every few seconds its like twitching a bit ?? Its perfectly stable in SMC3 no movement at all until I ask it to .

    Anyone any ideas ??

    @Pit @wannabeaflyer2 @BlazinH @Grigory ??? please help :)
  12. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,145
    Location:
    Oklahoma City, USA
    Balance:
    16,568Coins
    Ratings:
    +1,830 / 32 / -1
    Are you using a mega or uno? Pit reported similar behavior when using his mega but he said changing 10ms to 1ms in Simtools interface fixed it. If that doesn't do it you can also try grounding pin 8 and reducing the baud from 500000 to 115000.
    • Informative Informative x 2
    • Agree Agree x 1
    • Useful Useful x 1
  13. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,145
    Location:
    Oklahoma City, USA
    Balance:
    16,568Coins
    Ratings:
    +1,830 / 32 / -1
    Btw, I know you figured it out already but for information Fpwm is irreverent since we are not directly controlling the h-bridge on the sabertooth.
    • Agree Agree x 1
  14. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,393Coins
    Ratings:
    +3,479 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    Thanks matey I will try in the morning, I am using UNO clones. I thought pin8 was just for 2x60's will try that too :)
  15. mariano68

    mariano68 Active Member

    Joined:
    Nov 15, 2014
    Messages:
    577
    Occupation:
    builder contractor
    Location:
    Argentina
    Balance:
    3,338Coins
    Ratings:
    +395 / 2 / -0
    My Motion Simulator:
    2DOF, Arduino, 4DOF
    Better motors, better software (Simtools 2.0), better designs, all ask for a better driver and better software driver, perfect timing! You guys are great!
    I'm ordering a pair of sabertooth 2x32 for my new sim!
    • Like Like x 1
    • Winner Winner x 1
  16. Pit

    Pit - - - - - - - - - - - - - - - - Gold Contributor

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,408Coins
    Ratings:
    +3,085 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    SimTools = 500000
    Sabertooth = 115200
    Uno or Mega = 115200
    SimTools Paket Rate Uno = 10ms
    SimTools Paket Rate Mega = 1ms
    • Informative Informative x 3
  17. RufusDufus

    RufusDufus Well-Known Member

    Joined:
    Jul 21, 2013
    Messages:
    681
    Location:
    Adelaide Australia
    Balance:
    15,592Coins
    Ratings:
    +1,008 / 8 / -1
    Nice work!
    • Friendly Friendly x 1
  18. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,619
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,393Coins
    Ratings:
    +3,479 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    Ok I've tried changing the PacketRate and it makes the twitches more frequent at 1ms and if I put it higher than 10ms they do go away but the motion is jerky as hell. In fact the movement from simtools is terrible its jerking everywhere.

    I use SCM3 to move the actuators and they are as smooth as you like, I have no idea lol
  19. Pit

    Pit - - - - - - - - - - - - - - - - Gold Contributor

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,408Coins
    Ratings:
    +3,085 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    1ms is only MEGA compatible. Can you upload all your settings for once?
  20. Pit

    Pit - - - - - - - - - - - - - - - - Gold Contributor

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,408Coins
    Ratings:
    +3,085 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF