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

Question I need help with Arduino code for my new 6DOF unlimited YAW

Discussion in 'DIY Motion Simulator Building Q&A / FAQ' started by xxpelle, Jan 31, 2021.

  1. xxpelle

    xxpelle Discord "TPMax#9574" Gold Contributor

    Joined:
    Dec 24, 2017
    Messages:
    120
    Occupation:
    Discord "TPMax#9574"
    Location:
    Germany
    Balance:
    605Coins
    Ratings:
    +150 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    I am currently building a 6DOF with no limit YAW

    The motors used are
    "Nema34 stepper motor 126mm 12Nm 6A Φ14mm Keyway Bipolar 1700oz-in"
    And the regulator is
    "DMA860H 2.4‑7.2A 18‑80VAC"
    The power supply is a
    "Siemens Delta 48V rectifier power supply"

    [​IMG]

    my problem is that the motors do not start and brake smoothly with the Arduino code that I found in the forum

    And then the Arduino code does not have to go back to -179 ° at over + 180 ° Yaw, but continue with + 181 °

    // #define DEBUG 1 // comment out this line to remove debuggin Serial.print lines

    // Declare pins
    int STEP[] = {2,4,6,8,10,12}; // Step Pins, active HIGH
    int DIR[] = {3,5,7,9,11,13}; // Direction Pins, active HIGH
    byte DIR_ACTIVE[] = {LOW, LOW, LOW, LOW, LOW, LOW};

    const int kAxisCount = 6; // how many axis we are handling

    int Pos[] = {0,0,0,0,0,0}; //Position logging

    const char kAxisName[kAxisCount] = {'A','B','C','D','E','F'}; // the letters ("names") sent from Sim Tools to identify each axis
    const int kAxisScale[kAxisCount][6] = { {0,999},{0,999},{0,999},{0,999},{0,999},{0,999} }; //Scaling
    const char kEOL = '~'; // End of Line - the delimiter for our acutator values
    const int kMaxCharCount = 3; // some insurance to 8 bit...
    int axisPosition[kAxisCount] = {500,0,0,0,0,0}; // current Axis positions, initialised to 127 middle for 8 bit
    int currentAxis; // keep track of the current Axis being read in from serial port
    int valueCharCount = 0; // how many value characters have we read (must be less than kMaxCharCount!!

    // set up some states for our state machine
    // psReadAxis = next character from serial port tells us the Axis info that follows
    // psReadValue = next characters from serial port until we hit our kMaxCharCount or kEOL which tells us the value
    enum TPortState { psReadAxis, psReadValue };
    TPortState currentState = psReadAxis;

    void setup() {
    Serial.begin(500000);
    // Define pins
    for (int i=0; i < kAxisCount; i++) {
    pinMode(STEP, OUTPUT);
    pinMode(DIR, OUTPUT);
    }
    }

    void loop()
    {
    for (int i = 0; i < kAxisCount; i++) {
    // check new position
    if (Pos != axisPosition) {
    // check direction and write DIR pin
    if (Pos >= axisPosition) {
    digitalWrite(DIR, LOW);
    Pos = Pos - 1;
    }

    if (Pos < axisPosition) {
    digitalWrite(DIR, HIGH);
    Pos = Pos + 1;
    }

    // make one step
    digitalWrite(STEP, HIGH);
    delayMicroseconds(100);
    digitalWrite(STEP, LOW);
    delayMicroseconds(100);

    //break;
    }}}

    // this code only runs when we have serial data available. ie (Serial.available() > 0).
    void serialEvent() {
    char tmpChar;
    int tmpValue;

    while (Serial.available()) {
    // if we're waiting for a Axis name, grab it here
    if (currentState == psReadAxis) {
    tmpChar = Serial.read();

    #ifdef DEBUG
    Serial.print("read in ");
    Serial.println(tmpChar);
    #endif
    for (int i = 0; i < kAxisCount; i++) { // look for our axis in the array of axis names we set up
    if (tmpChar == kAxisName) {
    #ifdef DEBUG
    Serial.print("which is axis ");
    Serial.println(i);
    #endif
    currentAxis = i; // remember which axis we found
    currentState = psReadValue; // start looking for the Axis position
    axisPosition[currentAxis] = 0; // initialise the new position
    valueCharCount = 0; // initialise number of value chars read in
    //break;
    }
    }
    }

    // if we're ready to read in the current Axis position data
    if (currentState == psReadValue) {
    while ((valueCharCount < kMaxCharCount) && Serial.available()) {
    tmpValue = Serial.read();
    if (tmpValue != kEOL) {
    tmpValue = tmpValue - 48;
    if ((tmpValue < 0) || (tmpValue > 9)) tmpValue = 0;
    axisPosition[currentAxis] = axisPosition[currentAxis] * 10 + tmpValue;
    valueCharCount++;
    }
    else break;
    }

    // if we've read the value delimiter, update the Axis and start looking for the next Axis name
    if (tmpValue == kEOL || valueCharCount == kMaxCharCount) {


    // scale the new position so the value is between 0 and 179
    axisPosition[currentAxis] = map(axisPosition[currentAxis], 0, 255, kAxisScale[currentAxis][0], kAxisScale[currentAxis][1]);
    // updateAxis(currentAxis);

    #ifdef DEBUG
    Serial.print("read in ");
    Serial.println(axisPosition[currentAxis]);
    Serial.print("Position ");
    Serial.println(Pos[currentAxis]);
    #endif

    currentState = psReadAxis;
    }
    }
    }
    }




    I have a test code where the engines run cleanly






    // testing a stepper motor with a Pololu A4988 driver board or equivalent

    // this version uses micros() to manage timing to allow high step rates to be tested
    // and illustrates a simple method for accleration and deceleration

    byte directionPin = 3;
    byte stepPin = 2;

    unsigned long curMicros;
    unsigned long prevStepMicros = 0;
    unsigned long slowMicrosBetweenSteps = 6000; // microseconds
    unsigned long fastMicrosBetweenSteps = 600;
    unsigned long stepIntervalMicros;
    unsigned long stepAdjustmentMicros;
    int numAccelSteps = 100; // 100 is a half turn of a 200 step mmotor
    int numSteps = 8000;
    int stepsToGo;
    byte direction = 1;

    void setup() {

    Serial.begin(115200);
    Serial.println("Starting Stepper Demo with acceleration");

    pinMode(directionPin, OUTPUT);
    pinMode(stepPin, OUTPUT);

    stepAdjustmentMicros = (slowMicrosBetweenSteps - fastMicrosBetweenSteps) / numAccelSteps;
    stepIntervalMicros = slowMicrosBetweenSteps;
    stepsToGo = numSteps;
    digitalWrite(directionPin, direction);
    }

    void loop() {

    moveMotor();

    }

    void moveMotor() {
    if (stepsToGo > 0) {
    if (micros() - prevStepMicros >= stepIntervalMicros) {
    prevStepMicros += stepIntervalMicros;
    singleStep();
    stepsToGo --;
    if (stepsToGo <= numAccelSteps) {
    if (stepIntervalMicros < slowMicrosBetweenSteps) {
    stepIntervalMicros += stepAdjustmentMicros;
    }
    }
    else {
    if (stepIntervalMicros > fastMicrosBetweenSteps) {
    stepIntervalMicros -= stepAdjustmentMicros;
    }
    }
    }
    }
    else {
    direction = ! direction;
    digitalWrite(directionPin, direction);
    // next two lines just for the demo
    delay(2000);
    Serial.println("Changing direction");
    stepsToGo = numSteps;
    prevStepMicros = micros();
    }
    }

    void singleStep() {

    digitalWrite(stepPin, HIGH);
    digitalWrite(stepPin, LOW);

    }

    Can someone help me

    Attached Files:

    • Winner Winner x 1
    • Creative Creative x 1
  2. sam poole

    sam poole Active Member

    Joined:
    Nov 14, 2017
    Messages:
    137
    Location:
    midlands
    Balance:
    34Coins
    Ratings:
    +45 / 0 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 4DOF, 6DOF
    does this have positional feedback for infinite yaw? I always imagined if i were to do this it would just be a case of not connecting a pot to the motor and allowing free movement then tune accordingly this seems a lot more in depth than that i am intrigued to see how this works as i have wanted to experiment with this also
  3. xxpelle

    xxpelle Discord "TPMax#9574" Gold Contributor

    Joined:
    Dec 24, 2017
    Messages:
    120
    Occupation:
    Discord "TPMax#9574"
    Location:
    Germany
    Balance:
    605Coins
    Ratings:
    +150 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF

    With this arduino code no "Hall sensor" potentiometer is used

    The position is determined by the steps of the motors

    If a position is determined via a sensor, I can upgrade it at any time

    I saw in a post where someone implemented 360 ° roll with a hall sensor and a brush motor
    https://www.xsimulator.net/community/threads/360-degree-rotation.8262/
    Last edited: Feb 1, 2021
  4. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,846
    Location:
    Portugal
    Balance:
    14,096Coins
    Ratings:
    +2,169 / 16 / -0
    My Motion Simulator:
    6DOF
    I will be back to give my idea on the yaw, but you are doing exactlly what I want to do for my next rig.

    But I want to mount it on the wall to have unlimited roll and allow for inverted flight.

    Unlimited YAW is not thd ideal. It has not much use in the motion cues. We need the yaw, but have it unlimited is something that in my opinion is not important.
  5. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,846
    Location:
    Portugal
    Balance:
    14,096Coins
    Ratings:
    +2,169 / 16 / -0
    My Motion Simulator:
    6DOF
    I did not look at the code in a detailed way, but the trick for the full rotation, is to travel the shorter distance.

    Imagine you have 10000 steps for a full turn, from 0=0º to 10000=360º.
    If you are at step 8000 and want to go to step 5, the shorter distance is 2005 steps increasing, not 7995 steps decreasing the step, so you will keep increasing the step.

    Like I said above, I'm adding to my software (Mover) this type of rotating Stewart platform, but mounted in a wall.
    Might be my next rig. Need to find a good and cheap solution to build it.
    I see you have the motors rotating (travelling), after 1 or 2 turns it might have a cable problem.
    On my thoughts, I thought of using fixed motors and a kind of cable system, like a big belt to move the joints.
    • Informative Informative x 1
  6. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,233
    Location:
    Marseille - FRANCE
    Balance:
    20,875Coins
    Ratings:
    +2,079 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    slip rings are fine for logical signals but quite expansive for power

    eager to see more :)
  7. xxpelle

    xxpelle Discord "TPMax#9574" Gold Contributor

    Joined:
    Dec 24, 2017
    Messages:
    120
    Occupation:
    Discord "TPMax#9574"
    Location:
    Germany
    Balance:
    605Coins
    Ratings:
    +150 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    IMG_1316.JPG
    IMG_1317.JPG

    Attached Files:

    • Useful Useful x 1
    • Creative Creative x 1
  8. xxpelle

    xxpelle Discord "TPMax#9574" Gold Contributor

    Joined:
    Dec 24, 2017
    Messages:
    120
    Occupation:
    Discord "TPMax#9574"
    Location:
    Germany
    Balance:
    605Coins
    Ratings:
    +150 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    • Like Like x 2
    • Creative Creative x 1
  9. xxpelle

    xxpelle Discord "TPMax#9574" Gold Contributor

    Joined:
    Dec 24, 2017
    Messages:
    120
    Occupation:
    Discord "TPMax#9574"
    Location:
    Germany
    Balance:
    605Coins
    Ratings:
    +150 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
  10. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,233
    Location:
    Marseille - FRANCE
    Balance:
    20,875Coins
    Ratings:
    +2,079 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    DIY slip rings! very nice :)
  11. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,846
    Location:
    Portugal
    Balance:
    14,096Coins
    Ratings:
    +2,169 / 16 / -0
    My Motion Simulator:
    6DOF
    Been working on this type of rig like I said. Just made some evolution yesterday:



    My objective is the wall mounted rig, but I will keep the horizontal one also.
    Calculation is working, but there's no limits test yet (beyond rod size and overlapping floor joints).
    • Winner Winner x 1
  12. xxpelle

    xxpelle Discord "TPMax#9574" Gold Contributor

    Joined:
    Dec 24, 2017
    Messages:
    120
    Occupation:
    Discord "TPMax#9574"
    Location:
    Germany
    Balance:
    605Coins
    Ratings:
    +150 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF

    OK . Where can I get the Rig Plugin for FlyPT Mover
  13. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,846
    Location:
    Portugal
    Balance:
    14,096Coins
    Ratings:
    +2,169 / 16 / -0
    My Motion Simulator:
    6DOF
    Next Mover release.
    Almost done. Need to add the limits to the rig and correct some small bugs.
    I will post here when ready.
    • Like Like x 2
  14. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,886
    Location:
    London
    Balance:
    11,543Coins
    Ratings:
    +453 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    is it only the yaw that uses a stepper motor ?

    are the other axis going to be lever or ballscrew ?

    I am not sure stepper motors are the best solution because you can only move one step at a time so you cant use pid control to get to the destination faster

    i imagine a stepper motor and gearbox will have a lot of torque !

    i know a few guys have tried a stepper motor for a ffb wheel using a different way to move them
    the result was a steppy feeling on the wheel but i think it would be ok in a motion rig with gears
  15. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,846
    Location:
    Portugal
    Balance:
    14,096Coins
    Ratings:
    +2,169 / 16 / -0
    My Motion Simulator:
    6DOF
    I think they are all steppers.
    In this rig, there are no actuators, motors move the bottom joints around a circle.

    I think ranges are less than we have with actuators, but with two circles, we allow the rods to swap positions and then we get higher ranges.

    Not sure I'm explaining it well


    Edit:
    Better explanation
    upload_2021-2-3_15-4-46.png
    With two circles, rods can swap positions not colliding. This increases the range.

    upload_2021-2-3_15-6-43.png
    • Like Like x 2
    Last edited: Feb 3, 2021
  16. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,846
    Location:
    Portugal
    Balance:
    14,096Coins
    Ratings:
    +2,169 / 16 / -0
    My Motion Simulator:
    6DOF
    Here's what they call a rotopod in action:



    Or similar to what I want:



    The one bellow is closest to what I want, but vertical:

    There's two circles, so rods can swap and increase ranges.

    @xxpelle , sorry for kidnapping your thread. When I get some more development and info on what I want to do, I will make a thread, I will avoid to contaminate this one.
    • Informative Informative x 2
    • Like Like x 1
  17. xxpelle

    xxpelle Discord "TPMax#9574" Gold Contributor

    Joined:
    Dec 24, 2017
    Messages:
    120
    Occupation:
    Discord "TPMax#9574"
    Location:
    Germany
    Balance:
    605Coins
    Ratings:
    +150 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF

    that's all great information for me, please more of it
  18. xxpelle

    xxpelle Discord "TPMax#9574" Gold Contributor

    Joined:
    Dec 24, 2017
    Messages:
    120
    Occupation:
    Discord "TPMax#9574"
    Location:
    Germany
    Balance:
    605Coins
    Ratings:
    +150 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, Motion platform, 6DOF
    that's the reason why I love this forum
    • Agree Agree x 3
  19. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,886
    Location:
    London
    Balance:
    11,543Coins
    Ratings:
    +453 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    Its quite a cool approach to a sim !

    How many mm/s can it provide ?
  20. pmvcda

    pmvcda aka FlyPT

    Joined:
    Nov 3, 2010
    Messages:
    1,846
    Location:
    Portugal
    Balance:
    14,096Coins
    Ratings:
    +2,169 / 16 / -0
    My Motion Simulator:
    6DOF
    Depends on motors, but can be really fast:







    Vibration tests:
    • Like Like x 1
    Last edited: Feb 4, 2021