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

Help with model code

Discussion in 'New users start here - FAQ' started by Abram Manoge, Apr 6, 2021.

  1. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Hi i need your assistance. im using this code. the servo moves when i send commands in serial monitor (ex L90) but i cant seem to get it to move in sim tools . What do i put in "Axis assignments" . I entered the information in interface settings the same as the picture you have attached and i have game manager running and set to live for speed
  2. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Im currently waiting for wiper motors and motor drivers to start building my sim. Can you please assist in turning your code to a small scale model one . im gonna use the following

    Arduino uno r3
    2x SG90 servos (2dof setup)

    im currently using the following code but i cant seem to get it to communicate with sim tools although in ardunio ide i can get the servos to move by sending serial commands(ex L120 or R90). here is the code

    "
    //********************************************************************************************
    // RC Model Servo
    // Written By EAOROBBIE (Robert Lindsay)
    // For free use for Sim Tool Motion Software
    //********************************************************************************************

    #include <Servo.h>

    Servo myservo1; // create servo object to control a servo
    Servo myservo2; // create servo object to control a servo
    char kind_of_data; // to capture which servo needs to be move
    int valLSP = 90; // set the intial Left Servo Position to centre
    int valRSP = 90; // set the intial Right Servo Position to centre

    void setup()
    {
    myservo1.attach(4); // attaches the servo on pin 5 to the servo object
    myservo2.attach(5); // attaches the servo on pin 4 to the servo object
    myservo1.write(valLSP); // sets the servo position according to the scaled value
    myservo2.write(valRSP); // set the servo position according to the scaled value

    Serial.begin(9600); // opens serial port at a baud rate of 9600
    }

    void loop()
    {

    //****************************** READ DATA FROM SERIAL ******************************
    while (Serial.available() > 0)
    {

    kind_of_data = Serial.read();
    if (kind_of_data == 'R' ) Read_RightServo();
    if (kind_of_data == 'L' ) Read_LeftServo();



    myservo1.write(valRSP); // sets the servo position according to the scaled value
    myservo2.write(valLSP); // sets the servo position according to the scaled value
    }
    }

    void Read_RightServo(){

    int RightServoPos = 0;
    delay(2);
    int RSP100 = Serial.read();
    delay(2);
    int RSP10 = Serial.read();
    delay(2);
    int RSP1= Serial.read();

    RSP100 = ((RSP100)-48)*100;
    RSP10 = ((RSP10)-48)*10;
    RSP1 = ((RSP1)-48)*1;
    if (RSP10 < 0 && RSP1 < 0){RSP100 = RSP100/100;RSP10 = 0;RSP1 = 0;}
    if (RSP1 < 0){RSP100 = RSP100/10;RSP10 = RSP10/10;RSP1 = 0;}
    //Serial.println(RSP100); // these are here for debugging purposes
    //Serial.println(RSP10); // these are here for debugging purposes
    //Serial.println(RSP1); // these are here for debugging purposes
    RightServoPos = RSP100+RSP10+RSP1;
    valRSP = map(RightServoPos, 0, 255, 0, 179); // scale it to use it with the servo (value between 0 and 180)
    //Serial.println(RightServoPos); // these are here for debugging purposes
    //Serial.println(valRSP); // these are here for debugging purposes

    }

    void Read_LeftServo(){

    int LeftServoPos = 0;
    delay(2);
    int LSP100 = Serial.read();
    delay(2);
    int LSP10 = Serial.read();
    delay(2);
    int LSP1= Serial.read();

    LSP100 = ((LSP100)-48)*100;
    LSP10 = ((LSP10)-48)*10;
    LSP1 = ((LSP1)-48)*1;
    if (LSP10 < 0 && LSP1 < 0){LSP100 = LSP100/100;LSP10 = 0;LSP1 = 0;}
    if (LSP1 < 0){LSP100 = LSP100/10;LSP10 = LSP10/10;LSP1 = 0;}
    //Serial.println(LSP100); // these are here for debugging purposes
    //Serial.println(LSP10); // these are here for debugging purposes
    //Serial.println(LSP1); // these are here for debugging purposes
    LeftServoPos = LSP100+LSP10+LSP1;
    valLSP = map(LeftServoPos, 0, 255, 179, 0); // scale it to use it with the servo (value between 0 and 180)
    //Serial.println(LeftServoPos); // these are here for debugging purposes
    //Serial.println(valLSP); // these are here for debugging purposes
    }
    "
  3. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Here are screenshots of my simtools settings. i also have game manager open running live for speed please assist sim settings.png
  4. Halloween2go

    Halloween2go Active Member Gold Contributor

    Joined:
    Dec 12, 2019
    Messages:
    202
    Balance:
    1,407Coins
    Ratings:
    +175 / 1 / -0
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform
    Abram, it's not my code for sure.. AEROBBIE code. Take a look at this link if you have time. I used it to initially set up my simtools. I cant tell what the characters are in the interface output section you show but they should be like this:
    [A<Axis1a>][B<Axis2a>]
    also Output Type - Binary
    and BitsPerSec - 500000
    Read through this link. Set it up the same I would think.
    https://www.xsimulator.net/communit...3dof-motor-driver-and-windows-utilities.4957/
  5. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,533
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    145,022Coins
    Ratings:
    +10,775 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Check your Interface Output, as you seem to have an extra character * at the end: R<Axis1a>~L<Axis2a>~

    Like this:

    [​IMG]
  6. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    I'll go ahead and check the link. Thank you
  7. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    It doesnt seem to work with and without the star. The setup is decimal on the thread I was following .
  8. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,533
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    145,022Coins
    Ratings:
    +10,775 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
  9. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
  10. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,533
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    145,022Coins
    Ratings:
    +10,775 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
  11. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Yes it's for a 2DOF . The part I'm having an issue with is doing the axis assignments section or can I leave that part blank, I cant seem to understand how I'm supposed to set that part?
    Sorry for the many questions
  12. noorbeast

    noorbeast VR Tassie Devil Staff Member Moderator Race Director

    Joined:
    Jul 13, 2014
    Messages:
    20,533
    Occupation:
    Innovative tech specialist for NGOs
    Location:
    St Helens, Tasmania, Australia
    Balance:
    145,022Coins
    Ratings:
    +10,775 / 52 / -2
    My Motion Simulator:
    3DOF, DC motor, JRK
    Grab a copy of the SimTools manual and keep it handy for reference: https://www.xsimulator.net/community/faq/rtfm-start-with-the-official-simtools-documentation.117/

    Axis Assignment % totals should be around 100% total: https://www.xsimulator.net/community/faq/axis-assignment-percentage-totals.120/

    Generally you start with something like 20% per axis and configure which way each axis should move: https://www.xsimulator.net/community/faq/which-way-to-set-simtool-axis-movements.230/

    Once that is sorted and everything is working as expected in Output Testing then a motion profile can be configured for a game, see the tips here: https://www.xsimulator.net/community/faq/steps-to-create-a-motion-profile.228/
  13. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    I've tried everything suggested. I ended up giving up after a whole day of trying
  14. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,145
    Location:
    Oklahoma City, USA
    Balance:
    16,574Coins
    Ratings:
    +1,831 / 32 / -1
    From reading the sketch in post 2 it looks like your simtools settings in post 3 should work. I suggest you try using axis setting for output testing from Simtools instead of dof.
  15. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,145
    Location:
    Oklahoma City, USA
    Balance:
    16,574Coins
    Ratings:
    +1,831 / 32 / -1
    If it still doesn't work try using only R<Axis1a>L<Axis2a>. However it looks like anything else in there is just ignored anyway.
  16. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,145
    Location:
    Oklahoma City, USA
    Balance:
    16,574Coins
    Ratings:
    +1,831 / 32 / -1
    Help.jpg
    I got this from my inbox. You must have deleted it though? Are you a quitter?
  17. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    No i didn't lol. a moderator deleted is as spam i think. I'm still gonna continue looking for solutions
  18. BlazinH

    BlazinH Well-Known Member

    Joined:
    Oct 19, 2013
    Messages:
    2,145
    Location:
    Oklahoma City, USA
    Balance:
    16,574Coins
    Ratings:
    +1,831 / 32 / -1
    In any case I was just wondering if you got it going but it appears not. So I looked into it further and while the advice I gave you was accurate now I found a serious logic error in the sketch. It expects to always receive a position value with 3 digits in it. The problem is with decimal output Simtools only sends the minimum number of characters needed so when sending an axis value that's less than 100 it sends less than 3 digits. For example for a value of 1 the sketch wants R001 sent and Simtools sends only R1.
    • Informative Informative x 1
    Last edited: Apr 13, 2021
  19. Abram Manoge

    Abram Manoge Member

    Joined:
    Apr 6, 2021
    Messages:
    46
    Occupation:
    Web developer
    Location:
    South Africa
    Balance:
    319Coins
    Ratings:
    +5 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino
    Mine works but only one servo works now and the second one moves randomly . I just changed Simtools interface to Binary. If you managed to mend the code please forward me a copy