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

RC Model for Motion Simulation

Discussion in 'SimTools compatible interfaces' started by eaorobbie, Jul 17, 2013.

  1. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,051
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,004Coins
    Ratings:
    +10,884 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    The Interface settings look correct.

    With Axis Assignment I would expect 1 DIR to be checked orange for roll, but that won't have anything to do with it not worker.

    As we have already ruled our antivirus and language settings that leaves me wondering about your actual hardware and its wiring. What specific servos are you using?

    The wiring should be this, so I just want to confirm it is:
    [​IMG]
  2. Vlad1225@45

    Vlad1225@45 New Member

    Joined:
    Oct 27, 2023
    Messages:
    18
    Balance:
    110Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    I'm attaching a video
  3. Vlad1225@45

    Vlad1225@45 New Member

    Joined:
    Oct 27, 2023
    Messages:
    18
    Balance:
    110Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    I checked everything correctly 10 times again but nothing works
  4. GWiz

    GWiz Active Member

    Joined:
    May 12, 2019
    Messages:
    186
    Occupation:
    Dentist
    Location:
    Aberdeenshire, Scotland
    Balance:
    1,498Coins
    Ratings:
    +120 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    Make sure you have clicked the green 'Save' after changing the Interface settings, it should bring up a window saying 'Settings Saved' if it updates correctly.

    I've verified the code and your settings with an arduino Uno and servo here and they work for me. You could also try closing down simtools and starting it again and check that the interface settings are showing up correctly. Also try unplugging and replugging the usb to your microcontroller.

    Also when the microcontroller is plugged in, your servo should move to centre and resist you manually moving the servo arm even without Simtools running if the code has been uploaded correctly.
  5. Vlad1225@45

    Vlad1225@45 New Member

    Joined:
    Oct 27, 2023
    Messages:
    18
    Balance:
    110Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    Maybe I, of course, uploaded the wrong sketch to the Arduino Uno, Serov drives resist manual movement, what you wrote is what I tried, but nothing changed
  6. GWiz

    GWiz Active Member

    Joined:
    May 12, 2019
    Messages:
    186
    Occupation:
    Dentist
    Location:
    Aberdeenshire, Scotland
    Balance:
    1,498Coins
    Ratings:
    +120 / 0 / -0
    My Motion Simulator:
    DC motor, Arduino, 6DOF
    Here is the code I used:

    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 = 2;                       // 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' };
    const int kPins[kActuatorCount] = {4, 5};                       // pins to which the Actuators are attached
    const int kActuatorScale[kActuatorCount][2] = { { 0, 179 } ,    // Right Actuator scaling
                                                    { 179, 0 }      // 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};    // 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]);
    }
    
  7. Vlad1225@45

    Vlad1225@45 New Member

    Joined:
    Oct 27, 2023
    Messages:
    18
    Balance:
    110Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    Well, it turns out that I also used it, maybe the Arduino ide is not the latest version installed
  8. Vlad1225@45

    Vlad1225@45 New Member

    Joined:
    Oct 27, 2023
    Messages:
    18
    Balance:
    110Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    in the section axis assignmens % set to 100 and dir DOF1 Axis2a set and when testing at 50-60 Roll and Pitch the first servo rotates by 1mm and that’s it
  9. Vlad1225@45

    Vlad1225@45 New Member

    Joined:
    Oct 27, 2023
    Messages:
    18
    Balance:
    110Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    and for some reason I have an Arduino connected to the com port where it is written in sim tools, but next to the cross and DEMO the red indicator is on, but when you turn on the test the blue one turns on, the red one means that there is no connection
  10. Vlad1225@45

    Vlad1225@45 New Member

    Joined:
    Oct 27, 2023
    Messages:
    18
    Balance:
    110Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    2DOF
    what should I do please help me
  11. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,051
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,004Coins
    Ratings:
    +10,884 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    @eaorobbie's RC code works and the related instructions are here: https://www.xsimulator.net/community/threads/2dof-simulator-servo-model.6851/#post-77270

    There is something odd you are doing, or with your hardware, which is not obvious.

    So, my suggestion is start from scratch. Download the code fresh: https://www.xsimulator.net/community/marketplace/rc-model-code-for-arduino-uno-2dof-expandable.89/

    Then rewire:
    [​IMG]

    Then reinstall and reconfigure SimTools: interface setup - IMPORTANT - Assuming a 2DOF for SimTools 2 the Interface Output should be set like this R<Axis1a>~L<Axis2a>~ https://www.xsimulator.net/community/attachments/rcsettings-jpg.48565/
    • Agree Agree x 1
  12. Krzysztof Dej

    Krzysztof Dej Active Member

    Joined:
    Jun 3, 2020
    Messages:
    310
    Location:
    Poland
    Balance:
    1,090Coins
    Ratings:
    +73 / 0 / -0
    My Motion Simulator:
    2DOF

    Attached Files:

    • Informative Informative x 1
    Last edited: Dec 31, 2023
  13. rocketfire302

    rocketfire302 Member

    Joined:
    Jun 19, 2024
    Messages:
    30
    Balance:
    66Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    SCN5, SimAxe
    maybe someone can help me.

    i am using this example code. by the way nice bit of code..thanks

    my issue is that i can get only 2 servos working. R, L but not B. or i can get B working but just not the third servo. in Simtool i have R<Axis1a>L<Axis2a>B<Axis3a> i've used the "~" but that make no difference.

    what i'm trying to get working is 4 servos but again i can only get 2 to work.

    Any ideas?


    / Original code By EAOROBBIE (Robert Lindsay)
    // Completely mangled by aarondc
    // Modify by Jun :p
    // 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', 'B' };
    const int kPins[kActuatorCount] = {5, 6, 9}; // pins to which the Actuators are attached
    const int kActuatorScale[kActuatorCount][3] = { { 0, 179 } , // Right Actuator scaling
    { 179, 0 } , // Left side Actuator scaling
    { 0, 179 } // Back 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;
  14. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,051
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,004Coins
    Ratings:
    +10,884 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Just checking, have you followed @eaorobbie's advice here for expanding his code: https://www.xsimulator.net/community/marketplace/rc-model-code-for-arduino-uno-2dof-expandable.89/
  15. rocketfire302

    rocketfire302 Member

    Joined:
    Jun 19, 2024
    Messages:
    30
    Balance:
    66Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    SCN5, SimAxe
  16. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,051
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,004Coins
    Ratings:
    +10,884 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Why?
  17. rocketfire302

    rocketfire302 Member

    Joined:
    Jun 19, 2024
    Messages:
    30
    Balance:
    66Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    SCN5, SimAxe
    because i already wired and solders things before expanding the code.
    Pin 10 is a PWM output so it does not matter (3,5,6,9,10,11) are all PWM and can be used
  18. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    21,051
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    148,004Coins
    Ratings:
    +10,884 / 54 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Did you review @eaorobbie's code and how it relates to pins: https://www.xsimulator.net/community/marketplace/rc-model-code-for-arduino-uno-2dof-expandable.89/

    void setup()
    {
    // attach the Actuators to the pins
    for (int i = 0; i < kActuatorCount; i++)
    actuatorSet.attach(kPins);

    // initialise actuator position
    for (int i = 0; i < kActuatorCount; i++)
    updateActuator(i);
  19. rocketfire302

    rocketfire302 Member

    Joined:
    Jun 19, 2024
    Messages:
    30
    Balance:
    66Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    SCN5, SimAxe
    i can try using different pins tomorrow as a test, however don't see why that would make a difference...but I've been wrong before according to my wife LOL.

    Looking over the Arduino Docs they stated you needed to pick a PWM (pulse width modulated) pin for servos hence why i picked pin 9 and 10 which are PWM

    the code you show just calls from a list KPins and increments to next value so it should "attach"
    pin 5, then 6 then 9 then 10 so that should be working. the loop is derived by the kActuatorCount which is 4 so it should increment all four

    const int kActuatorCount = 4;
    const int kPins[kActuatorCount] = {5,6,9,10};

    for (int i = 0; i < kActuatorCount; i++)
    actuatorSet.attach(kPins);

    i'll post what i find when changing the pins tomorrow.
    any other imput is welcome...thanks
  20. rocketfire302

    rocketfire302 Member

    Joined:
    Jun 19, 2024
    Messages:
    30
    Balance:
    66Coins
    Ratings:
    +0 / 0 / -0
    My Motion Simulator:
    SCN5, SimAxe
    All Right...got to love CHATGPT
    looks like the servo library uses a timer on pins 9 and 10 so you cannot use them as PWM

    here is chatgpt reply:

    The issue where only two of the three PWM signals work could be due to the pins you've chosen to generate PWM signals on. The Arduino Uno has limitations on which pins can generate PWM signals when using the Servo library.

    Key Points:
    1. Servo Library Conflicts with PWM Pins:
      • The Servo library uses hardware timers to control servos, which can conflict with the PWM functionality on certain pins.
      • On the Arduino Uno, the Servo library uses Timer1, which controls pins 9 and 10.
      • If you're trying to use pins 5, 6, and 9, note that pin 9 will be controlled by Timer1, which the Servo library also uses. This may disable the PWM functionality on that pin.
    Suggested Solution:
    To avoid conflicts, you can try using different PWM-capable pins that do not conflict with the Servo library, or ensure that you're not using the same timer for both servos and PWM signals.

    Adjusted Code Example:
    You could try moving the PWM output to pins 3, 5, and 6 instead, as pin 3 is controlled by Timer2, which isn't used by the Servo library: