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 Arduino code for 4DOF and 1 DIRpin Hbridge board

Discussion in 'DIY Motion Simulator Projects' started by RacingMat, Aug 7, 2013.

  1. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,158
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,176Coins
    Ratings:
    +2,159 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    Hi Mat,

    I tried to load your sketch but ran into this error:

    expected ')' before ',' token

    RacingMat_Sketch.ino: In function 'void motorMotion(int, int, int, int, int)':
    RacingMat_Sketch:177: error: expected `)' before ';' token
    RacingMat_Sketch:177: error: expected primary-expression before ')' token
    RacingMat_Sketch:177: error: expected `;' before ')' token
  2. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,234
    Location:
    Marseille - FRANCE
    Balance:
    20,894Coins
    Ratings:
    +2,084 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Oups, my mistake : it's corrected ! The updated code is on page 1.

    So you can now setup a (low) pwmMax to prevent too high current for your test !

    Have you finished your sleep ? Wake up ! :morecoffee:
  3. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,158
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,176Coins
    Ratings:
    +2,159 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    Thanks for the update Mat, I appreciate it!
  4. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,234
    Location:
    Marseille - FRANCE
    Balance:
    20,894Coins
    Ratings:
    +2,084 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Good !

    it has been also tested fine with Pololu 755 single Hbridge driver boards = 40 $ per motor
    5.5 to 30 V voltage range and is efficient enough to deliver a continuous 15 A without a heat sink.
    http://www.pololu.com/catalog/product/755

    0J1022.600.jpg

    0J1025.600.jpg
  5. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,158
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,176Coins
    Ratings:
    +2,159 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    Hi Mat, have you tested the chinese driver yet?
  6. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,234
    Location:
    Marseille - FRANCE
    Balance:
    20,894Coins
    Ratings:
    +2,084 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Arduino code for 4DOF and 1 PWMpin & 1 DIRpin Hbridge board

    Yes, both chinese and Pololu driver boards.

    In a previous message, maybe Eaorobbie intended to have a try but I don't know with what kind of board...
  7. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,158
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,176Coins
    Ratings:
    +2,159 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    What voltage are you putting through them? At what amperage?
  8. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,234
    Location:
    Marseille - FRANCE
    Balance:
    20,894Coins
    Ratings:
    +2,084 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    It was 24V and dunno intensity but low because no load...
    I can't tell you at the moment because I have dismantled the equipments as I'm working on another project ...
  9. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,158
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,176Coins
    Ratings:
    +2,159 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    Hey Mat, I have a question.

    When I connected my Pololu 755s to the Arduino, power, motors and pots the motors just spin at full power.

    Oddly, I found that if I manually move the pots back to center the motors act like the pots are controlling the speed and direction. The motors do not snap to the center of the pots (I assume they are supposed to right?).

    Is this something in the sketch? Shouldn't the arduino have them move to center and wait for input?

    I mounted my pots on slip tubes just in case the motors turned beyond their rotation limit, good idea that I did, lol.
  10. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,234
    Location:
    Marseille - FRANCE
    Balance:
    20,894Coins
    Ratings:
    +2,084 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Excellent ! you succeeded ! :clap:

    you just have to reverse your motor wiring ;D
    once correctly wired, the behaviour is the following :

    First : pot are not mounted onto the motor
    you can see the expected behaviour in this video
    http://www.youtube.com/watch?v=oFnLDR2xGgg
    and please find the explanation of the code here :

    The code is written to put the simulator on middle position at start :
    /* init position value*/
    int DataValueL=512; //middle position

    - if your pot is fully turned to max, as Arduino reads potentiometer value as motor position, Arduino believes that motor is in max position.
    - but the order is to be in middle position
    - so the Arduino will ask the motor to go reverse in order to go to middle position
    - your motor is turning
    - but while your pot keeps still, the motor will turn non stop !

    - when you manually turn the pot backward to min, Arduino reads that motor is in min position
    - but the order is still middle position, so Arduino will tell the motor to go forward
    - motor runs non stop until the pot is in middle position

    In the code, you have a tolerance parameter : when the pot is around middle position (<middle+tolerance and >middle-tolerance), the motor stops.
    You can broader Tolerance value to stop your motor more easily manually.

    Second : now checked the wiring
    Once you have played in this manner, now checked the wiring
    simulate the pot mounted onto the motor (back to back or alongside with gears...)
    reduce the speed (pwmMax) to see the direction of motor rotation
    and check if Arduino will behave as expected when you turn the pot

    if your pot is mounted this way :
    20130413154729-RacingMat-montage-potentiomy-tre-2-.JPG
    when you turn in a direction, motor has to go the opposite way.
    If not, invert motor wiring or pot wiring.

    Warning ! if you have gears between pot and motor, you'll have to twist your mind :eek: to check the correct behaviour.

    Third : mount the pot onto the motor, the behaviour will be the following :
    - motor goes to middle position and stop
    - if you send order to Arduino via Serial Monitor (say R7FLAE) the left motor will move and stop at his new position ! right motor didn't move.
    - etc...

    et voilà !
    Mathieu
  11. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,158
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,176Coins
    Ratings:
    +2,159 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    Excellent!

    It works! Well....sort of.

    Thanks to Mat for his instructions I have coordinated movement. I ran the output test, motors move according to the sliders. Also loaded Race07 and tested the motors, lots of movement on the motors, especially when I hit the wall....all too often.

    Unfortunately not all is good. I can only run the motors on 12v as the 15amp fuses pop with 24v. I am thinking of grabbing some 20amp fuses tomorrow and test with those.

    12v is far too weak to move my lard ass around; I can move the motors by hand when they are supposed to be holding in place. I did bolt on the connecting rods to see what it would do, they jerk around a bit but are not powerful enough to move the platform without me.

    Actually I doubt that 24v will do the trick either.

    On a bright note; my winches and JRKs will be here tomorrow or Thursday.

    Mat, again I want to thank you for all your hard work and dedicated help and most of all providing the Arduino sketch.
  12. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,234
    Location:
    Marseille - FRANCE
    Balance:
    20,894Coins
    Ratings:
    +2,084 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    You're welcome !

    For testing, you can install rFactor lite (250 Mo) and run it in IA mode : in a race, press i key and the IA will drive your car ! while you can adjust and fix hardware and software issues ! 8)

    What jrk did you buy ?
    Will you use them with arduino ?
  13. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,399Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    lol Jrk has its own micro controller in built mate.
  14. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,234
    Location:
    Marseille - FRANCE
    Balance:
    20,894Coins
    Ratings:
    +2,084 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Sure, but Jrk can be used with Arduino as well !
    IMHO, I do not like their calibration software, I prefer Arduino code...

    It's a matter of choice ! (try to add a LCD onto a JRK ! :mug1: )
  15. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,399Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Lol never had an issue with their software, set it and forget it. Just drive them.

    Ah lcd mmm custom VB App can be written but over 4 years never found the need for this.

    Ah yes you are correct they can be driven by the Ard using servo commands but this will only be at a 8bits resolution , see in sim tools we are using a 12bit resolution resulting in a lot nicer of control.

    When I first investigated and worked out how to run the Jrks I used a Serial Servo Controller from pololu and hooked the jrk to that. Sent uso commands to drive servos but again was 8 bit and the usb - serial converter was really touchy, which lead me to working out how to directly communicate with them in 12bit on usb.
    For beginners in Sims and electronics they have proven over the years to work well.

    I beg that you don't take in the wrong context, I congratulate you in completing a new motion driver for sims, now proven by another sim builder(well done) you now have a motion controller worthy of Sim use. Big +1 mate, and I feel a thanks from everyone is needed.
  16. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,234
    Location:
    Marseille - FRANCE
    Balance:
    20,894Coins
    Ratings:
    +2,084 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Thanks for the details, that sounds nice ! :thbup:

    you convinced me : I'll have a look on Jrk ! :yes:

    First I need to find a big friend ... in my hemisphere ! Historiker is too far ! ;-)
  17. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,158
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,176Coins
    Ratings:
    +2,159 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    I spent time in France, why do you think I am this big?! :D I miss the food, lol.

    By the way, your setup does indeed work with 24v, I replaced my 15 amp fuses with some 20amp types and now the motors seem to have plenty of power. Almost shook the entire rig apart, lol. I am using standard 270 degree pots, there is a huge amount of play in the center so they sling back and forth for about 10 degrees. It was a really bad idea to start up Race07 with the motion platform connected, lol. I thought it would jump from one edge of the shop to the other!

    I have not actually tried to sit on it yet, need to figure out how to significantly reduce the power and speed of the movements.

    I know I can reduce the motor movement by adjusting it from 255 down to 150 or so but I ran into an issue with the Arduino; I cannot change the sketch. Every time I try I get an error. After searching for the error it seems that the chip has issues where it will not talk to the PC except for rare occasions. :(

    Hopefully there is a way to reduce the speed in SimTools. I am looking at the axis assignments. I have already reduced them to 25%, should I go lower?

    Anyway...if I can get all of this set up I will keep the 24v motors on the race platform and start on the flight platform with the winches and JRKs.

    Thanks again Mat.
  18. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,234
    Location:
    Marseille - FRANCE
    Balance:
    20,894Coins
    Ratings:
    +2,084 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Thanks for this feedback !
    Oh ! Please prepare your cam, sit on your rig, and have a go at this full speed ! I'd really enjoy the video ! :rofl:

    Mat
    PS : I sent to you a PM
  19. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,158
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,176Coins
    Ratings:
    +2,159 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    lol, I dont think my health insurance will cover the result :D
  20. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,399Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    LOL yes I already had a mate put his neck out on mine, wont get back on , lol, his scared of it.
    My answer was Learn to drive, not bouncing off walls, lol
    Wicked very good to here its running on 24v now, impressed.
    Is there a way in code to slow accel and duty cycle of motors, see with the Jrks I run them at 100% (600)duty cycle and throttled back to 55% on Accel (350) so to calm the big worm gears down, if I don't , I can not hang onto the wheel and my vision goes blurry from the resulting motion. But at over 500mm/sec its expected.

    Be nice if users can select this in the Ard code, Overall duty cycle, max acceleration.