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

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

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

  1. wannabeaflyer2

    wannabeaflyer2 Well-Known Member

    Joined:
    Jun 12, 2015
    Messages:
    667
    Location:
    london uk
    Balance:
    7,611Coins
    Ratings:
    +878 / 4 / -0
    My Motion Simulator:
    2DOF, Arduino, Motion platform, 6DOF
    Hi @SeatTime early days with this to be honest , I wont be able to provide better info until I finally get simtools running so that I can see real life operation under simulation running mode .

    had a bee in my bonnet about using optical encoders for a while and now that the means of doing this have crossed my path I thought I'd give it a whirl ..


    Warning did not have my hearing aid on so forgot about noisy PC fan :-(

    this is the very basic setup with no real fine tuning of PID / PWM values etc in smc just needed you guys to have an input in case I misunderstood what should be happing during the running of SMC utility and the interpretation of what should correct operation incase I have missing pulse counting due to not fitting Pull up resistors on the encoder channel a&b outputs ..

    Cheers Guys
    • Like Like x 1
  2. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,119
    Location:
    Oklahoma City, USA
    Balance:
    15,579Coins
    Ratings:
    +1,797 / 31 / -1
    Thanos's Encoder2pos board converts encoder signals into 12 bit analog. The arduino uno and mega only have 10 bit adc's though negating the additional resolution. There are still two possible advantages using it though. There's no drift with encoders like with hall pots and if Thano's board outputs a full 0-5 volts you will gain around 4% additional range at both ends since hall pots usually only output .2 to 4.8 volts. But since his board likely uses a 12 bit dac to output the voltage, it will still be limited to 4096 total positions making it the same resolution as a hall pot when used on a 10 bit adc. Also if the encoder signal does go thru a dac that likely induces drifting.
    Last edited: Dec 2, 2018
  3. wannabeaflyer2

    wannabeaflyer2 Well-Known Member

    Joined:
    Jun 12, 2015
    Messages:
    667
    Location:
    london uk
    Balance:
    7,611Coins
    Ratings:
    +878 / 4 / -0
    My Motion Simulator:
    2DOF, Arduino, Motion platform, 6DOF
    Hi @BlazinH really appreciate the tech feedback as I tend to be ok Mechanical wise but electronics per say is not my strongest element ..
    Last edited: Dec 2, 2018
  4. JeepGunner82

    JeepGunner82 Member Gold Contributor

    Joined:
    May 23, 2016
    Messages:
    41
    Location:
    San Jose, CA
    Balance:
    201Coins
    Ratings:
    +16 / 0 / -0
    My Motion Simulator:
    2DOF, SCN5
    something doesn't seem right... can't turn on motors.. 2x60 0v -gnd, S1-pin13. pot Analog-A0 Pot A&B-pins 2,3. connection seems solid. Something to do with baud?

    Attached Files:

  5. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,119
    Location:
    Oklahoma City, USA
    Balance:
    15,579Coins
    Ratings:
    +1,797 / 31 / -1
    In short what I said was there won't be any resolution gain when using Encoder2pos instead of hall pots with SMC3-SPS.
    • Informative Informative x 1
  6. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,119
    Location:
    Oklahoma City, USA
    Balance:
    15,579Coins
    Ratings:
    +1,797 / 31 / -1
    Nope. Motors turning on in SMC3 utilities has nothing to do with the sabertooths baud rate, it has to do with feedback being in range. If the motors turn on in utilities and still don't run then it may be a baud issue.
  7. wannabeaflyer2

    wannabeaflyer2 Well-Known Member

    Joined:
    Jun 12, 2015
    Messages:
    667
    Location:
    london uk
    Balance:
    7,611Coins
    Ratings:
    +878 / 4 / -0
    My Motion Simulator:
    2DOF, Arduino, Motion platform, 6DOF
    Hi @BlazinH all info soaking into grey matter nicely, and its all appreciated , :cheers
  8. Thanos

    Thanos Building the Future one AC Servo at a time... or 6

    Joined:
    Jul 6, 2017
    Messages:
    813
    Occupation:
    Electronics Engineer
    Location:
    United States
    Balance:
    4,373Coins
    Ratings:
    +697 / 6 / -0
    My Motion Simulator:
    AC motor, Motion platform, 4DOF, 6DOF
    Unless you are willing to do some oversampling in the code. With oversampling, the 10bit analog inputs of an Atmel micro can provide up to 12bit accurate measurement given you don't have very much noisy system. But then again the Encoder2position modules does exactly that, provides noise free 12bit analog signal...
  9. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,119
    Location:
    Oklahoma City, USA
    Balance:
    15,579Coins
    Ratings:
    +1,797 / 31 / -1
    Correction: In short what I said was there won't be any resolution gain when using Encoder2pos instead of hall pots with SMC3-SPS as currently written.

    But since you seem to already know what needs to be added to improve it @Thanos please go ahead and do so buddy; its open source after all. I'm sure there will be members here who will be very appreciative of your contribution to the sketch and to the diy community. :popcorn:popcorn
    Last edited: Dec 8, 2018
  10. dorulet

    dorulet New Member

    Joined:
    Aug 30, 2018
    Messages:
    4
    Balance:
    6Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Hello

    I am having an issue with CH2 on my Sabertooth 2x60 on my initial setup with SMC3-SPS.

    Notes on the setup:
    The 6V Pololu motors that i use at this point are toys! The motors that i want to use for the motion sim are 24V and much too powerful for a desk test, this being the same reason why i want to make sure everything works to a certain degree before connecting those.
    The scope of this setup is to prepare Arduino, Sabertooh, SimTools, connections between components, etc.
    Setup:
    • Arduino Mega 2560 in this form factor (same schematic as normal one only smaller):
    Atmega.JPG
    • Sabertooth 2x60
    • Sony 8.4V, 1.5A power for the Sabertooth
    • Pololu 228:1 Plastic Gearmotor (search for POLOLU-1118)
    • ALPS RK09K113004U 10k Pots (junk i had laying around)

    First i want to talk about CH1. I have first tried CH1 and it seems to work exactly as i expected.
    CH1 Working properly.jpg
    I have configured and tested Ch1 all the way to LFS. Tested with heave and roll. Responds as expected.
    Feedback is not following target due to low PWMmax. I have tried with PWMmax 60 and it follows it perfectly, but it cooks the motor. I am guessing this is because of the crappy motors + over voltage from the power supply.

    Now onto Ch2.
    In picture 1 we have Ch2, with same motor as Ch1, same polarity on both the motor and the pot as for Ch1.
    5th same polarity.jpg
    Motor starts with proper speed (dependent on PWMmax) in what i concluded, after several test sessions, to be a random direction.
    You can see that it keeps that direction throughout the test. Also you can note that it seems to be trying to compensate for the target route but nowhere near enough.

    Picture 2:
    3rd, same polarity.jpg
    In this picture you can see that motor pics one direction, still keeps speed according to (now higher) PWMmax. In this case it ignores the target completely. When PWMmax is above about 13 it seems to always completely ignore target. The bigger the PWMmax value, the faster it will go to the mechanical limits (no change in behavior).

    Picture 3:
    2nd Reverse polarity,.jpg
    For this picture i have swapped polarity on the pot.
    What i would like to mention is that even after manually setting the PWMmax to 0 the motor does not stop. It then reaches a mechanical stop, and if i go and force it in the other direction it still powered on and wants to go in the initial direction. ON/OFF button in SMC Utility does nothing. Only way to stop this is powering off the Sabertooth. This is the same for all the cases, even the ones above with the sine target.

    Picture 4:
    Same as picture 3 (inverted polarity than Ch1) but a different case.
    1st Reverse polarity.jpg

    Picture 5:
    Sabertooth powered off, manually turning the motor to see pot feedback. Probably not relevant in this case.
    4th manual movement same polarity.jpg

    Conclusion:
    In the last 2 days i have pulled my hair out with this. I have tried fiddling with almost all of the values, switched polarities back and forth, burnt 2 motors, etc. So I am writing this because i have run out of ideas. So any suggestion is welcomed at this point.
    If i missed some important information or there is need for additional photos (maybe with the actual setup). I can also provide those.
  11. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,119
    Location:
    Oklahoma City, USA
    Balance:
    15,579Coins
    Ratings:
    +1,797 / 31 / -1
    I don't know whats going on but to start narrowing things down what happens if you pull out the wire to S1 instead of powering off the Sabertooth? Does the motor stop?
  12. dorulet

    dorulet New Member

    Joined:
    Aug 30, 2018
    Messages:
    4
    Balance:
    6Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    First of all thank you for your response. Secondly, sorry for my late response, but i got carried away with Christmas holidays.

    Short version:
    I have fixed the problem. It was a beginner mistake that i tried so hard not to make. Inverted polarity on Ch2.

    Long version:
    Like i have said before, the actual problem was inverted polarity, but how could have that happen, when i have clearly stated that i changed polarity on this channel several times? It actually is a case of mixed channels than mixed polarity. What do i mean by this? Well you see i have made a prototype "motherboard" that takes care of all the necessary connections Sabertooth <->Arduino<->Pots. This motherboard also includes an additional controller that also provides some additional features: controls power supplies, provides an emergency button, ON/OFF button, monitors pot status (can cut power if something goes wrong regardless of Arduino status), display and more.
    Problem was that i have wired Ch1 on Ch2 connector and vice versa. So i just had luck that Ch1 worked right from the start, and when i was changing polarity for "Ch2" i was actually changing it for Ch1 instead. I knew that Ch1 worked so it did not cross my mind to re-check Ch1. I only realized the issue when disconnecting and reconnecting everything.
    After sorting out this issue i got both channels to work as expected all the way to LFS.
  13. Gabor Pittner

    Gabor Pittner Active Member Gold Contributor

    Joined:
    Oct 25, 2018
    Messages:
    181
    Location:
    Szekesfehervar Hungary
    Balance:
    1,113Coins
    Ratings:
    +82 / 0 / -0
    My Motion Simulator:
    6DOF
    Hello Guys,

    I've been stuck in a very confusing situatuion. I configured my motors with SMC3 utility. Motors moving properly, but when I go to simtools and turn on output test, each motors move a bit from middle home position. During test they are moving randomly up and down, as you can see that short video: I guess they search that strange home point all the time. Can somebody notice what could be wrong?

    Last edited: Jan 1, 2019
  14. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,119
    Location:
    Oklahoma City, USA
    Balance:
    15,579Coins
    Ratings:
    +1,797 / 31 / -1
    Last time this issue popped up (where utilities works correctly but not Simtools) is was a communications issue with Simtools at 500000 baud. Therefore the first thing to try is to put a jumper from pin 8 to gnd on your Ard then reset. Now use 115200 in Simtools instead of 500000 and see if you have success.

    Note: You must switch it back to 500000 to use utilities again though.
    • Agree Agree x 1
  15. Gabor Pittner

    Gabor Pittner Active Member Gold Contributor

    Joined:
    Oct 25, 2018
    Messages:
    181
    Location:
    Szekesfehervar Hungary
    Balance:
    1,113Coins
    Ratings:
    +82 / 0 / -0
    My Motion Simulator:
    6DOF
    Thank you @BlazinH very much for help me. I tried that, ...switched to 115200 as you said but it the same happens. Motors move a bit forward when turn on output test and don't run properly during the test. After I reset Arduino, motors move the correct midpoint, but starting simtools they are wrong again.
    Now I configured my second arduino uno, upload "SMC3_packet_serial_beta8_softstart" sketch, set motors up in the utility, everithyng was good, motors run correctly. But when I started simtools everything the same happened. :(
  16. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,119
    Location:
    Oklahoma City, USA
    Balance:
    15,579Coins
    Ratings:
    +1,797 / 31 / -1
    Unfortunately I don't have anymore suggestions to try atm but it certainly looks like a Simtools settings or communications issue.
    • Like Like x 1
  17. Gabor Pittner

    Gabor Pittner Active Member Gold Contributor

    Joined:
    Oct 25, 2018
    Messages:
    181
    Location:
    Szekesfehervar Hungary
    Balance:
    1,113Coins
    Ratings:
    +82 / 0 / -0
    My Motion Simulator:
    6DOF
    It can be simtools settings. I configured the second sabertooth too, changed baud to 115200 using DEScribe, its the same. So something wrong with my simtuuls setup, but what? I checked everything several times.
    Why do motors move a bit, and every time they move exactly the same distance.
    Where can I change home midposition in simtools?

    Edit: I made a fresh install of simtools to another PC, It's the same, ...incredible :(
    Last edited: Jan 1, 2019
  18. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,119
    Location:
    Oklahoma City, USA
    Balance:
    15,579Coins
    Ratings:
    +1,797 / 31 / -1
    You can't. I still believe communication is the problem though. We know you are getting some communication with Simtools because SMC3-SPS uses a checksum. But it appears to be erratic and/or inconsistent which would explain why your motors are exhibiting erratic and inconsistent behavior.

    Btw, the checksum is between the Ard and Sabertooth so the motors won't move at all unless the Sabertooth receives a valid 4 byte command.
    • Agree Agree x 1
    Last edited: Jan 1, 2019
  19. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,119
    Location:
    Oklahoma City, USA
    Balance:
    15,579Coins
    Ratings:
    +1,797 / 31 / -1
    • Agree Agree x 1
  20. Gabor Pittner

    Gabor Pittner Active Member Gold Contributor

    Joined:
    Oct 25, 2018
    Messages:
    181
    Location:
    Szekesfehervar Hungary
    Balance:
    1,113Coins
    Ratings:
    +82 / 0 / -0
    My Motion Simulator:
    6DOF
    Could it be with sabertooth? As the tutorial says I have to change baud to 115200 on the new 2x32 sabertooth. But could it be something else to check or change?
    Its very strange that everything happens the same way on different sabertooth different arduino and a fresh simtools on a different PC.