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 nedeed for a 6DOF mini platform based on small motors and Arduino.

Discussion in 'New users start here - FAQ' started by dr.Evil, Sep 6, 2020.

  1. dr.Evil

    dr.Evil New Member

    Joined:
    Aug 26, 2020
    Messages:
    15
    Balance:
    66Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    2DOF
    Hi,

    I successfully completed the admission exam required for this forum, aka building the mini 2DOF "shoulder strapped" platform. I spent 3 days in reading,trying, failing and reading again. Making the software to work was beyond a bad dream, there are so many variables and stuff to check PC and Arduino side, firing up an old compiler and so on. By pure luck I changed the Arduino board(this leads me to think 1st batch of problems arose from baudrate) and loaded some n!th 2dof code I've found on web, this one is 5 years old and if fails me on different levels e.g no motors movements because it cannot be sketched. Cfg file cannot be put in SimTools 2.0 ( I'll xml it if I need).
    I tried SMC3 tools and I got lucky only once - sadly motors didn't move, never got em again working.

    I got it working now and also only half figured the axis configs, a 3/6 dof config would enormously help me learnt it.

    I am thinking of trying a 3 mini sim platform using only 3 motors and pwn pins from ard , all this juiced with an external battery pack. Is is doable?
  2. dr.Evil

    dr.Evil New Member

    Joined:
    Aug 26, 2020
    Messages:
    15
    Balance:
    66Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    2DOF
    This is the code I am using and I adapted to the 3 motors
    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>
    //#define DEBUG 1                                    // comment out this line to remove debuggin Serial.print lines
    const int kActuatorCount = 3;                       // how many Actuators we are handling
    
    // the letters ("names") sent from Sim Tools to identify each actuator
    // NB: the order of the letters here determines the order of the remaining constants kPins and kActuatorScale
    const char kActuatorName[kActuatorCount] = { 'R', 'L' , 'F' };
    const int kPins[kActuatorCount] = {4, 5,6 };                       // pins to which the Actuators are attached
    const int kActuatorScale[kActuatorCount][3] = { { 0, 179 } ,    // Right Actuator scaling
                                                    { 179, 0 }   , { 179, 0 } , // Front side Actuator scaling  // Left side Actuator scaling
                                                   };    
    const char kEOL = '~';                              // End of Line - the delimiter for our acutator values
    const int kMaxCharCount = 3;                        // some insurance...
    Servo actuatorSet[kActuatorCount];                  // our array of Actuators
    int actuatorPosition[kActuatorCount] = {90, 90, 90};    // current Actuator positions, initialised to 90
    int currentActuator;                                // keep track of the current Actuator 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
    // psReadActuator = next character from serial port tells us the Actuator
    // psReadValue = next 3 characters from serial port tells us the value
    enum TPortState { psReadActuator, psReadValue };  
    TPortState currentState = psReadActuator;
    
    void setup()
    {
        // attach the Actuators to the pins
        for (int i = 0; i < kActuatorCount; i++)
            actuatorSet[i].attach(kPins[i]);
       
        // initialise actuator position
        for (int i = 0; i < kActuatorCount; i++)
            updateActuator(i);
       
        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 Actuator name, grab it here
            if (currentState == psReadActuator) {
                tmpChar = Serial.read();
                // look for our actuator in the array of actuator names we set up
    #ifdef DEBUG          
    Serial.print("read in ");          
    Serial.println(tmpChar);          
    #endif
                for (int i = 0; i < kActuatorCount; i++) {
                    if (tmpChar == kActuatorName[i]) {
    #ifdef DEBUG          
    Serial.print("which is actuator ");          
    Serial.println(i);          
    #endif
                        currentActuator = i;                        // remember which actuator we found
                        currentState = psReadValue;                 // start looking for the Actuator position
                        actuatorPosition[currentActuator] = 0;      // initialise the new position
                        valueCharCount = 0;                         // initialise number of value chars read in
                        break;
                    }
                }
            }
           
            // if we're ready to read in the current Actuator's 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;
                        actuatorPosition[currentActuator] = actuatorPosition[currentActuator] * 10 + tmpValue;
                        valueCharCount++;
                    }
                    else break;
                }
               
                // if we've read the value delimiter, update the Actuator and start looking for the next Actuator name
                if (tmpValue == kEOL || valueCharCount == kMaxCharCount) {
    #ifdef DEBUG          
    Serial.print("read in ");          
    Serial.println(actuatorPosition[currentActuator]);          
    #endif
                    // scale the new position so the value is between 0 and 179
                    actuatorPosition[currentActuator] = map(actuatorPosition[currentActuator], 0, 255, kActuatorScale[currentActuator][0], kActuatorScale[currentActuator][1]);
    #ifdef DEBUG          
    Serial.print("scaled to ");          
    Serial.println(actuatorPosition[currentActuator]);          
    #endif
                    updateActuator(currentActuator);
                    currentState = psReadActuator;
                }
            }
        }
    }
    
    
    // write the current Actuator position to the passed in Actuator
    void updateActuator(int thisActuator) {
        actuatorSet[thisActuator].write(actuatorPosition[thisActuator]);
    }
    I didn't look deep into SMC3 because I'm missing the 3rd motor - a 5 pack coming tomorrow. I mean I got the ino and sees motors.
    Last edited: Sep 6, 2020
  3. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,551
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    145,124Coins
    Ratings:
    +10,778 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
  4. dr.Evil

    dr.Evil New Member

    Joined:
    Aug 26, 2020
    Messages:
    15
    Balance:
    66Coins
    Ratings:
    +1 / 0 / -0
    My Motion Simulator:
    2DOF
    Believe me I've printed the simtools manual. The 2Dof is working good now, the problems were part from the arduino board and some an old serial monito.
    I'm trying to scale it up to a 3 or 6dof model, with pots and maybe motor drivers before I will begin construction for the final one.