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. Attyla.pl

    Attyla.pl Active Member

    Joined:
    Oct 1, 2023
    Messages:
    163
    Location:
    Polska
    Balance:
    660Coins
    Ratings:
    +46 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    AS5600 has an operating voltage of 3.3V and from the arduino you get 5V it has no right to work.
    MT6701 has an operating voltage of 3.3-5V so theoretically it should work , but first of all it requires some kind of magnet mounted on the pinion whose field is to measure , in addition it has a number of inputs I do not know if the analog output is active standard or it requires some programming of the sensor .
    https://www.skytech.ir/DownLoad/File/4471_5001592712907.pdf

    In general, at the beginning you can safely use ordinary potentiometers 10KOhm
    https://www.youtube.com/@DMAX_DIY
  2. Gefahren

    Gefahren Member

    Joined:
    Mar 9, 2024
    Messages:
    55
    Occupation:
    Electronics Engineer
    Location:
    Central Mississippi, USA
    Balance:
    395Coins
    Ratings:
    +66 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    ordanssela I use the AS5600 chips. All the ones I've seen on Amazon and such are configured for I2C and not analog out. For most of them it is resistor R4 that needs to be removed to enable the analog output. The ones like what I have will work off of either 3.3V or 5V without any modification, but will need to be powered off of 5V to give the correct analog output for the Arduino.
    Screenshot 2024-07-29 205151.png

    Attyla.pl there is no real problem with the SMC3 code, it does a lot of good things. If your motion simulator motors only need a Proportional control, then everything is good. If your motors need all the extra control that a full PID loop will give, then look at one of the other versions of SMC3 that people have done since several seem to have 'fixed' the code errors.
    If your motors have lots of natural dampening (from driving a high ratio gearbox for example) then just a proportional control should be fine. If they tend to overshoot or can be back driven easily then you probably want the better control.
  3. Attyla.pl

    Attyla.pl Active Member

    Joined:
    Oct 1, 2023
    Messages:
    163
    Location:
    Polska
    Balance:
    660Coins
    Ratings:
    +46 / 0 / -0
    My Motion Simulator:
    2DOF, Arduino
    Gefahren, thank you for your reply which I think explains a bit my problems with controlling the motor with the IBT-2 bridge , when moving fast the motor overshoot of position. Interestingly this problem disappeared after replacing the controller with 100A motor controllers.
    As for changing the SMC3 code I will try but it will be hard since I am completely unfamiliar with it :).
  4. Gefahren

    Gefahren Member

    Joined:
    Mar 9, 2024
    Messages:
    55
    Occupation:
    Electronics Engineer
    Location:
    Central Mississippi, USA
    Balance:
    395Coins
    Ratings:
    +66 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    • Like Like x 1
    • Useful Useful x 1
  5. ordanssela

    ordanssela New Member

    Joined:
    Jul 17, 2023
    Messages:
    4
    Balance:
    - 58Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, SimforceGT, Motion platform
    Gefahren, Attyla.pl Thanks for responding, I'm dying to test the magnetic sensors, you guys are awesome.
  6. Gefahren

    Gefahren Member

    Joined:
    Mar 9, 2024
    Messages:
    55
    Occupation:
    Electronics Engineer
    Location:
    Central Mississippi, USA
    Balance:
    395Coins
    Ratings:
    +66 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    Wow, I feel like a complete idiot right now, but I will publicly admit that I was wrong.

    I completely missed that inside the PID calculations of SMC3 the variables are declared 'static' which means they retain their value between function calls and do not get reset every time. That means what I said was wrong with The CalcMotor1PID function is untrue. It is working as it should.

    CalcMotor2PID and CalcMotor3PID still have those two extra lines that mess up the derivative calculation to always be zero. Also, CalcMotor3PID still has the bit shifts that reduces the effect of the Integral Term and would increase the effect of the Derivative Term if it wasn't always zero.

    So, I feel that my foot has been inserted as far in my mouth as I can get it, and I apologize for being even partially wrong.
    • Informative Informative x 2
    • Like Like x 1
    • Friendly Friendly x 1
  7. lihao

    lihao New Member

    Joined:
    Jul 30, 2024
    Messages:
    4
    Balance:
    - 52Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    3DOF
    Hello, I had a strange problem when I was making it. My smc3 until and simtools initial positions are not the same. My build uses two motors that extend about 30 degrees out in the starting position. The picture is of my smc3 until the initial position, then when I open simtools, both motors will automatically deflect about 30 degrees, and there will be this mutation every time when running through 0 and 1 of the axis.
    Due to forum rules I can't send pictures, so I can only describe my problem in as much detail as possible.
    In the smc3until program, both of my motors run normally and smoothly, but when the axis of simtools passes through 0 and 1, there will always be a sudden change, automatically rotating through a range of 30 degrees.
    I can't send pictures due to forum rules, so I'll just try to describe my problem in as much detail as possible.
    In the smc3until program, both of my motors ran normally and smoothly, but there was always a sudden change when the axis of simtools passed 0 and 1, automatically turning the range of 30 degrees.
    Last edited by a moderator: Aug 23, 2024
  8. lihao

    lihao New Member

    Joined:
    Jul 30, 2024
    Messages:
    4
    Balance:
    - 52Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    3DOF
    Oh, it looks like I can send pictures, the first is my smc3until initial position and the second is my simtools initial position.

    Attached Files:

    Last edited by a moderator: Aug 23, 2024
  9. lihao

    lihao New Member

    Joined:
    Jul 30, 2024
    Messages:
    4
    Balance:
    - 52Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    3DOF
    Presumably due to some problems with Google Translate, I have to re-send the translated text。
    Hello, I had a strange problem during production, my smc3 was not in the same initial position as simtools. My fabrication used two motors that were extended about 30 degrees from the starting position. The picture is my smc3 up to the initial position, and then when I turn on simtools, both motors automatically deflect by about 30 degrees, with this mutation every time they pass the 0 and 1 of the axis while running.

    In the smc3until program, both of my motors ran normally and smoothly, but there was always a sudden change when the axis of simtools passed 0 and 1, automatically turning the range of 30 degrees.
  10. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,094
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,246Coins
    Ratings:
    +10,892 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Can you please post pictures of all your SMC3 settings, and your SimTools settings.

    Does SMC3 work as expected? Could you please post a picture of the SMC3 Sine Wave test running.
  11. lihao

    lihao New Member

    Joined:
    Jul 30, 2024
    Messages:
    4
    Balance:
    - 52Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    3DOF
    Hello, my problem has been solved today. I have done two things, one is to update the simtools software and plug the interface tightly. After that, the initial position of simtools and smc3until is the same. Because I did both things at the same time and then tested them, I don't know what the problem is, but it has been solved.:grin
    • Winner Winner x 2
  12. ordanssela

    ordanssela New Member

    Joined:
    Jul 17, 2023
    Messages:
    4
    Balance:
    - 58Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, SimforceGT, Motion platform
    I don't know much about programming, I wanted to control the position of a homemade servo motor using a potentiometer, I'm using a BTS 7960 and an Arduino R3, could someone edit the code. Thank you all in advance, this is the code
    //pins
    int ENA = 2; // enable pin
    int pwm[2] = {5, 6}; // motor driver pwm pins
    int encoder = A0; // encoder pin

    //constants
    float offset = 0;
    String input;

    void setup() {
    pinMode(ENA, OUTPUT);
    Serial.begin(115200);
    }

    void loop() {
    //moveTo(60);
    //Serial.println(getPos());
    //inputPos();
    }

    float moveTo(float setpoint){ // moves the servo to an input position
    float error, out;

    float CW_error = setpoint - getPos(); //calculates the error if moving CW
    if(CW_error < 0){ //if CW_error is less than 0
    CW_error = CW_error+360;
    }
    float CCW_error = getPos()-setpoint; //calculates the error if moving CCW
    if(CCW_error < 0){ //if CCW_error is less than 0
    CCW_error = CCW_error+360;
    }

    // if CW_error is smaller than CCW_error (or both are equal) then error should be CW_error
    if(CW_error < CCW_error || CW_error == CCW_error){
    error = CW_error;
    }

    // if CCW_error is smaller then CW_error then make error CCW_error
    else if(CCW_error < CW_error){
    error = -1*CCW_error; //makes error negative
    }

    out = 12*error;
    out = constrain(out, -255, 255); //constrains output to have maximum magnitude of 255
    if(abs(out) < 25){ //if output is less than 25 make it 0
    out = 0;
    }
    digitalWrite(ENA, HIGH); //sets enable pin HIGH
    if(out > 0){ //if output is positive move CW
    analogWrite(pwm[0], 0);
    analogWrite(pwm[1], out);
    }
    else if(out < 0){ //if output is negative move CCW
    analogWrite(pwm[0], abs(out));
    analogWrite(pwm[1], 0);
    }
    else if(out == 0){
    analogWrite(pwm[0], 0);
    analogWrite(pwm[1], 0);
    }
    }

    float getPos(){ // gets and returns encoder position
    // gets raw 10 bit position from the encoder and maps it to angle value
    // adds offset value
    float pos = map(analogRead(encoder), 0, 1023, 0, 359) + offset;

    //corrects position if needed
    if (pos < 0) {
    pos = 359 + pos;
    }

    else if (pos > 359) {
    pos = pos - 359;
    }

    return pos;
    }

    void inputPos(){ // moves servo to the position typed in the serial monitor
    if (Serial.available() > 0) { // is a character available?
    input = Serial.readString();
    }
    moveTo(input.toInt());
    Serial.println(getPos());
    }
  13. Ronan Design

    Ronan Design Roman Design - Custom MSFS Scenery

    Joined:
    Jun 4, 2021
    Messages:
    193
    Occupation:
    Web Designer, MSFS Scenery Designer
    Location:
    Toronto, Canada
    Balance:
    1,311Coins
    Ratings:
    +71 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    What if there are 3 Arduino SMC boards in a 6DOF rig? If there's a runaway, SMC will stop the motors, but because 3 independent instances of SMC are not aware of each other, 4 other motors will still be working and powered. Which means the 6DOF platform will try to tear itself apart, as 2 stopped motors will go out of the virtual plane that all motors are supposed to stay in. Is there a way to shut everything down across all 3 boards? It would be a good solution to add some code that transmits a signal to a pin and stops motors when receiving a signal on a pin. That way all boards could be connected and an emergency stop on one will immediately lead to an emergency stop on all. I'm not sure I'm proficient enough in coding to add that without breaking something else though...
  14. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,094
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,246Coins
    Ratings:
    +10,892 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    The FAQs may be of use: https://www.xsimulator.net/community/faq/emergency-stop-switch-wiring.56/
  15. Ronan Design

    Ronan Design Roman Design - Custom MSFS Scenery

    Joined:
    Jun 4, 2021
    Messages:
    193
    Occupation:
    Web Designer, MSFS Scenery Designer
    Location:
    Toronto, Canada
    Balance:
    1,311Coins
    Ratings:
    +71 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Those are about how to wire a manual emergency stop button. I will have one that triggers a 6-bank relay module that cuts the "ON" circuit of 6 server power supplies wired into 3 24V pairs. But what I'm talking about is the CMS3 built-in safety feature that cuts the motors when any one of them goes out of designated working zone into the "red" band. Because any single Arduino will only control 2 motors in a 6DOF, only those 2 will stop. The others will keep working, potentially tearing the rig apart. If there is no solution maybe I will try to add some code that piggybacks on the shutoff function and sends a HIGH signal out on a digital pin, and checks another digital pin for HIGH input and shuts down the motors if detected. Then shorting 3 output pins and 3 input pins between the 3 boards should coordinate the emergency shutdown and trigger all boards if any one of them goes into shutdown mode. I'm not an expert on coding Arduino but hopefully I can pull that off. I need to figure out if it's safe to short out pins t in pins across the 3 boards. Maybe a resistor is needed.
  16. grooste_lwd

    grooste_lwd Active Member

    Joined:
    Nov 20, 2015
    Messages:
    123
    Location:
    Nederland => Friesland => Leeuwarden
    Balance:
    123Coins
    Ratings:
    +91 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino
    10k
    • Like Like x 1
  17. prophet.id

    prophet.id New Member Gold Contributor

    Joined:
    Mar 11, 2024
    Messages:
    11
    Balance:
    - 41Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    3DOF
    Question: Why did the motor stop moving after I slide the dial (on the right side) very quickly?
    The motor is back to normal (able to rotate again) right after the power cycle on the 24v power supply.

    I use IBT-2 motor driver.
    10K pot connected directly to the motor shaft (where the arm is attached).

    I tried all the settings on the Utility, and it didn't seem to solve this issue.

    https://tinyurl.com/hx47725v

    Attached Files:

  18. Sebastian2

    Sebastian2 Member Gold Contributor

    Joined:
    Dec 17, 2023
    Messages:
    82
    Balance:
    296Coins
    Ratings:
    +48 / 1 / -0
    Lots of IBT2 are faulty straight from the box. Can you cross check with another IBT2?
  19. prophet.id

    prophet.id New Member Gold Contributor

    Joined:
    Mar 11, 2024
    Messages:
    11
    Balance:
    - 41Coins
    Ratings:
    +3 / 0 / -0
    My Motion Simulator:
    3DOF
    I tried the 2nd board and act exactly the same. Perhaps both are bad?
    Do you notice the Yellow line (PWM) clipped on the top? I never see those on other people picture. I wonder if this is the problem.

    Seems like when I slide the motion and manage not to get too fast, and the Yellow PWM line is not clipped, the motor moves just fine.
  20. Sebastian2

    Sebastian2 Member Gold Contributor

    Joined:
    Dec 17, 2023
    Messages:
    82
    Balance:
    296Coins
    Ratings:
    +48 / 1 / -0
    A clipping yellow line means the PWM value is at 255, so maximum output power.

    For further diagnostic, I suggest you try to try the following

    1. Measure the voltage of the PSU after the motor stopped moving. Maybe the PSU can't supply the power needed for PWM 255 and turns off.

    2a. Reduce maxPWM in SMC3tools. Try Values like 100 or 200. The maximum power of the motors will be reduced, so this way you can confirm that the issue only arises if the demanded power is too high. Even with reduced power, the motors might still be powerful enough for a satisfying experience.

    2b. If you are running a 24V system, reduce the voltage of your PSU. I think I read multiple times that cheap IBT2 don't like voltages above 18...20 V.

    ---

    I just noticed your screenshots show that you didn't just move the slider quickly (in one direction), but you moved it _back and forth_ quickly. This might mean that your problems are caused by regenerative currents. If that's the case, the PSU should turn off when the motor stops moving.
    How do you handle regenerative currents in your system?