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 Servo Testing Problems 2DOF model rig

Discussion in 'SimTools DIY Version' started by Xyclone, Sep 10, 2017.

  1. Xyclone

    Xyclone New Member Gold Contributor

    Joined:
    Sep 4, 2017
    Messages:
    6
    Occupation:
    Engineer
    Location:
    Syracuse, NY
    Balance:
    210Coins
    Ratings:
    +4 / 0 / -0
    ###################################################
    Simulator
    1. DIY
    2. 2DOF Model
    3. Actuators: Testing Servos
    4. Interface: Arduino
    SimTools
    1. Version Number: 2.1
    2. Game Plugin where the error is happening: issues occurring during testing
    3. Settings: Running Serial Tests
    ###################################################

    Hey all,

    Working towards building a temporary test model before I start building my rig as many others

    I have been trying to test my Adruino setup with a simple 2DOF setup with two RC servos on the bench.

    I initially tried my own code and failed (I haven't coded anything in over a decade), so to get it off the ground I tried testing eaorobbie's RC test code. (your old posts have been VERY helpful and guiding me through much of the process, thanks dude!)

    Problem: I can use the serial monitor in Adruino to control the servos without issue sending manual commands and the same goes for using the "HW start" and "HW stop" lines to send initial alignment commands to them and they also respond when I start Output testing, so I know Simtools is communicating with the Adruino, but once it turns on, the output sliders dont do anything. I'm now using not only eaurobbies code, but also his interface setup (thanks again) and it still doesnt work when output testing.

    I thought maybe it was power related so the Adruino is now powered off 9 volts, and I even pulled one of the servos so it should only be running one to lighten the load, still nothing.

    I'm assuming its something fundamental and easy that I'm missing, but my engineer brain is mucking it up, help!

    Adruino Code (eaorobbies to a T with Debug commented out) and attached are two screens of my settings
    //********************************************************************************************
    // 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.attach(kPins);

    // 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) {
    #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]);
    }

    Attached Files:

  2. insanegr

    insanegr !N$@n€

    Joined:
    Jan 14, 2014
    Messages:
    505
    Location:
    Athens
    Balance:
    16,715Coins
    Ratings:
    +499 / 1 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    in interface settings you should have an a or a b for axis grouping IE( A<Axis1a>~ B<Axis2a>~ ) and you will need to configure the default profile for testing movements manually in simtools
    • Agree Agree x 2
  3. Gadget999

    Gadget999 Well-Known Member

    Joined:
    Dec 27, 2015
    Messages:
    1,897
    Location:
    London
    Balance:
    11,610Coins
    Ratings:
    +458 / 9 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, 6DOF
    does it work with the SMC3 interface ?
  4. Xyclone

    Xyclone New Member Gold Contributor

    Joined:
    Sep 4, 2017
    Messages:
    6
    Occupation:
    Engineer
    Location:
    Syracuse, NY
    Balance:
    210Coins
    Ratings:
    +4 / 0 / -0
    @insanegr - You nailed it on the head! I must have missed the grouping letters somewhere, every walkthrough I saw only had the <Axis#> no grouping!

    Well glad to know it was something stupid!

    Thanks guys! On to the next step: firing up the 3D printer for the seat and some framework
    • Like Like x 2