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

2DOF mini Arduino motion platform protoype

Discussion in 'DIY Motion Simulator Projects' started by early_m, Feb 7, 2017.

  1. early_m

    early_m Active Member

    Joined:
    Jul 28, 2016
    Messages:
    321
    Location:
    Chelmsford
    Balance:
    822Coins
    Ratings:
    +347 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    this is @eaorobbie 's code i'm using
    Code:
    //********************************************************************************************
    // RC Model Servo
    // Original code By EAOROBBIE (Robert Lindsay)
    // Completely mangled by aarondc
    // For free use for Sim Tool Motion Software
    //********************************************************************************************
    
    #include <Servo.h>
    const int kServoCount = 2; // how many servos we are handling
    const int kRIGHT = 0; // constants for our servos
    const int kLEFT = 1; //
    const int kPins[kServoCount] = {4, 5}; // pins to which the servos are attached
    const int kValueCharCount = 3; // how many characters we must read in for a new servo position value
    const int kServoScale[kServoCount][2] = { { 179, 0 } , // Right servo scaling
                                              { 0, 179 }};      // Left side servo scaling
    Servo servoSet[kServoCount]; // our array of servos
    int servoPosition[kServoCount] = {90, 90}; // current servo positions, initialised to 90
    int currentServo; // keep track of the current servo being read in from serial port
    int valueCharCount = 0; // how many value characters have we read in
    
    // set up some states for our state machine
    // psReadServo = next character from serial port tells us the servo
    // psReadValue = next 3 characters from serial port tells us the value
    enum TPortState { psReadServo, psReadValue };  
    TPortState currentState = psReadServo;
    
    void setup()
    {
        // attach the servos to the pins
        servoSet[kRIGHT].attach(kPins[kRIGHT]);
        servoSet[kLEFT].attach(kPins[kLEFT]);
       
        // initialise their position
        updateServo(kRIGHT);
        updateServo(kLEFT);
       
        Serial.begin(9600); // opens serial port at a baud rate of 9600
    }
    void loop()
    {
    
    }
    
    // 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 servo name, grab it here
            if (currentState == psReadServo) {
                tmpChar = Serial.read();
                switch (tmpChar) {
                    case 'R' : currentServo = kRIGHT;
    //Serial.println("reading right servo value");
                               break;
                    case 'L' : currentServo = kLEFT;
    //Serial.println("reading left servo value");
                               break;
                }
                currentState = psReadValue;             // start looking for the servo position
                servoPosition[currentServo] = 0;         // initialise the new position
                valueCharCount = 0;                     // intitialise our position characters read in from serial port counter
            }
           
            // if we're ready to read in the current servo's position data
            if (currentState == psReadValue) {
                while ((valueCharCount < kValueCharCount) && Serial.available()) {
                    tmpValue = Serial.read() - 48;
                    if (tmpValue < 0) tmpValue = 0;
                    servoPosition[currentServo] = servoPosition[currentServo] * 10 + tmpValue;
                    valueCharCount++;
                }
               
                // if we've read the number of characters required for servo position, update the servo and start looking for the next servo name
                if (valueCharCount == kValueCharCount) {
    //Serial.print("read in ");
    //Serial.println(servoPosition[currentServo]);
                    // scale the new position so the value is between 0 and 179
                    servoPosition[currentServo] = map(servoPosition[currentServo], 0, 255, kServoScale[currentServo][0], kServoScale[currentServo][1]);
    //Serial.print("scaled to ");
    //Serial.println(servoPosition[currentServo]);
                    updateServo(currentServo);
                    currentState = psReadServo;
                }
            }
        }
    }
    
    
    // write the current servo position to the passed in servo
    void updateServo(int thisServo) {
        servoSet[thisServo].write(servoPosition[thisServo]);
    }
    simtools settings
    GSEAT1.png GSEAT2.png
    video of behaviour

  2. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,194
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,844Coins
    Ratings:
    +10,920 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Last edited: Feb 13, 2017
  3. early_m

    early_m Active Member

    Joined:
    Jul 28, 2016
    Messages:
    321
    Location:
    Chelmsford
    Balance:
    822Coins
    Ratings:
    +347 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
  4. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,194
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,844Coins
    Ratings:
    +10,920 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    I have not done so on SimTools 2 but download and try the code and its preset, but be aware that SimTools 2 needs the Axis Interface defined with an a, like this: Axis1a
  5. early_m

    early_m Active Member

    Joined:
    Jul 28, 2016
    Messages:
    321
    Location:
    Chelmsford
    Balance:
    822Coins
    Ratings:
    +347 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    Yep I have the interface output as R<Axis1a>~ L<Axis2a>~ and matched the servo pins with the code (4&5). Still no joy. And in @eaorobbie 's rc ard code this works great, but the servos dont function the way i require for a gseat.
    What needs to be changed so that one servo only deals with positive data and one servo with negative data? the gseat paddles need to be pushed outwards and not pulled inwards by the servo. Really scratching me head. Appreciate your help @noorbeast
  6. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,194
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,844Coins
    Ratings:
    +10,920 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    If the servos are now working with telemetry you just need to configure SimTools to suit, @SeatTime recently did this for his G-seat project.

    Checking or unchecking the DIR box in the Axis Settings determines which way the axis moves.
  7. early_m

    early_m Active Member

    Joined:
    Jul 28, 2016
    Messages:
    321
    Location:
    Chelmsford
    Balance:
    822Coins
    Ratings:
    +347 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    The servos work under @eaorobbie 's rc code, but not the code he posted in @Schluzu 's gseat post (the twitch as per the video). Am I OK using the rc code for this application? If so I will stick with that, it works. What I'm not achieving is the servo behaviour. I'm probably not explaining it very well so I have made the animation below to show the result I am after
    Servos.gif
  8. mirkobastianini

    mirkobastianini Active Member

    Joined:
    Jan 23, 2017
    Messages:
    193
    Occupation:
    informatic
    Location:
    italy
    Balance:
    1,300Coins
    Ratings:
    +77 / 2 / -0
    My Motion Simulator:
    2DOF
  9. early_m

    early_m Active Member

    Joined:
    Jul 28, 2016
    Messages:
    321
    Location:
    Chelmsford
    Balance:
    822Coins
    Ratings:
    +347 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    yep me too, great little bit of code.
    my prototype is all ready to go, just waiting on my 3d prints. although its looking likely that the parts will be harvested for a new project
    • Like Like x 1
  10. early_m

    early_m Active Member

    Joined:
    Jul 28, 2016
    Messages:
    321
    Location:
    Chelmsford
    Balance:
    822Coins
    Ratings:
    +347 / 4 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, Motion platform
    I didn't think I would ever finish this project after moving onto a full size g-seat concept. But as the final version of the g-seat has begun and the concept had to be dismantled I couldn't resist harvesting some parts and assembling it. Gave it a quick run in LFS. Was a fun little project and a great intro into all aspect of designing a sim.

    Vid

    Attached Files:

    • Like Like x 2