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

2DOF Arduino Mega 2560 school project

Discussion in 'DIY Motion Simulator Projects' started by Marek, Jan 22, 2014.

  1. Marek

    Marek New Member

    Joined:
    Dec 26, 2013
    Messages:
    11
    Balance:
    384Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    Hi my name is Marek, and I decided that I will do 2DOF simulator, as a substitute for final exams at school. I would like to do it through the Arduino but serial port I used only for writing and i do not know how to use it for reading from simtools. Can you help me solve this problem? I have arduino mega 2560. For Motor control I will use L298N. I find here some arduino codes but i need to make it by myself.

    Today I will try to read via i = Serial.read () in Arduino and then write over Serial.println (i), but I just -1.
    Theoretically, it could go right?
    My settings:Axis Assigments
    Interface Settings
    Later i add a photo how i prepare my 2DOF sim and how looks a model of simulator.
    Last edited: Jan 22, 2014
  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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Ok for an example of SimTools talking to an Ard I will show you how I did it with the model, actually another member @aarondc made it way better.

    That controls 2 servos but can be written in a different way to control what ever.
    So you would setup 2 axis like this in the axis assignments:
    1-23-2014 1-34-44 AM.png
    Axis 1 is the Pitch servo and Axis 2 is the Roll Servo and but use 100% of the servos movements.
    Then to talk to the above code I use this in the interface setting except set the comport to what you need.
    1-23-2014 1-37-49 AM2.png
    Ok here you can see Im sending the info to the ard at 9600 and 8,N,1 and in a decimal format at 8 output range ie (0-256).
    Startup tells it to centre the servos, so does the End. Make sure you save before move of any of the sim tools pages too.
    I hope that helps you along the way, I will attach copy of original code to post plus the better more expandable version 2.
    Good Luck.

    Attached Files:

  3. Marek

    Marek New Member

    Joined:
    Dec 26, 2013
    Messages:
    11
    Balance:
    384Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    Thanks. Now i understand how to do it. I try this code on Live for Speed, can i know, which game is better for this code? And what is better, actuator or DC motor.
  4. 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
    Set up your default axis to move the model in the correct way, and this will work with all game plugins from simtools, Tested most games with my model before using the game on the sim.

    Motors V's Actuators. They both have their pros and cons, actuators (SCN5/6) are expensive and can break when setup wrong, Dc Motors are about half the price if you use Jrk which will make them equal a SCN speed and accuracy, yet to see a Ard code on Sim Tools match a SCN5 but its almost 1/3 of the price. So what Im trying to say without being rude to any of the Ard Dev guys, you get what you pay for in quality, more you pay the better the outcome. But SCN's are priced to catch the DIY market and for an almost plug and play(almost as easy as a JRK) for some one with no knowledge of motors, controllers etc, they make a good choice, if a lot cheaper I would probably use them. But have had Jrk sims since 2009 never had a real issue to down them on.
  5. RaceRay

    RaceRay Administrator Staff Member SimAxe Beta Tester

    Joined:
    Nov 8, 2006
    Messages:
    4,656
    Occupation:
    Self-employed | Web and application development
    Location:
    Hamburg, Germany
    Balance:
    23,864Coins
    Ratings:
    +2,007 / 13 / -0
    My Motion Simulator:
    2DOF, DC motor, SimAxe, SimforceGT
    Today i recommend SCN actuators only for seatmover and more important only for peope who do not live in a appartment with neighbours wall to wall. They are way too loud and i had been in real trouble with my neighbours in the past:) DC Motors are much more quiet and give you a equal immersion and feeling.
  6. Marek

    Marek New Member

    Joined:
    Dec 26, 2013
    Messages:
    11
    Balance:
    384Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    Can i ask you, how strong motor i need to use?
  7. 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
    All depends on your construction(rig) for a simple seat mover (easiest and quickest to construct) we have been using 12v 200w motor but been driving them at 30-40amps with no issues to the motors, that will produce enough motion to blur the eyes and rattle the teeth, but some still use slow(20-50rpm) wipers and that produces a lot slower movement but still quiet good to drive on, just not as bone jarring as the big worm gear units.

    In the past I have used 900kg 12v Boat Trailer winches which were a little quicker than the wipers but had tons of torque to play with, which lead me to build a full 2 dof frame with the same fierceness of the big worm gears, only con was they are a little noisy, oh well turn the game sound up and enjoy the ride. They are 300w motors with a about a 400:1 gearbox run through multiply gear sets, where the torque comes from, enough that one member built a 3dof unit with it that had an impressive heave movement too it.

    So really all depends on the construction to what you will need to drive it, the more power the better, I always say, you can always under drive them , easier than risking burning them out when you try and push them.
  8. Marek

    Marek New Member

    Joined:
    Dec 26, 2013
    Messages:
    11
    Balance:
    384Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    This is video from my model. This is video from my model. But i dont know how to set up sim tools, because if i use your settings and code, sim is moving up and down. No move to sides. If I steering with wheel in game sim is without moving.
    Is servo in good position?
  9. 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 if you had used the above settings for the axis assignments then they are wrong to the way that you now have built the model too. You are using combined axis and the above axis setting are for separated axis as in one axis(servo) controls roll and the other controls pitch.
    The correct Axis Assignments to make you model move correctly is as follows.
    correct axis for combined axis movement.png
  10. Marek

    Marek New Member

    Joined:
    Dec 26, 2013
    Messages:
    11
    Balance:
    384Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    Hi, I have problem with simtools. If I am simulating with Axis testing i get both servos up. And problem come if I get slowly down to -21 servo gets to -21° but if i continue to -22 or bellow servo get up to 180°. simtools problem.png
  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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    You using the updated version of SimTools, has a correction in it for the Output Testing. As previous it was a little touchy to use, I normally just test the DOF. But this axis test should work too, Check in the Tuning centre as you move the axis to be sure its an issue with the code or not.
    I need to plug my model in and test this again my self.
  12. 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
    I do apologize for stuff around mate been a while since I used it, been building dashboards and got the processes confused, lol.
    check here.
    http://www.xsimulator.net/community/threads/rc-model-for-motion-simulation.4600/#post-43775
    Simtest works on my model just tested in SimTools.
    Please excuse my bad posting without physically testing it.

    Ok this is the revised code , tested. One is in Debug mode allowing you to use the Serial monitor in Ard IDE enviroment, handy for pre testing.
    Command to test with is Rxxx~Lxxx~ with xxx being a number between 1 - 255.
    Then the other is in SimTools mode ready to run in sim tools with this preset.
    or set it to 8 , N , 1 and decimal with 8bit output.
    Command is R<Axis1>~L<Axis2>~ at 10ms.
    I have tested both with my model, you might have to change the pin out for the servos or the mapping as one servo is mapped the opposite to the other.
    I need to update my original post to these codes , sorry a project that I did over 6 months ago , the post didnt get cleaned up. Sorry man.

    The following zip file contains both codes debug and SimTools ready plus an Interface Settings file which can be imported into SimTools via the Tools - Preset Validator.

    Attached Files:

  13. Marek

    Marek New Member

    Joined:
    Dec 26, 2013
    Messages:
    11
    Balance:
    384Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    Hello. Today I edited your old code, and now everything works as it should. I added to it one more Funck, adjusts the congestion. Thank very much for any help. I think with this i can graduated in matricular exam. Tomorow i share arduino code and some photos.
    • 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,440Coins
    Ratings:
    +1,684 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    Well done glad I could help in the end.
  15. Marek

    Marek New Member

    Joined:
    Dec 26, 2013
    Messages:
    11
    Balance:
    384Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    Hi, there is code.
    Code:
    
    #include <Servo.h>
    
    Servo myservo1;
    Servo myservo2;
    
    int DegreeLS; //Degree measurement for Left Servo (0-180)
    int DegreeRS; //Degree measurement for Right Servo (0-180)
    
    int Gforce = 0; //Gforce Xsim is sending.
    int Gforce1 = 0; //Gforce breakdown ie 123 is 3
    int Gforce10 = 0; //Gforce breakdown ie 123 is 2
    int Gforce100 = 0; //Gforce breakdown ie 123 is 1
    
    char kind_of_data; //The char sent from Xsim ie L or R
    
    void setup() {
    
    //set servo pins
    myservo1.attach(5); //Wire for signal on Left Servo
    myservo2.attach(6); //Wire for signal on Right Servo
    
    //align servos center postision
    myservo1.write(90); // Centre Left Servo
    myservo2.write(90); // Centre Right Servo
    
    //open serial connection
    Serial.begin(9600);
    }
    
    void loop() {
    while (Serial.available() > 0)
    {
    //Lets read the first char
    kind_of_data = Serial.read();
    if (kind_of_data == 'L' ) Read_Leftmyservo2os(); // Ok data is for Left Servo
    if (kind_of_data == 'R') Read_Rightmyservo2os(); // Ok data is for Right Servo
    }}
    
    //To read the Left Servos Gforce and change it to a degree
    //Move the servo to that Degree.
    void Read_Leftmyservo2os(){
    Gforce=0; //Just to be sure Gforce is clear.
    delay(2);
    Gforce100 = Serial.read()-48; // Read the 100's digit
    delay(2);
    Gforce10 = Serial.read()-48; // Read the 10's digit
    delay(2);
    Gforce1= Serial.read()-48; // Read the 1's digit
    
    if (Gforce1 <=9 && Gforce1>=0 && Gforce10 <=9 && Gforce10>=0){
    
    Gforce = (Gforce100*100)+(Gforce10*10)+Gforce1;
    
    DegreeLS = map(Gforce, 0, 255, 180-SilaPretazenia, 0+SilaPretazenia);
    
    myservo1.write(DegreeLS);
    }
    
    if (Gforce1 > 9 && Gforce10 <= 9 && Gforce10 >= 0){
    
    Gforce = (Gforce100*10)+Gforce10;
    
    DegreeLS = map(Gforce, 0, 255, 180, 0);
    
    myservo1.write(DegreeLS);
    }
    
    //To read the Right Servos Gforce and change it to a degree
    //Move the servo to that Degree.
    void Read_Rightmyservo2os(){
    Gforce=0;
    delay(2);
    Gforce100 = Serial.read()-48;
    delay(2);
    Gforce10 = Serial.read()-48;
    delay(2);
    Gforce1= Serial.read()-48;
    
    if (Gforce1 <= 9 && Gforce1 >= 0 && Gforce10 <= 9 && Gforce10 >= 0){
    
    Gforce = (Gforce100*100)+(Gforce10*10)+Gforce1;
    
    DegreeRS = map(Gforce, 0, 255, 0, 180);
    
    myservo2.write(DegreeRS);
    }
    
    if (Gforce1 > 9 && Gforce10 <= 9 && Gforce10 >= 0){
    
    Gforce = (Gforce100*10)+Gforce10;
    
    DegreeRS = map(Gforce, 0, 255, 0, 180);
    
    myservo2.write(DegreeRS);
    }
    
    
    }
    Here is GameEngine
    GameEngine.png
    I added the N and now I know where is the end. In code I add the condition, if is gforce1 bigger than 9 (it is because if i get from simtools L=76-48=28 or N=78-48=30). if a condition is true gforce1=0 and gforce10 is ok and gforce100=gforce100*10. You can add next condition, if gforce10 is bigger than 9. It is for the case where the number of simtools is not a three-digit.
    • Agree Agree x 1
  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
    A little bit of a harder way to do this , will be a little slow though if you decide to increase this too more DOF, I found that out myself and had help to modify the code into something that is a lot faster and easier to increase the DOF.
    I like to run mine at 5-10ms to give a finer detail of motion, the servos are quicker than the code, so to increase the update I did that.
    But a top effort and for 2DOF model should work fine.
  17. Marek

    Marek New Member

    Joined:
    Dec 26, 2013
    Messages:
    11
    Balance:
    384Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    Hi, i got one more question. I found DC motors on 24V but they want 30A. One guy wrote me what i can use this schematic. [​IMG]
    And question is, can it be good if I use mofset on 24V and 30A? I found here this but 80A is much.
  18. Marek

    Marek New Member

    Joined:
    Dec 26, 2013
    Messages:
    11
    Balance:
    384Coins
    Ratings:
    +2 / 0 / -0
    My Motion Simulator:
    2DOF, DC motor, Arduino, SimforceGT, Motion platform
    Hello, after a long time. For the simulator I got at school 1 what is the best that I could. On school-leaving exam did not work yet, but we used 12V 60A engines. During the holidays we want to finish, add some photos soon, certainly video and some informations. Thanks all.