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. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,390Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    This was my first step in building a sim.

    I decided to build an RC model so that I may learn how to use the software and develop a motion sim.

    Components include:

    2x Futaba FP - S148 RC Servo's.
    4x Clevis's to suit RC Servo Horns.
    2x Rod to suit clevis's.
    1x Uni Joint for 3/8 Socket (cheapest uni joint I could find).
    1x 1.6mm zinc sheet (main box to mount servos in and top for model to sit on).
    1x Ardunio UNO R3.
    1x 6v power pack.
    Some patching wire to connect servos to Arduino.

    Ok from here I bent I cut 2 squares out of the 1.6 zinc to create to open top boxes with the dimensions of 225x225x10 (Top for model to sit on) and 255x255x80 (box to house servos and Ard. )

    RC Sim Model.jpg

    From there I welded the uni joint in between the two as per my google sketch.
    Now the top moves as a sim base would, I cut in and inserted my servos as per my sketch, position them so that a connecting rod from the servo horns to the top tray are near vertical.
    Then I created a rod with two clevis to join the servo horn to the top tray.
    Wired the servos to the Ard as below

    RC Sim Model_bb.jpg
    Not shown is power pack attached to Ard. to help with the amp draw of running two servos and the usb cable to run the model from Sim Tools

    Ok from here I needed to write a custom code to drive the servos with the commands Sim Tools will send it

    RC_Sim_Model.zip

    Then set up Sim Tools to drive the servos in game.

    Pics of Sim Tools set up.



    Everything rewritten for Sim Tools no longer usable in X-Sim3.
    • Like Like x 11
    • Informative Informative x 2
    Last edited: Oct 10, 2013
  2. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,390Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    All updated with code and wiring.
    Sim Tools ready.
    • Like Like x 2
    • Informative Informative x 1
  3. mario318i

    mario318i New Member

    Joined:
    Oct 24, 2012
    Messages:
    13
    Location:
    Wieselburg/Austria
    Balance:
    88Coins
    Ratings:
    +6 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, Arduino, JRK
    Nice job, buddy! :D
  4. bsft

    bsft

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    groovy
  5. yobuddy

    yobuddy Well-Known Member Staff Member Moderator SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Feb 9, 2007
    Messages:
    5,133
    Occupation:
    Computer Technician
    Location:
    Portland, Oregon - USA
    Balance:
    47,903Coins
    Ratings:
    +5,027 / 16 / -0
    Very Cool!
  6. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    Great work, mate. This is going to be my next step, I think. About to put in an order for some servos, etc.
  7. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    Will Sim Tools handle more than 2 actuators?
  8. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    And can I ask which language Sim Tools is being developed in?
  9. value1

    value1 Nerd SimAxe Beta Tester SimTools Developer Gold Contributor

    Joined:
    Jan 9, 2011
    Messages:
    2,184
    Location:
    Zug, Switzerland
    Balance:
    14,460Coins
    Ratings:
    +3,318 / 11 / -1
    My Motion Simulator:
    2DOF, DC motor, JRK, Joyrider
    SimTools can hanlde up to 6 actuators. It's written in VB.
  10. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    If I am way out of line here, I apologise in advance. Would be very curious if the following code worked with your current setup, Rob.


    Here's quick debug that tells me it's not doing anything stupid:

    [​IMG]

    That last servo position is L 17 - wasn't sure if you were padding with spaces or 0s but either seem to work.
  11. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,390Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    No padding used in code. My code is quite simple but you need to note that the ard receives R255 as R , 2 , 5 , 5 , all as single characters as so can see by my code I capture each one after a char is received and rephrase it back to a whole number in the ard ie get 255 as its set position and then map this from 0,179 before moving the servos.

    Your method is good thou, I will have a look at it on the weekend and do a test through sim tools, I feel a 6dof model build on the way from ya, go for it. My next model will be a 3dof with no centre support to test a theory before building the bigger one.

    Thanks for ya input, got me thinking.....
  12. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    Yep, the screen shot I posted shows I used the following as a dummy Serial port send: R000L000R255L255R123L 17

    The main difference between our code is I don't use pause(), and you should be able to modify it up to (1..n) actuators just by changing the constants at the top of the file, everything else stays the same. Otherwise it does essentially the same thing.

    I didn't want to step on your toes by posting it - you're helping me out with everything else, so if I can contribute some code after doing it professionally for some 21 years, it's purely as an attempt to give something back.

    Look forward to your next rig and theory testing :D
  13. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,390Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ya not stepping on toes mate more than welcome this will better my understanding of code for the setup I have.
    Not only benefitting me but the whole community in a good way.

    I will run a test soon and report back to ya , Thanks again for your interest, all point taken positively, :cheers:
    I have only be coding ard's for 2 years playing with digital dashboards, and welcome every bit of new found information with open eyes. :thbup:
    • Like Like x 1
  14. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,390Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    No code doesn't work once sim tools fires up they move erratically without a command being sent.
    Could be the serial println causing the error I had to comment them back out once i connected this to sim tools, mmm I have a lcd shield, gives me an idea.

    No even just using serial monitor no go. Only moves one servo but i have just copied and paste code, need to find some time to troll through it. To me the error is in how it reads the value in, no padding used in simtool, ie R1 is not sent as R001 ?

    P.s Yes its your char count needs a routine in there that counts how many digits are avail before the next char and then process that, not sure how too sorry, I have done this before with arrays in my dashboard code for xsim, hopefully coming to sim tools eventually. If you could make the changes I will retest for you and if all is well can I attach it to my first post with big thanks and credits to your changes and make it RC Sim Model V2. Thanks in advance.
  15. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    Sure thing. I will need to understand how the SimTools send works. Can you please confirm:

    If right servo is being set to 7, what gets sent?
    * R7
    * R 7
    * R007
    ?

    If it's left being set to 10, what gets sent?
    * L10
    * L 10
    * L010
    ?

    In your code, you read in 3 values, separated by pause(2), no matter what. Does that mean there is nothing there and you are reading in 0 (NULL)? I had not considered that that was the case, and had assumed you always send 3 chars. If this is wrong, how do you know when the servo data has finished being sent?

    Also, is the actuator data sent for the full sim - ie all actuator data sent each time, or one actuator at a time with a pause in between? If the sim is meant to move to a new position, say

    LEFT = 1
    RIGHT = 75

    And you send R75L1

    Your code (post #1) would read in
    R --> we're doing the right servo. bu then it would read
    75L
    as the RIGHT servo value, and convert it to numbers, maxing out at 255 each time (7 x 100 + 5 x 10 + 28 = 778 maps to 255 --> 179 or 0 limits).

    Then there would only be a 1 left in the serial buffer, which would be discarded when you read in the next char and look for 'R' or 'L'.

    There's 2 ways of doing it:
    1. delimited data. eg [R75~L1~]
    2. fixed width data. eg [R 75L 1] (what I assumed was happening, due to your 3 x Serial.read() calls)

    If you're not doing it either of these ways, I would be interested in learning how you get data transmission happening reliably.

    Unless.. I have it completely wrong, once again assuming how you are talking to the Ard.

    Ok, finaly question :)

    Can you tell me the timing for sending data? eg if you had to move both acutators to R=75, L=1, what is the timing between:

    R then 7 then 5
    then
    L then 1
    ?

    I had a couple of ideas to make the code even more generic - despite what I said previously, you would need to add code to make it work with more actuators. If we get this timing / data sorted, I am happy to update the code and add some other improvements down below to make it better there too.

    Am very curious why it was moving when Sim tools was sending no data at all. Again, should be working just like yours does.

    Feel free to PM me if you don't want to answer the questions above in the thread.

    Ooh ooh, one more question. Can you tell me what the actuators are called for say 6DOF and 3DOF? I'll add comments in the code for adapting the code for those 2 setups as well if you like.
  16. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    Sendng R123 will take 3.75ms at 9600 baud.
  17. eaorobbie

    eaorobbie Well-Known Member SimTools Developer Gold Contributor

    Joined:
    May 26, 2009
    Messages:
    2,574
    Occupation:
    CAD Detailer
    Location:
    Ellenbrook, Western Australia
    Balance:
    20,390Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ok simular situation as when using xsim you set a packet of Rxxx Lxxx where xxx is a value between 0 - 255 and does this every 20ms.
    ie to move the left servo to 90deg (level) xsim sends L127 and to 0deg it send L0.

    The above string is read by the ard a char at a time ie R, x, x, x, L, x, x, x every 20ms.
    Another way would be below but send Rxxx Lxxx E and then phrase the arrays into the needed result then move the servos according to result then read another complete array. I do this in my dashboard code.

    Suppose my code is not that great what actually happens is that now again you loose 1 set of data when it falls bellow 10 for a cycle but with flow control ie pauses in code and packet rate you send the data at, this can be controlled, ie I found that at 20ms intervals with pauses in the reading of the data resulted in the right data being captured all the time. This took a bit of testing but to do this better we can send a char to stop reading process and read the next ??? ie Rxxx E Lxxx E so when the array reads a R it knows to read in chars till it reads a E then it knows it has all the data right and processes it and then reads the next char to find the next servo to position until it reads an E and processes the position and the cycle starts again.
    To me this would ensure no loss and the ability to run it a lot faster.

    To move past 2 dof with this code ie 3dof we will just have 3 axis, two control roll and pitch and heave together and the third just controls pitch and heave. So its data packet would be R<Axis1> L<Axis2> B<Axis3> as in Right for Right , L for Left and B for Back. (just my thought) or If the single axis is in Front an F, to keep it simple we could turn list into A,B,C.

    Hope that clarifies what it does.
  18. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    Sounds good mate. As a suggestion, make the delimiter something like ~ or ! or one of those characters. Allows you to keep letters for meaningful names, like you already have with R for right and L for left, B for back, F for front, etc. The mcu doesn't care and neither does Sim Tools, but as you know, debugging is where the sweat happens, and if you can look at something and say

    E100

    ahha that's Elevation 100 but the rig isn't elevating, then it's much easier than running out of letters and having to look up a chart or similar heheh :D

    As for your code not being great, I will only say this (and I mean it, I'm not someone who sucks up, and meant no disrespect by my last post): you wrote some code and it worked. And if my experience in the field of software development means anything, I can say beyond a shadow of doubt, that working code is worth it's friggin' weight in diamond encrusted, platinum plated gold bars. Your code was perfect because it worked. There's more than a few multi-million dollar software systems that were scrapped because they did not work. (eg: $100M system scrapped - http://www.informationweek.com/sap-soft ... /207000149)

    I'll bash something out now. I just finished mucking around with a couple of NRF2401L+ transceivers and they're working so I'm in a good programming mood :D
  19. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    Ok new version uploading now.
    Modifications include:

    * defined DEBUG for the Serial debug lines. comment out the line to remove the debug from the code
    * renamed all servo variables (and comments) to actuator so it's a bit more generic when you're reading the code and comments
    * created an array of actuator names or identifiers (like R, L, etc) so nothing is hard coded in the processing part of the app
    * replaced hard coded references to actuator indexes or names with for loops
    * set delimiter at the top and check for it in the code. also checks for max of 3 chars for value
    * very simple range checking on actuator value chars. anything not from 1 to 9 gets treated as a 0.


    The test string I sent the new code: L0~R0~L255R255L9~R123
    L0~
    R0~
    L255
    R255
    L9~
    R123

    Note that the values that are 3 chars long work without the delimiter, as it stops reading value chars after 3 chars read.

    As you can see from the test output, the code appears to be working.
    [​IMG]

    Attached Files:

  20. aarondc

    aarondc Member

    Joined:
    Jun 12, 2013
    Messages:
    133
    Location:
    Melbourne, Australia
    Balance:
    186Coins
    Ratings:
    +7 / 0 / -0
    Here's the code:

    • Like Like x 1