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

New XPID software for Arduino UNO/Mega and Sabertooth (with LCD !!)

Discussion in 'SimTools compatible interfaces' started by vthinsel, Apr 1, 2015.

  1. bsft

    bsft

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Or just use JRKS
  2. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    5,986Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Here is v3.12
    Changelog:
    Version 3.12
    ------------
    * Updates:
    - Changing pot min/max and standby value using LCD makes the motors move to the new position for 3 seconds to test the value.
    - LCD refresh every 100ms : more readable, less CPU usage for LCD = more CPU available for XPID calculation.
    - removed FASTADC trick : better conversion with much less noise. As a consequence, no need to read n times and make an average when using FASTADC.


    As a bonus, here is Project Cars, with gamedash, and XPID 3.12

    Attached Files:

  3. Wanegain

    Wanegain Active Member

    Joined:
    Nov 6, 2013
    Messages:
    571
    Location:
    Bruxelles
    Balance:
    1,947Coins
    Ratings:
    +297 / 2 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    Very nice project !

    I used your code to set a lot of similar features for a 4 dof. This is very useful !!

    Than you for sharing :)
  4. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    5,986Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    You welcome :)
    Maybe one day I'll build a 4DOF. Meanwhile my 2DOF is still under construction... :(
    • Like Like x 1
  5. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    5,986Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Hello,

    I have done some big refactoring of the code and optimized the behavior. The code is now much more readable as I'm now using a class which gets instantiated for each motor. As a consequence, no more need to declare tons of varaiables in the main code.

    Before:
    double K_motor_1 = 0;
    double proportional1 = 0;
    double integral1 = 0;
    double derivative1 = 0;
    double K_motor_2 = 0;
    double proportional2 = 0;
    double integral2 = 0;
    double derivative2 = 0;

    double integrated_motor_1_error = 0;
    double integrated_motor_2_error = 0;
    float last_motor_1_error = 0;
    float last_motor_2_error = 0;

    int Motor1STDBY = 0;
    int Motor2STDBY = 0;
    .....


    Now:
    XPIDDCMotor M1;
    XPIDDCMotor M2;


    Much easier, especially if you want to add new motors, for a 6DOF for example :)
    The class holds all variables (private) related to the motors, and public functions to get/set those.
    public:
    XPIDDCMotor();
    int PIDUpdate();
    void setK(double K);
    void setP(double P);
    void setI(double I);
    void setD(double D);
    void setTarget(int target);
    void setCurrent(int current);
    void setStandby(int standby);
    void setDeadZone(int val);
    void setMin(int val);
    void setMax(int val);
    double getK();
    double getP();
    double getI();
    double getD();
    int getTarget();
    int getCurrent();
    int getStandby();
    int getPower();
    int getDeadzone();
    int getMin();
    int getMax();


    I also optimized the PID calculation which was split across 2 procedures. The PID calculation is part of the class
    The code generated is now smaller (even when changing the optimizer to optimize for speed)
    a few bugs have also been corrected as well.

    Maybe i'll turn this in a standalone lib someday when I have time to fill the gaps (documentation, examples,....)

    No regression found so far in the tests.

    Attached Files:

    • Like Like x 2
    • Useful Useful x 1
  6. Wanegain

    Wanegain Active Member

    Joined:
    Nov 6, 2013
    Messages:
    571
    Location:
    Bruxelles
    Balance:
    1,947Coins
    Ratings:
    +297 / 2 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    Very clever !
    I'll read it. Thank you for sharing :)
    • Agree Agree x 1
  7. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    5,986Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Oups. I noticed the serial port in case of arduino mega is not correct. Check line 104/105 to move debug onto serial2.
    Sorry
  8. Pit

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

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,416Coins
    Ratings:
    +3,088 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    Hi @vthinsel how's your rig going? :) BTW I will get the Sabertooth 2x32 the next days and I will try out your fantastic code as well. I do not need any flip switches because I have an automatic shut down solution (if the motor crosses a certain point on the rail, then the motors will shut down caused by flip switches on the 220V line). So my question would be the combo works without the switches also? At the moment I have no LCD screen, I will it add later if necessary.
  9. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    5,986Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Well, it is in standby : I use it as a static one for now. I need to pick-up some metal bars to finish it. My target is to finish it for XMas as my own present :p
    Meanwhile, I'm playing with a 2"8 touchscreen (well, I try to....)
    To go back to your question , no need to put the flip switches. The internal pull-up is activated so if you do not wire them to GND through a switch they will stay high which is the normal way (LCD on, regular bahavior). If you do not put the LCD, you will have issues to configure the variables.
    Let me know if you face any issues.
  10. Wanegain

    Wanegain Active Member

    Joined:
    Nov 6, 2013
    Messages:
    571
    Location:
    Bruxelles
    Balance:
    1,947Coins
    Ratings:
    +297 / 2 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    I highly recommend you the lcd shield, for troubleshooting it's very useful !
  11. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    5,986Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Agreed, it is useful. But now I also debug a lot with visual studio + visual micro plugin. I'll probably make a small tutorial one of these days.
  12. Pit

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

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,416Coins
    Ratings:
    +3,088 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    ordered...
  13. Wanegain

    Wanegain Active Member

    Joined:
    Nov 6, 2013
    Messages:
    571
    Location:
    Bruxelles
    Balance:
    1,947Coins
    Ratings:
    +297 / 2 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 4DOF
    So fast :eek: but good choice ;)
  14. vthinsel

    vthinsel Well-Known Member

    Joined:
    Feb 20, 2015
    Messages:
    439
    Location:
    FRANCE
    Balance:
    5,986Coins
    Ratings:
    +564 / 2 / -0
    My Motion Simulator:
    Arduino, 4DOF
    Eheh... when (if) I release a 2"8 touchscrren version you will have to place another order :grin
    I was afraid the touchscreen display would take a lot more cycles than the LCD, but it doesn't seem to be true thanks to the processing done by the touchscreen itself. I'll make some benchmark anyway to make sure it is a viable alternative (also the display can be shut down using the famous switch you do not plan to wire....). A graphical touchscreen is quite eye-candy I agree, but well......
  15. Pit

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

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,416Coins
    Ratings:
    +3,088 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    lol, never mind, the LCD is only 10 bucks. Anyway I appreciate your next release. :)
  16. Pit

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

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,416Coins
    Ratings:
    +3,088 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    hmm, i have the MEGA, since today the Sabertooth but no LCD :-/ . The closest home country dealer delivers later than the dealers from north Europe :)
  17. Pit

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

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,416Coins
    Ratings:
    +3,088 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    Hi, today I got the LCD so I began to put all together. I am using the Dip Switches advises from @Wanegain, 2, 4 and5 are off - this is correct?
    Like to be expected I was running into troubles ;), I have recorded a short video which hopefully tells more than 1000 words...
    Thank you in advance for clearing out the issue showed by the video.

    PS: the quality of the video is bad (forgot to set the better resolution), if you need a better quality please ask. Thanks.
  18. Pit

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

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,416Coins
    Ratings:
    +3,088 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    First issue solved - switches are off off on on on on. Now all seems to be OK, SimTools tested successfully, but I have no power on the outputs, even the diagnostic says 0%.
  19. Pit

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

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,416Coins
    Ratings:
    +3,088 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    Problem solved - I have to upload the settings FIRST to the device, because you @vthinsel did that already you missed the step while making the video ;)
  20. Pit

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

    Joined:
    Oct 2, 2013
    Messages:
    3,013
    Location:
    Switzerland
    Balance:
    30,416Coins
    Ratings:
    +3,088 / 31 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    OK, I add the following information for beginners:
    1. The Dip switches have to be set off off on on on on
    2. the Sabertooth has to be connected to the PC (USB)
    3. The software DEscribe" has do be started
    4. the Sabertooth has to be configured showing in the video, then the settings have to be uploaded to the device. If you want, you can save the settings to a file separately on disk.
    5. The Sabertooth must be powered by a PSU for testing the correct outputs using a multimeter.
    6. The Sabertooth has not to be connected to the Ard on the 5V line.
    7. ?
    Thank you @Wanegain and especially @vthinsel for this code - now the tests can begin. I have to start carefully so to do so IMO i have to limit the power output f.eg. to 2V or there are more limitations for the first test which I can use with?
    • Informative Informative x 1