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 SMC3 Arduino 3DOF Motor Driver and Windows Utilities

Discussion in 'SimTools compatible interfaces' started by RufusDufus, Dec 1, 2013.

  1. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    251
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    989Coins
    Ratings:
    +147 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    hi @RufusDufus , i have a question ! :D
    I work on a new g-seat and i hooked up my hall effect potmeter directely on the motor's shaft, that's mean i get an angular measure but i wish having a linear measure, then i add a formula into the loop process of your code to convert angular-to-linear and it works but i wonder if i have to change the data type of the "Feedback1" because i use cosine in radian ? :sos

    **
    if (PIDProcessCounter >= PIDProcessDivider)
    {
    PIDProcessCounter=0;

    // Check and Update Motor 1 drive

    Feedback1 = analogRead(FeedbackPin1);
    Feedback1 = 512-(512*cos(Feedback1/325.9495)); <---------------------------------------------o_O
    if ((Feedback1 > CutoffLimitMax1) || (Feedback1 < CutoffLimitMin1)) { DisableMotor1(); }
    PWMout1=CalcMotor1PID(Target1,Feedback1);
    if (Disable1==0)
    {
    SetOutputsMotor1();
    }
    else
    {
    PWMout1=0;
    }


    and i wonder too , if i add a formula like this , if I can disrupt something , synchro, timing ....?
    Eric :cool:
    • Like Like x 1
    Last edited: Aug 3, 2014
  2. RufusDufus

    RufusDufus Well-Known Member

    Joined:
    Jul 21, 2013
    Messages:
    681
    Location:
    Adelaide Australia
    Balance:
    15,896Coins
    Ratings:
    +1,016 / 10 / -1
    Hi Eric,

    The main issue in doing this is that you will need to use floating point arithmetic for the calculation and that together with the fact Cosine calulations take alot of processor cycles it will most likely have a significant effect on the maximum number of PID calculations that can be performed per second. I expect it will overrun the period timer and just calculate PID updates whenever the loop gets finished rather than on regular timed periods.

    That being said, that would be the right place to do the calculation. I take it you are trying to compensate for the angular motion of the lever arm so the seat moves a linear distance for a given movement in linear target. Not sure the formula is correct - I think it should be sin?

    That aside, I don't really think you will get a noticeable benefit from doing this... Look at the chart below that shows a comparison of the movement resulting from the angular motion compared to an equivalant linear motion. You can see that the majority of the levers end point motion is "close" to linear anyway. Its only the last 17% of travel at each end that starts to deviate significantly. When you in these areas of the travel you would typically be simulating fairly large vehicle motion anyway and in my opinion you won't "perceive" a great difference anyway.

    LinearMotion.JPG
    In fact in my latest version of SMC3 (which reminds me I need to release it) I actually have implemented a POT input that the user can use for adjusting/scaling motion. The scaling approach I have adopted in a non linear approach which compresses the largest travel but keeps the smaller travels largely unchanged. So at the end of the day I guess as always it comes down to what individuals feel right.

    You may have noticed in my MRAP simulator I use rope and pulleys that result in linear motion... This was done more so to allow greater travel distances with minimum load on the motors - not really to compensate for the non-linear travel (even though it does that also). The result is a 250mm travel with a 40mm pulley (equiv to a 20mm level from a motor load point of view). That is one of the main reasons I get away with one single cheap power supply to power the whole sim.

    Hope that helps.
    • Like Like x 2
  3. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    251
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    989Coins
    Ratings:
    +147 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    Hi RufusDufus ,
    ***The main issue in doing this is that you will need to use floating point arithmetic for the calculation and that together with the fact Cosine calulations take alot of processor cycles it will most likely have a significant effect on the maximum number of PID calculations that can be performed per second. I expect it will overrun the period timer and just calculate PID updates whenever the loop gets finished rather than on regular timed periods.***

    This is the kind of problem that I was afraid to create.:eek:

    LinearMotion.JPG

    The problem I see is when I have 2 -3 or more combined force. The first force is reproduced in the "B"section most often and sometimes it can be found in the "A"section (heave+sway) or (sway+heave). Depending on which comes first. I found it a little contraingnant .

    Rope / pulley is a good solution for eliminating this little problem...:thumbs

    Anyway, yesterday i tested my motor alone (not in a combined manner) and i have been impressed and satisfied of the result. In my new build i will have need the angular measurement :think

    Sorry for the inconvenience

    thank you for your fast reply and clean explication. :thumbs
    Eric :cool:
    • Like Like x 1
  4. ferslash

    ferslash Active Member

    Joined:
    Feb 8, 2011
    Messages:
    495
    Balance:
    4,798Coins
    Ratings:
    +181 / 2 / -0
    guys this is my first arduino and rufus code intent... it is 4:00 am and i dont figure out how to tell my motors not to e spin out of countrol... i remmember that in the past i played with a jrk and in some point i told the jrk which whas the top possition and the lower position of my wipers... how do i do this using arduino and the rufus code?

    i was playing with the windows smc3 utility, but i dont know how to do this

    can some one help me plese :D

    fer from mexico
    • Like Like x 1
  5. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    251
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    989Coins
    Ratings:
    +147 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    hi,

    @ferslash , With SMC3 you can't adjust the max/min independently.
    but if you move your motor and/or your potmeter manualy you will see the max and min with SMC3utlis.
    With the "clip" option of the SMC3utlis (refer to the first page) you will adjust it before the max for protecting your motor (hard brake)
    and the max limit will stop the motor...

    these options will be saved automatically in the Arduino !
    • Like Like x 2
    Last edited: Aug 12, 2014
  6. RufusDufus

    RufusDufus Well-Known Member

    Joined:
    Jul 21, 2013
    Messages:
    681
    Location:
    Adelaide Australia
    Balance:
    15,896Coins
    Ratings:
    +1,016 / 10 / -1
    Hi Eric, if you do want to proceed with this try to work out a way of doing the angular conversion with integer math rather than float (sine/cosine) formula - integer math is much more efficient in these type of micros. You could maybe use a pre-calculated lookup table if there is enough code space, or perhaps break the calculation into regions and use a linear approximation for each region.
    • Winner Winner x 1
    • Informative Informative x 1
  7. RufusDufus

    RufusDufus Well-Known Member

    Joined:
    Jul 21, 2013
    Messages:
    681
    Location:
    Adelaide Australia
    Balance:
    15,896Coins
    Ratings:
    +1,016 / 10 / -1
    Hi, Not quite sure what you mean by "the motors spin out of control" - do they never stop spinning or just move further than you want?

    As per Eric's response, use the "clip input" and "max limit" settings in SMCUtils to setup how far the motors can move.

    Remember though if the feedback pots are not "mechanically" connected to the motors they will act more like motor speed controllers - the closer the pot position is to the target position the slower the motor and the further away the faster the motor is, when exactly on target the motor will stop.
    • Informative Informative x 1
  8. ferslash

    ferslash Active Member

    Joined:
    Feb 8, 2011
    Messages:
    495
    Balance:
    4,798Coins
    Ratings:
    +181 / 2 / -0
    @RufusDufus "Hi, Not quite sure what you mean by "the motors spin out of control" - do they never stop spinning or just move further than you want?"

    - at first the motors connected to the pots where spinning, when i used the square or rectangle function the motors where freely spinning they never stopped to get back to a position, then..

    -Using the post that @ericRacer gave me, i moved the pots and then the motors where spinning to a position and brake to get back to a position, the thing now is that the motor are going from position a to position b, (good stuff) but this positions are not the top and bottom positions... using the clip button i can set the bottom position, and then the top position is "automatic" in the graphic but it is not the motor top position, it is just the middle position of the motor.

    should i let them this way or is there something to do...?

    on the other hand... it could be a grate feature for SMC3 Windows Utilities, that the user could "move" the feedback (pots) position by the software insted of moving the pots physically.
    or even a "set position button" the jrk utilities make this by asking you to manually move the motor to the top position and save the pot position, then you have to move manually the motor to the bottom position and again save the pot position and you are set. (i dont know how hard could make this to the sm3. (i understand that coding would be a headache :( )

    thanks for sharing this grate soft.

    best regards fer
    • Friendly Friendly x 1
    Last edited: Aug 11, 2014
  9. hooshang

    hooshang Active Member

    Joined:
    Jul 6, 2011
    Messages:
    273
    Balance:
    285Coins
    Ratings:
    +157 / 3 / -0
    My Motion Simulator:
    2DOF, DC motor, AC motor, Arduino, 6DOF
    Hi @RufusDufus
    as you know I setup smc3 with 2 Ard for my 6dof rig.
    everything work smooth except a little problem with both Arduino in 3rd motors that there is a stop point for a fraction of second at the middle of their teavel ,what is it for and how can I solve this?
    thank you in advance
    regards
    Hooshang
    • Like Like x 1
  10. RufusDufus

    RufusDufus Well-Known Member

    Joined:
    Jul 21, 2013
    Messages:
    681
    Location:
    Adelaide Australia
    Balance:
    15,896Coins
    Ratings:
    +1,016 / 10 / -1
    The signals from SMC3Utils only drive the motors about 50% of full feedback travel. They are really just for checking the motion tracking not the range of travel. Perhaps a future version can change this.

    You can put it in manual mode and use the slider (little blue circle) on the right of the chart to test your travel range, just manually move the slider to where ever you want.[/user]
  11. RufusDufus

    RufusDufus Well-Known Member

    Joined:
    Jul 21, 2013
    Messages:
    681
    Location:
    Adelaide Australia
    Balance:
    15,896Coins
    Ratings:
    +1,016 / 10 / -1
    Hi hooshang, I hadn't noticed this, I'll have a closer look when I have some time and get back to you.

    Check your deadzones are the same for all motors though.
    • Like Like x 1
  12. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    251
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    989Coins
    Ratings:
    +147 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    ok, thanks for the tips :)
    • Like Like x 1
  13. hooshang

    hooshang Active Member

    Joined:
    Jul 6, 2011
    Messages:
    273
    Balance:
    285Coins
    Ratings:
    +157 / 3 / -0
    My Motion Simulator:
    2DOF, DC motor, AC motor, Arduino, 6DOF
    @RufusDufus
    thank you for replay ,all parameters in smc3util are the same except Fpwm that for motors 1 & 2
    is 30khz and for 3rd is 31 khz
    • Like Like x 1
  14. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    251
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    989Coins
    Ratings:
    +147 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform
    Is that your problem only happens when you use two Arduinos or the same thing happens if you use only one Arduino ?

    I am going to use 3 motors soon, and i am curious to know.
    • Like Like x 1
  15. hooshang

    hooshang Active Member

    Joined:
    Jul 6, 2011
    Messages:
    273
    Balance:
    285Coins
    Ratings:
    +157 / 3 / -0
    My Motion Simulator:
    2DOF, DC motor, AC motor, Arduino, 6DOF
    Hi @ericRacer
    it happened for both and I just never used smc3 3rd motor for a single Ard:p.
    but just a little wait,cause I changed my power supply and get better result
    ill tell you the news later
    regards
    Hooshang
    • Like Like x 1
  16. SilentChill

    SilentChill Problem Maker

    Joined:
    Jul 19, 2014
    Messages:
    2,643
    Occupation:
    Railway Maintenance
    Location:
    Morecambe, Lancashire, England
    Balance:
    20,557Coins
    Ratings:
    +3,487 / 34 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    I'm using your code @RufusDufus and I have had no problems at all, really good piece of work.

    Thanks for your time and effort :)
    • Like Like x 1
  17. hooshang

    hooshang Active Member

    Joined:
    Jul 6, 2011
    Messages:
    273
    Balance:
    285Coins
    Ratings:
    +157 / 3 / -0
    My Motion Simulator:
    2DOF, DC motor, AC motor, Arduino, 6DOF
    • Like Like x 1
  18. ferslash

    ferslash Active Member

    Joined:
    Feb 8, 2011
    Messages:
    495
    Balance:
    4,798Coins
    Ratings:
    +181 / 2 / -0
    guys, i am having a bad time setting the pots position in winutilities... any advice? i can see the feedback line in the graphic, if i use some of the waves (triangular or square) where should i place the feedback line? any trick any advice?

    fer
    • Like Like x 1
  19. ericRacer

    ericRacer You get old because you stop playing ! Gold Contributor

    Joined:
    Jun 11, 2009
    Messages:
    251
    Occupation:
    Pilot
    Location:
    Canada, Quebec
    Balance:
    989Coins
    Ratings:
    +147 / 2 / -0
    My Motion Simulator:
    3DOF, Arduino, Motion platform

    Hi @ferslash ,

    You can't adjust the feedback line in the graphic, the SMC3utlis help you to see how your pots is adjusted to the Arm /motor.
    I mean, the feedback is always in the middle (1024/2=512 or 0-5v./2=2.5v) you must adapt (fit) the pots travel with these numbers.
    When your Arm/motor is in the middle position , you must adjust manuelly the pots in the middle of his travel too (here the travel of the pots = the travel of the Arm/motor)

    hope this helps !
    • Like Like x 1
  20. ferslash

    ferslash Active Member

    Joined:
    Feb 8, 2011
    Messages:
    495
    Balance:
    4,798Coins
    Ratings:
    +181 / 2 / -0
    sure it will my dear Erick :D i will try it today :D:D:D
    • Like Like x 1
    • Informative Informative x 1