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

Using plugins to drive servo motors

Discussion in 'DIY Motion Simulator Projects' started by hugso, Oct 6, 2013.

  1. hugso

    hugso Active Member

    Joined:
    Sep 17, 2013
    Messages:
    140
    Location:
    Glos UK
    Balance:
    611Coins
    Ratings:
    +51 / 1 / -0
    My Motion Simulator:
    Arduino, Motion platform, 4DOF
    Wow! Thanks for the prompt reply. I can hardly believe my eyes. We have struggled for ages to do this and now it looks as if it will really happen. I will get the Arduiono card and if you can get any of the motions moving my servos I will be absolutely delighted. Maybe there is something I can do for you in return - I hope so.
  2. Hypo

    Hypo Member

    Joined:
    Oct 4, 2013
    Messages:
    50
    Occupation:
    Former cooperate enterprise software developer
    Location:
    Harlow, Essex, UK
    Balance:
    879Coins
    Ratings:
    +24 / 0 / -0
    That sounds cool to me :) I hope Hugso agrees when he catches up with this thread. My sincere thanks to everyone involved.
  3. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,161
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,201Coins
    Ratings:
    +2,164 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    Your code does work with DCS EaoRobbie, I use my desktop R/C servo prototype platform and your sketch to test out new plug-ins before I take them out to my shop to use with my 2DoF rig.

    Both Roll and Pitch work perfectly as does the other four DoF. I swapped out roll and pitch for heave, sway, yaw and surge to test them out as well.

    I have also been tinkering with your sketch to add more servo's, but I will not publishing it, it is your work not mine. I very much appreciate the work that you and Aarondc put into that sketch.

    Hypo/Hugso, I would be willing to bet that your platform is pretty much plug and play with the arduino. If you are using servos to open and close valves in a linear manner (slow movement of the servo in one direction equals slow movement of the DoF in the platform) then it looks like you just need to get an Arduino and wait for Eaorobbie to expand his sketch.

    One warning though, the sketch still has to have the debug function commented out (//) as that had not been changed. With "#define DEBUG 1" left in the sketch sends information only to the Serial Monitor and not to the servos. I chased my tail for a week on that one, until Aarondc pointed it out to me ;)
  4. hugso

    hugso Active Member

    Joined:
    Sep 17, 2013
    Messages:
    140
    Location:
    Glos UK
    Balance:
    611Coins
    Ratings:
    +51 / 1 / -0
    My Motion Simulator:
    Arduino, Motion platform, 4DOF
    This is all very exciting! Yes, the servos open and close valves sure enough, although indirectly as the roll and pitch and heave motions are mechanically integrated to give three control signals (one for each of the three rams). I can post a schematic if you are interested. Not sure I understand about the DEBUG business, but I guess I will before long... Thanks again for the rapid responses.
  5. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,161
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,201Coins
    Ratings:
    +2,164 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    I would love to see your work, yes please do post a schematic.

    As to Arduino coding; I am a novice. Everything I have learned so far has been from the holy trinity; Eaorobbie, Aarondc and RacingMat, lol. :D

    I am sure Eaorobbie will fix the #define Debug 1 issue when he redoes his sketch code. I edited to work with 6 DoF (on my desktop test platform) but I am sure there are issues with my work. Eaorobbie will provide a better version.
  6. RacingMat

    RacingMat Well-Known Member Gold Contributor

    Joined:
    Feb 22, 2013
    Messages:
    2,236
    Location:
    Marseille - FRANCE
    Balance:
    20,975Coins
    Ratings:
    +2,089 / 21 / -2
    My Motion Simulator:
    2DOF, DC motor, Arduino
    @Historiker : "God bless you!"
    If you need some help... :)

    Yes, if the Debug mode is activated, the Arduino speak with the serial monitor (and not to the servos interface) as it has only 1 channel in this configuration.
    Hence you have to disable (comment) the Debug Line in the code if you want to drive yours servos
  7. Hypo

    Hypo Member

    Joined:
    Oct 4, 2013
    Messages:
    50
    Occupation:
    Former cooperate enterprise software developer
    Location:
    Harlow, Essex, UK
    Balance:
    879Coins
    Ratings:
    +24 / 0 / -0
    I couldn't resist it. I have ordered an Arduino Uno board! ;-) I want to see a couple of servos moving when I am flying DCS. On a good day I still dream of flying along in my own gSeat down in my shed :)

    Hugso, don't worry about the DEBUG stuff. I understand what this is about, sort of. I presume the serial line was being used to output info to check if the right data was getting to the micro-controller. We can follow the instructions given to you by the XSimulator gang and get your gSeat flying :)
  8. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,161
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,201Coins
    Ratings:
    +2,164 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
    I can wait until Eaorobbie releases an updated version. I can get up to 5 servos to work at once but not reliably. Not sure what I am doing wrong. Thanks for the offer though.
  9. hugso

    hugso Active Member

    Joined:
    Sep 17, 2013
    Messages:
    140
    Location:
    Glos UK
    Balance:
    611Coins
    Ratings:
    +51 / 1 / -0
    My Motion Simulator:
    Arduino, Motion platform, 4DOF

    Here are two schematics. The three pneumatic rams which support my cockpit are each controlled by a servo motor which operates the air valve. This air valve is simply two simple cheap shut-off valves mounted back to back and a longer lever attached. Moving the lever down opens the air valve and moves the ram upwards. Moving the lever upwards opens the exhaust valve and the ram descends. Because the servo motor is linked to the top of the ram with a stiff wire it moves with the ram so that the ram moves to a given position and stays there. These servo motors are not driven directly from the sim, but via the mechanical integrator. As I hope you can see from the diagram, the pitch and roll servos driven from the sim are connected at 90 degrees to each other by nylon fishing line to a ring. This ring will tilt in both axes and also move bodily up and down driven by the heave (g) servo. On the ring are mounted 3 LEDs which shine onto 3 light dependent resistors on a fixed surface. These 3 resistors control 3 servo drivers which move the servos on the rams. As the ring move up away from the LDRs their resistance changes and the servos on the rams operate the air valves and the ram moves up and vice versa. Same with pitch and roll. The heave servo is linked to the moving ring by an oil-filled piston which allows the ring to wash-out back to the centre position with sustained high g. In other words the movement of the seat mimics the movement of the ring of LEDs. For sway motion the whole seat carried on the rams is mounted on heavy duty drawer runners and a horizontal ram and servo moves it a couple of inches either way. This is driven directly from the sway servo from in game.

    I hope this is of interest.

    Attached Files:

  10. 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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ok fella's busy sorry, Looking for a job, bugger.

    Ok the code needed as noted below drives 2 servos for pitch and roll , lets start simply first, then we can expand it very easily.


    You may have to change the pin outs depending where you hook the signal wires to the UNO.
    For running more than one servo , on a UNO you need to provide extra power to the board via the power socket as the 5v from the usb is not enough to drive the servo's

    Please test without Sim Tools running, with the serial moniter you can send a command at 9600 baud of Pxxx~Rxxx~.
    P = pitch servo and xxx is a value from 1 - 255 which as you can read in the code which then scales the value from 0 - 179 deg.
    R = roll servo and xxx is a value from 1 - 255 which as you can read from the code which then scales the value from 0 - 179 deg.
    Also if you need a different intial starting position this also can be changed too {90,90} sets both servos at 90 deg.

    Once you are happy the code is giving the right values and is moving the rig in the right way , we can proceed to move on and setup sim tools to drive the servos, in turn driving your rig.

    Edit:
    Looking at your above pictures I can see that roll and pitch should work for you , I hope but the g level one is that to control the vertical position of the rig if right I can easily include this in the above code, and control this with heave.
    Let me know you could probably do this your self the code is quite versatile to add another axis too, ie set the extra pin and the starting position and a Letter 'H' for heave and the scaling value you require, Aarondc made it very adaptable, hope for opening this code for 6dof use.
    Last edited: Oct 10, 2013
  11. hugso

    hugso Active Member

    Joined:
    Sep 17, 2013
    Messages:
    140
    Location:
    Glos UK
    Balance:
    611Coins
    Ratings:
    +51 / 1 / -0
    My Motion Simulator:
    Arduino, Motion platform, 4DOF

    Thanks so much for that. As soon as my Arduiono board comes I will have go at getting things moving. I am very grateful for your help.
  12. Hypo

    Hypo Member

    Joined:
    Oct 4, 2013
    Messages:
    50
    Occupation:
    Former cooperate enterprise software developer
    Location:
    Harlow, Essex, UK
    Balance:
    879Coins
    Ratings:
    +24 / 0 / -0
    Hi eaorobbie, sorry to see you are having to look for a new job. I hope your situation improves quickly.

    I should get my Arduino Uno tomorrow. I have downloaded the Arduino IDE and cut and paste your source code into the editor. Will be able to play around with this stuff tomorrow and the weekend. The code looks straight forward to me. Good to see it is a subset of C. I cut my programming teeth on C many years ago. It's good to know C is still being used on modern projects like Arduino. It looks much easier than Microchip PIC programming, which I have played around with and didn't like so much.

    This is the bit where my lack of electronics knowledge lets me down. I initially intend to test the Uno with one servo, testing pitch, I have a Futaba S3003 servo which has black, white and red wires.

    Could you supply a diagram or description where I need to attach each of these wires, please?

    This was the great thing about Phidgets; the boards come with connectors for the devices that are going to be attached and using a high level language, like Java, abstracted the electronics interface so I didn't need any practical electronics knowledge to program servos, stepper motors, switches or whatever. I just needed to know a bit of theory of how each device worked. Sorry for being a bit of dumb ars* in this area, but I am willing to learn :)
  13. Historiker

    Historiker Dramamine Adict Gold Contributor

    Joined:
    Dec 16, 2010
    Messages:
    2,161
    Occupation:
    Retired
    Location:
    Michigan USA
    Balance:
    9,201Coins
    Ratings:
    +2,164 / 19 / -1
    My Motion Simulator:
    3DOF, DC motor, Arduino, Motion platform, 6DOF
  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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    For the above code here is where the signal wire needs to be connected -
    const int kPins[kActuatorCount] = {4, 5}; // pins to which the Actuators are attached

    So with you servos you should have a plug that has a white,red and black, in order white - signal, red - 5v, black - GND.
    Therefore the white goes to 4 or 5 depending on servo, 4 is the pitch servo and 5 is the roll servo.
    And the red and black need to got to the GND and 5v of the UNO

    This will require a power pack to be connected to the UNO as well as the UNO only draws about 50 milli amps from the USB port , only enough power to drive one servo. If not the servo movement will be a little crazy and sometime nothing.

    I have used the exact same servos on another build I did for a fellow member, so there wont be an issue using them.

    And on another note , I never considered anyone as dumb mate, 4 years ago I knew nothing about programming or the uno or Jrks, no one back then at the forum was willing to spend the time, so I read numerous post and hundreds of pages on other websites and taught myself, now always willing to do what others in the past would not, pass on this knowledge so others dreams may become a reality in the world of sims.
    As we grow the knowledge from with in us all grows and our sims become better for all of us.
  15. Hypo

    Hypo Member

    Joined:
    Oct 4, 2013
    Messages:
    50
    Occupation:
    Former cooperate enterprise software developer
    Location:
    Harlow, Essex, UK
    Balance:
    879Coins
    Ratings:
    +24 / 0 / -0
    Thanks for the clear information and thread link. I am hoping the Uno arrives today and I can try it out :)

    As mentioned, I have worked with PIC in the past and until I discovered MikroElectonika, http://www.mikroe.com, getting a micro-controller and devices to do what I needed to do was a bit hard going. When I started using this development environment things started to really get moving. If you have taken the time to learn Wired then learning to use MikroC maybe worth looking at. If you have a custom micro-controller based project you have in mind these products are excellent. As a programmer I was much more comfortable using these kits opposed to the more traditional Microchip PIC development environment. I haven't looked at this stuff for a while and it is good to see MikroElectronika are now making an ARM solution; http://www.mikroe.com/easymx-pro/stellaris/. Really cool stuff.

    Thanks for the kind words about not being dumb. I don't mind asking simple questions, like where a wire goes. It saves me some time which I can better use programming. This is where my skills are. Hugso is the electronics and mechanical expert. Usually I would ask him, but he hasn't got his Arduino yet. I have gone ahead and got an Arduino Uno not solely for myself, but to assist Hugso with the micro-controller side of things. I am comfortable with micro-controller programming and, as you say, it is much better for all of us if we share the knowledge we have. I am looking at this long term. One day I would like to build my own motion platform and I would base it on the gSeat concept. If I can contribute to making gSeat work with DCS, CoD, rFactor... then it is my interest to do so.

    And it is good fun too :)
  16. 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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    To me air actuation is way to slow and cumbersome but if some wants to use it then why not. From my 4 years of building sims I have tried every method but the way he does it is a new way of thinking , something that is welcome here indeed.
    I'm an Ard user cause of one simply reason is it is totally open source and they even provide schematic if you choose to build your own and not use their pre built boards. I actually prefer the Freetronics boards here in Australia and can be bought at any good hobby electronic store plus their forums are very helpful. Not say the others are not. Will take a gander at them, Thanks.
  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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Right your first comment is sort of correct, because sim tools doesnt communicate both ways in Serial unless a interface plugin is created , the return serial information will eventually lock up the Ard communication port.
    But second is totally wrong.

    The debug allows you to view what the the Ard is working out, ie the value you sent , how it then scales the value to a value the servo can use. As well the servos will move to this scaled value. In order to let another program (Sim Tools) to communicate properly this comment needs to be "//" commented out so it doesnt call the debug function and lock up the serial port. This is actual a new process that Aarondc showed me and I know use it in all my Ard code, makes for powerful debuging of code.
    • Like Like x 1
  18. Hypo

    Hypo Member

    Joined:
    Oct 4, 2013
    Messages:
    50
    Occupation:
    Former cooperate enterprise software developer
    Location:
    Harlow, Essex, UK
    Balance:
    879Coins
    Ratings:
    +24 / 0 / -0
    Had a look at your YouTube video of your R/C model in action. I can understand why you would need a quick reacting platform for racing simulators. You've really done your homework over the years and know what works best. Have you got any videos posted of your full size simulator in action?

    There are a lot of solutions out there. I really like the Arduino stuff because of the Open Source nature. This would make life easier if someone decided to sell a motion simulator based on Arduino. The MikroElectronika kits are for prototyping work. If it got to the stage where the development work was done one would have to consider having custom boards manufactured. This is where it gets expensive and in my experience can all go wrong.

    My Arduino has just arrived. Going to have a go at plugging it in and giving your program are try. I will let you know how I get on :)
  19. 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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ok

    Is a camera mounted to the back of the chair mount is very secure so you can see the speed of the gear changes. Very quick jolt, measured at 700mm/s.

    This shows better the speeds and accuracy of the motors.
  20. Hypo

    Hypo Member

    Joined:
    Oct 4, 2013
    Messages:
    50
    Occupation:
    Former cooperate enterprise software developer
    Location:
    Harlow, Essex, UK
    Balance:
    879Coins
    Ratings:
    +24 / 0 / -0
    Great videos! Thanks for that. Really shows your simulator rocking along ;-)

    Been playing with the Uno today. I have got the simple servo Sweep example working with one servo. eaorobbie, I have tried uploading your program, but get this error message; request for member 'attach' in 'actuatorSet', which is of non-class type 'Servo [2]' in the orange message area of the IDE and the compiler blows out with these compiler messages;

    gSeat.ino: In function 'void setup()':
    gSeat:37: error: request for member 'attach' in 'actuatorSet', which is of non-class type 'Servo [2]'
    gSeat.ino: In function 'void serialEvent()':
    gSeat:66: error: ISO C++ forbids comparison between pointer and integer

    There may be a simple answer to this; do I need to have two servos attached?

    I spoke to Hugso earlier and we worked through getting the Sweep example working and making sure the IDE was set up and working properly.

    Hugso has now attached two servos, as per your diagram, and gets the same error messages when he tries to verify or upload your program.

    I have not attached two servos, yet, because I need to get my soldering iron out and start practising to use it again. Its been a while since I've done any soldering :-/ Hugso is ahead of me here because he is the electronics guru :)

    TIA for your assistance. Sorry to have to ask for your help so soon, but Hugso and I are very eager to see the servos working with your program and the Uno.