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

My 2DOF with stepper motors

Discussion in 'DIY Motion Simulator Projects' started by Lebois, Jun 28, 2019.

  1. cityparker

    cityparker Member

    Joined:
    Sep 14, 2020
    Messages:
    35
    Balance:
    125Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor
    Looks like a great project and its fantastic that you are sharing your stepper code! Big props!

  2. Trigen

    Trigen Active Member

    Joined:
    Nov 25, 2018
    Messages:
    484
    Balance:
    2,872Coins
    Ratings:
    +178 / 1 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino
    So would i :)
  3. dr.Evil

    dr.Evil New Member

    Joined:
    Aug 26, 2020
    Messages:
    15
    Balance:
    66Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    2DOF
    @Lebois ....any stepper motor could be a set up as a transducer.
    Did you use the same motors and the same drivers as in the first page? I mean, on your OP you said "Arduino sends pulse and dir signals to two HBS86h stepper drivers. I had a hard time trying to make them work. I learned a lot doing this project, but it also means that it took quite a long time... It's a closed loop driver. that means that an position encoder is fitted on the motor shaft and indicates to the driver where the motor is, and the driver can correct the position. " and to my question "the encoders are integrated into the stepper motors."

    Sorry for so many questions. I have a 2DOF rig that i bought from a bankrupt VR shop, it's working only on analogs inputs eg. turn of the steering wheel or accel/brake. it's made from quite good quality steppers and drivers. I need to make it work on the feedback from Simtools. You are the only soul that succeeded in making something similar.
  4. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    351
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,550Coins
    Ratings:
    +207 / 2 / -0
    My Motion Simulator:
    2DOF
    I already tried to wire the stepper motor encoder directly to the arduino. Problem is that the arduino needs to run extremely fast to read the encoder position while driving the motor at the same time. Or you need a great code... Everything is possible, but it was clearly simpler to use it the way I used it.

    My new stepper based actuators are almost ready. I can't describe the enjoyment they gave me. 3DOF is the way to go if you really want a good experience :)
    [​IMG]
  5. dr.Evil

    dr.Evil New Member

    Joined:
    Aug 26, 2020
    Messages:
    15
    Balance:
    66Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    2DOF
    @Lebois ....any stepper motor could be a set up as a transducer.
    did you use the same motors and the same drivers as in the first page? I mean, on your OP you said "Arduino sends pulse and dir signals to two HBS86h stepper drivers. I had a hard time trying to make them work. I learned a lot doing this project, but it also means that it took quite a long time... It's a closed loop driver. that means that an position encoder is fitted on the motor shaft and indicates to the driver where the motor is, and the driver can correct the position. " and to my question
    with no means of feedback other that the motors?
  6. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    351
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,550Coins
    Ratings:
    +207 / 2 / -0
    My Motion Simulator:
    2DOF
    yes, same motor and same driver. The feedback comes from the motor encoder, and is only sent to the driver.
  7. yellofella

    yellofella Member

    Joined:
    Aug 8, 2011
    Messages:
    94
    Occupation:
    builder
    Location:
    UK
    Balance:
    743Coins
    Ratings:
    +84 / 0 / -0
    My Motion Simulator:
    3DOF, SimforceGT
    Hi guys. You mentioned that you would like to see the code im using but i have not got the complete code to control all the motors finished yet as it is the project that i am currently working on so is a work in progress at the moment. As i build/expand and improve the project the code that it uses changes. Once the project is finished i will do a build log and post all the files on the site but i am a long way from that.
    @Lebois i looked up the datasheet for your driver and it does say that it has auto correction for missed steps. I did some testing with the hybrid stepper driver that i have and found it better than a standard driver for missed steps but it did loose its home point at high rpm with no acceleration ramping. The real problem and the main reason i abandoned the driver was that you cant change the micro stepping dynamically. You set it using dip switches on the side of the driver. This means you have a choice between full steps with massive cogging while trying to hold a position or using a high micro step value to stop the cogging but have low rpm output. I ordered some drv8825 drivers to test with as they are cheap and found that being able to change the step rate in the arduino code allowed full step high rpm and 1/32 micro steps to sit on the target exactly. I'm using a 4000cpr encoder on the 1.8 degree motor so need at least 1/20 microsteps to hold target without any cogging. This works well for small motors but i need more power than the little driver can deliver so now im using the pololu drv8711. This can drive the 4A that i need but is controlled using spi which has changed the code im using again and in no way suits your driver.
    You could give this a go though if you want to.
    To read the encoder on the arduino i use this example https://github.com/Saeterncj/QuadratureEncoder
    Install the library and connect your encoder to the arduino. For your encoder i would wire red to 5v through a 1k resistor, white to ground, blue to pin 2 and green to pin 3. Open the serial monitor and you should see the encoder count change when you turn the motor. It uses interrupts so will always catch the pulses.
    Your motors have a 1000ppr encoder on them with 2 encoder outputs (a & b). I assume that you should get 4000cpr in the serial monitor (4000 pulses per revolution as 1 quad encoder).
    So an example for you might be that you want 180 degrees or rotation at the final drive of your 5:1 gearbox for your rig. So 4000cpr x 5 / 2 = 10000 pulses for 180 degrees. If you set the simtools output to 13 bit you get an output of 0 - 8192. Read the value into the arduino via serial and this will be the target position. The encoder count will be the current position. Then do some simple integer math to calculate the difference between the two which i will call delta position for this example. I will use 1 arduino pin for the micro stepping to keep it simple. Something like this.

    if (delta_position < 500) {
    interval = map(delta_position, 0, 499, speedMin, speedMax); // speedmin 2000 - speedmax 600
    }
    else {
    interval = speedMax;
    }
    if (target_pos < current_pos) {
    delta_position = current_pos - target_pos;
    digitalWrite(dirPin, HIGH); // Set the spinning direction CCW
    servoStep();
    }
    else if (target_pos > current_pos) {
    delta_position = target_pos - current_pos;
    digitalWrite(dirPin, LOW); // Set the spinning direction CCW
    servoStep();
    }
    }
    void servoStep() {
    if (delta_position < 20) {
    digitalWrite(microStepPin, HIGH); //1/32 step
    }
    else {
    digitalWrite(microStepPin, LOW); //full step
    }

    if (micros() - previous_micros >= interval) {
    previous_micros = micros();
    if (step_state == LOW) {
    step_state = HIGH;
    } else {
    step_state = LOW;
    }
    digitalWrite(stepPin, !digitalRead(stepPin));
    }
    }
    You could count the pulses from the encoder, control the stepping and use the other two interrupts for limit switches to setup a home position all on 1 arduino. Then use a second arduino with the same setup for motor two and a third for motor 3. I guess that would be the simplest way but i cant do this for six motors as simtools has a limit of 3 interfaces i think so im using a fast controller as a master to interface all six motor drivers and encoder counters via spi.
    Not sure if this helps guys as its not the code that im using now but gives you the idea. You would have to modify the code for you particular driver input as this example uses 1 step and direction pins. It will move the motors at full speed until it is 24 steps from the target then ramp the speed down in full step mode the closer it gets to the target then switches to 1/32 microsteping when 1 full step from the target. If you manually force the motor out of position or it stalls it will always try to return to the target set by sim tools.
    • Like Like x 2
    • Informative Informative x 1
  8. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    351
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,550Coins
    Ratings:
    +207 / 2 / -0
    My Motion Simulator:
    2DOF
    "The real problem and the main reason i abandoned the driver was that you cant change the micro stepping dynamically" Yes, it can be a big improvement !
    Your explanation is clear, thank you !
    I will think about it, and try it later. For the moment, I will focus on releasing the first version of this actuators.
  9. dr.Evil

    dr.Evil New Member

    Joined:
    Aug 26, 2020
    Messages:
    15
    Balance:
    66Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    2DOF
    Good advice, I'll try it as soon as I get free.
  10. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    351
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,550Coins
    Ratings:
    +207 / 2 / -0
    My Motion Simulator:
    2DOF
    Now it's 3DOF.
    • Friendly Friendly x 1
  11. Arta Yasa

    Arta Yasa Member

    Joined:
    Jan 27, 2021
    Messages:
    159
    Balance:
    788Coins
    Ratings:
    +14 / 0 / -0
    My Motion Simulator:
    2DOF
    Hi sit for srx100 actuactor posible to use stepper motor?? Like nema 23 or 34? Or ac servo 100 until 400 watt?
  12. zhai1987

    zhai1987 Member

    Joined:
    Sep 7, 2021
    Messages:
    96
    Balance:
    320Coins
    Ratings:
    +11 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, AC motor
    Brother, will the project be updated? Look forward to it!
  13. Lebois

    Lebois (maybe I am wrong, but who knows...)

    Joined:
    Dec 10, 2018
    Messages:
    351
    Occupation:
    Math teacher
    Location:
    France
    Balance:
    2,550Coins
    Ratings:
    +207 / 2 / -0
    My Motion Simulator:
    2DOF
    Nop I won't work on this version. But you could be able to merge the two code easily.
  14. Alakey9

    Alakey9 New Member

    Joined:
    May 14, 2021
    Messages:
    5
    Location:
    Казахстан
    Balance:
    - 203Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino, 4DOF, 6DOF
    I have the same nema32 motors and the same driver, I assembled your circuit, connected the display, writes data reading and nothing more happens, nothing happens in simtools either, help me what I'm missing, sorry for my English translator
  15. Alakey9

    Alakey9 New Member

    Joined:
    May 14, 2021
    Messages:
    5
    Location:
    Казахстан
    Balance:
    - 203Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, Arduino, 4DOF, 6DOF
    Sorry nema34