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 miniature motion platform w 2-servos

Discussion in 'DIY Motion Simulator Projects' started by jamesdio, Oct 13, 2011.

  1. jamesdio

    jamesdio Member

    Joined:
    Feb 4, 2009
    Messages:
    66
    Location:
    Seoul, Korea
    Balance:
    763Coins
    Ratings:
    +59 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, AC motor, SCN5, SimforceGT, Motion platform, 4DOF
    Hi. Every X-SIMMERS.

    This is Jason from Korea.
    I'd like to introduce my work in process to bulid wiper motor based motion simulator.
    This miniature is just the first step.

    I'll post arduino source codes and X-Sim profiles later.



    This is an arduino miniature motion simulator which is going to be scaled up to wiper motor powered one such as DERIY(SATO)

    2dof-wiper-motor-car-simulator-by-deriy-sato-...

    or ua6aak
    2dof-simple-wipermotor-chair-by-ua6aak-t2512-...

    these guys fantastic work inspires and motivates me!
    of course there are many masters such as Thanos, SirNoName and so on...sorry i can't remember the others.. :(
    and also big thanks to them!
    If there were no their awesome works, I've naver ever tried to build a homebrew motion simulator even thought of it :(

    it'll be a step by step process which is following Thanos work for AMC, DSMhb and take quite some time.
    because, I have no idea on electronics.
    So, I have a lot of things to learn to build homebrew motion sim.

    Honestly I'm having a hard time to gathering information regarding building Motion simulator and to find the place to buy necessary parts in Korea.

    Hope for the success!

    Sorry for my english.

    Regard Jason.


    P.S. I have one question for those who know about current consumtion of 2 wiper motors with load.
    I'm going to use my old ATX pc power supply which is 510W with 12V-34A (38A peak-single rail) as a PSU for 2 wiper motors.
    The image of my PSU specs is attached.

    Can one ATX power supply handle 2 wiper motors with load?

    Attached Files:

    Last edited: Nov 8, 2016
  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,398Coins
    Ratings:
    +1,683 / 23 / -2
    My Motion Simulator:
    2DOF, DC motor, JRK, SimforceGT, 6DOF
    should be ok mate but ya could use one per motor.
    Well done on mini. Time to build the real thing because i dont think it would last if ya sat on it, lol, sorry could help myself.
    Well Done, Ask away.
  3. bsft

    bsft

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Yes a great job there, well done.
    Can you please share the code?
    Also power supply, yes one each per motor would be sufficient. Otherwise run one power supply in parallel with a car battery for both motors. Several of us use that set up. Good to handle big spikes in current draw.
  4. jamesdio

    jamesdio Member

    Joined:
    Feb 4, 2009
    Messages:
    66
    Location:
    Seoul, Korea
    Balance:
    763Coins
    Ratings:
    +59 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, AC motor, SCN5, SimforceGT, Motion platform, 4DOF
    thank you guys for the answers.

    Normally, a car wiper motor(DC12V-30W) consumes 10A on its specification.

    but I learned before that P = VI,
    then 30W = 12V * y A.

    Therefore
    y = 2.5 A.

    is that right?

    if it's right, one PSU can easily handle 2 wiper motors
    So, I thought one PSU can handle 2 wiper motors w a payload of nearly 130kg.

    if I'm wrong,
    I should buy a car battery or another PSU. :(

    plz correct me if I'm wrong.
    Thanks in advance

    Anyway, Here is my code.
    the origin source codes come from herctrap and juiou.

    Many thanks to herctrap, juiou and their source codes. :clap:

    Code:
    
    /*
     * 2DOF Motion Platform with 2 Servos
     * -------------------------------------
     * Thanks to herctrap and his source
     * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1280139142
     * 
     * and also thanks to juiou and his source
     * http://www.x-simulator.de/forum/arduino-and-x-sim-t2773-30.html
     *
     * I just combined their sources.
     * 
     */
     
    #include <Servo.h>
     
    Servo myservo1;
    Servo myservo2;
    
    int Degree;
    int Gforce = 0;
    int Gforce1 = 0;
    int Gforce10 = 0;
    int Gforce100 = 0;
    
    char kind_of_data;
    
    void setup() {
      
      //set servo pins
      myservo1.attach(2);
      myservo2.attach(3);
      
      //align servos center postision
      myservo1.write(90);
      myservo2.write(90);
      
      //open serial connection
      Serial.begin(115200);
    }
    
    void loop() {
    
      // wait for serial input (min 3 bytes in buffer)
      while(Serial.available() > 0) {
        
        kind_of_data = Serial.read(); //string from USO --> L~a01~ R~a02~ 8bit resolution\decimal output
        if(kind_of_data == 'L') {
          Read_Pos(kind_of_data);
        }
        if(kind_of_data == 'R') {
          Read_Pos(kind_of_data);
        }
      } 
    } 
        
    void Read_Pos(char which_servo){
      delay(2);
      int Gforce100 = Serial.read()- '0';
      delay(2);
      int Gforce10 = Serial.read()- '0';
      delay(2);
      int Gforce1 = Serial.read()- '0';
      
      //Verifica se e centena dezena ou decimal... =]
      if (Gforce1 < 0) { Gforce = Gforce10 + 10*Gforce100; }
      if (Gforce1 < 0 && Gforce10 < 0) { Gforce = Gforce100; }
      if (Gforce100 < 0) { Gforce = 127; }
      if (Gforce1 >=0 && Gforce10 >= 0 && Gforce100 >= 0) { Gforce = 100 * Gforce100 + 10 * Gforce10 + Gforce1; }
    
      if (which_servo == 'L') {
        Degree = map(Gforce, 0, 255, 180, 0);    
      }
      if (which_servo == 'R') {
        Degree = map(Gforce, 0, 255, 0, 180);
      }
    
      if (which_servo == 'L') {
        myservo1.write(Degree);
      }
      if (which_servo == 'R' ){
        myservo2.write(Degree);
      }
    }
    
    
    • Agree Agree x 1
  5. bsft

    bsft

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Hello dude, in regards to power supplies and wiper motors.
    When a wiper motor is doing what it usually does, that being turn one way to swing a wiper arm, it draws a quick bit of high current to start it then uses a little bit after that.
    Example being an air-conditioning compressor. Mine is 9kw cooling, so when I start it up, it draws 72amps for about 1/2 second and then 10-12amps running after that.
    A wiper motor constantly having its direction and speed changed draws a LOT more current than what it lists as actually using. A safe bet would be to use either one psu per motor, or use one psu wired in parallel with a decent size car battery. I use a cheap 500w pc psu, which really runs more like 330w (it runs about 18amps on 12v) and a second hand car battery rated at 330cca. The two of them together handle the spikes of 22amps through my JRK controllers very well. I run two motors.
    Also, thanks for sharing the code. :clap:
    Cheers, David.
  6. jamesdio

    jamesdio Member

    Joined:
    Feb 4, 2009
    Messages:
    66
    Location:
    Seoul, Korea
    Balance:
    763Coins
    Ratings:
    +59 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, AC motor, SCN5, SimforceGT, Motion platform, 4DOF
    Thank you bsft for your kind answer.
    Now I can see in power consumption of motors more then before.

    Anyway does the spikes you wrote mean peak current?

    In your case the power consumption of 2 wiper motors is 264W(=12V * 22A) at maximum.
    Am I wrong? 22 amps in each?

    If the spikes of 22A is for 2 wiper motors, There is one thing I can't understand is that My PSU which can handle 12V-34A(510W) on the average, 12V-38A(650W) at peak is not enough to turn 2 wiper motors on in severe situation you said.

    I think the spikes of 22A is quite lower than the capacity of my PSU, 34A.

    sorry for bothering you to explain.
    Thanks in advance.

    Regard, Jason.
  7. bsft

    bsft

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
    Hello Jason, sorry, I'd better explain myself better. Yes I mean peak current, in this case my boards are set at 22.5 amps peak, each. I can go up to 30amps, but they would stress the boards.
    Yes I mean 22amps per motor. So perhaps allow up to 50 amps total. My suggestion would be to use your power supply with a car battery in parallel. This will cover peak current bursts and perhaps save a few dollars in getting another power supply.
    With the motion, if you harden up the motion or add more forces, you add more power needed, hence the higher current needed.
    It took me ages to figure out power requirements and cost to do it. Eaorobbie, suggested a car battery in parallel with my current power supply. It works a dream. I got a good second hand battery for $30, and modified a pc psu $40, cheap overall and very effective.
  8. bsft

    bsft

    Balance:
    Coins
    Ratings:
    +0 / 0 / -0
  9. juniou

    juniou New Member

    Joined:
    Jan 8, 2011
    Messages:
    12
    Location:
    Brazil
    Balance:
    271Coins
    Ratings:
    +0 / 0 / -0
  10. BartS

    BartS Member

    Joined:
    Oct 10, 2010
    Messages:
    156
    Balance:
    417Coins
    Ratings:
    +5 / 1 / -0
    Hi,
    To do this you are going to need a fixed time base for the PID, the way to do it is to set the PID sample time to 0 and run an interrupt timer of a chosen period on the PID. This is the hard part as you will have to work out how long everything takes to execute and build your timebase from there.
    Bart
  11. shomi87

    shomi87 New Member

    Joined:
    Nov 7, 2011
    Messages:
    10
    Location:
    Serbia
    Balance:
    57Coins
    Ratings:
    +0 / 0 / -0
    This is really good idea, i was thinking about it too. I don't have H-bridge and motors now but i think this code for arduino could work that job. Of course it will need some more tuning but this is a simple code. I was reading about two or more PID in interrupts and it can make some problems , but who knows.

    Sorry on my English if i have some errors. :D

    Code:
    /*
    * 2DOF Motion Platform with 2 Servos
    * -------------------------------------
    * Thanks to herctrap and his source
    * http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1280139142
    * 
    * and also thanks to juiou and his source
    * http://www.x-simulator.de/forum/arduino-and-x-sim-t2773-30.html
    *
    * I just combined their sources.
    * 
    */
    
    
    #include <PID_v1.h>
    
    
    double Setpoint1, Input1, Output1,Input1T;
    double Setpoint2, Input2, Output2,Input2T;
    PID myPID1(&Input1, &Output1, &Setpoint1,2,5,1, DIRECT); //L motor
    PID myPID2(&Input2, &Output2, &Setpoint2,2,5,1, DIRECT);//R motor
    
    int Degree;
    int Gforce = 0;
    int Gforce1 = 0;
    int Gforce10 = 0;
    int Gforce100 = 0;
    
    char kind_of_data;
    
    void setup() {
     
      //initialize the variables we're linked to
      Input1T = analogRead(0); // read from Lpotentiometer
      Input1=map(Input1T, 0, 1024, 180, 0);    // map that value in degrees
      Setpoint1 = 90;
      //turn the PID on
      myPID1.SetMode(AUTOMATIC);
      
      Input2T = analogRead(2);
      Input2=map(Input2T, 0, 1024, 0, 180);    
      Setpoint2 = 90;
      //turn the PID on
      myPID2.SetMode(AUTOMATIC);
      
      //open serial connection
      Serial.begin(115200);
    }
    
    void loop() {
    
      // wait for serial input (min 3 bytes in buffer)
      while(Serial.available() > 0) {
        
        kind_of_data = Serial.read(); //string from USO --> L~a01~ R~a02~ 8bit resolution\decimal output
        if(kind_of_data == 'L'|| kind_of_data == 'R')
        {
          Read_Pos(kind_of_data);
        }
      } 
      
      
      Input1T = analogRead(0);
      Input1=map(Input1T, 0, 1024, 180, 0);
      Input2T = analogRead(0);
      Input2=map(Input2T, 0, 1024, 0, 180);
      myPID1.Compute();
      myPID2.Compute();
      
      if(Output1<0)
          digitalWrite(1,LOW); //for - direction
        else
          digitalWrite(1,HIGH);//for +direction
      analogWrite(3,abs(Output1)); // PWM signal to H-bridge1 for rotatin impulses
      
      if(Output2<0)
          digitalWrite(2,HIGH);
        else
          digitalWrite(2,LOW);
      analogWrite(9,abs(Output2)); // PWM signal to H-bridge2 for rotatin impulses
      
     // The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles.
     // This is because of interactions with the millis() and delay() functions, 
     //which share the same internal timer used to generate those PWM outputs.
    // This will be noticed mostly on low duty-cycle settings (e.g 0 - 10)
    //and may result in a value of 0 not fully turning off the output on pins 5 and 6.
      
      
    } 
        
    void Read_Pos(char which_servo){
      delay(2);
      int Gforce100 = Serial.read()- '0';
      delay(2);
      int Gforce10 = Serial.read()- '0';
      delay(2);
      int Gforce1 = Serial.read()- '0';
      
      //Verifica se e centena dezena ou decimal... =]
      if (Gforce1 < 0) { Gforce = Gforce10 + 10*Gforce100; }
      if (Gforce1 < 0 && Gforce10 < 0) { Gforce = Gforce100; }
      if (Gforce100 < 0) { Gforce = 127; }
      if (Gforce1 >=0 && Gforce10 >= 0 && Gforce100 >= 0) { Gforce = 100 * Gforce100 + 10 * Gforce10 + Gforce1; }
    
      if (which_servo == 'L') {
        Degree = map(Gforce, 0, 255, 180, 0);    
        Setpoint1 = Degree; //new setpoint
      }
      if (which_servo == 'R') {
        Degree = map(Gforce, 0, 255, 0, 180);
        Setpoint2 = Degree;
      }
    }
    
  12. jamesdio

    jamesdio Member

    Joined:
    Feb 4, 2009
    Messages:
    66
    Location:
    Seoul, Korea
    Balance:
    763Coins
    Ratings:
    +59 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, AC motor, SCN5, SimforceGT, Motion platform, 4DOF
    Hi, shomi87.

    I ordered electronic parts for Thanos's Dual H-Bridge yesterday.
    As soon as I get DSMhb work, I will try to complie and test your source code with my arduino motion simulator.

    Thank you for your source

    Regard Jason.
  13. shomi87

    shomi87 New Member

    Joined:
    Nov 7, 2011
    Messages:
    10
    Location:
    Serbia
    Balance:
    57Coins
    Ratings:
    +0 / 0 / -0
    Hi. I am glad because this topic is not dead. I am not sure about this code, and i will work on it.
    I dont know how you setup your profile and how x-sim software works, what is its output to arduino, but i just recode your code.
    what is with that Gforce calculation?
    I understand that you calculate movement for step motors in degrees and i try to convert that in pwm impulses and direction. Maybe you have better idea?
    That mappings i use I am not so sure about them :(

    This is nice idea and i hope we will make some progress.

    Best wishes from Serbia :)
  14. shomi87

    shomi87 New Member

    Joined:
    Nov 7, 2011
    Messages:
    10
    Location:
    Serbia
    Balance:
    57Coins
    Ratings:
    +0 / 0 / -0
    I had a little time and play with PID library. I write code that simulate controlling one motor. I change PID library from Arduino site. I think this is good code. What are you think about it?

    Code:
    #include <PID_v1milos.h>
    
    /********************************************************
     * PID Basic Example
     * Reading analog input 0 to control analog PWM output 3
     ********************************************************/
    
    
    
    //Define Variables we'll be connecting to
    double Setpoint, Input, Output;
    
    int i;
    int Gforce = 0;
    int Gforce1 = 0;
    int Gforce10 = 0;
    int Gforce100 = 0;
    
    PID myPID(&Input, &Output, &Setpoint,2,0.05,0.25, DIRECT);
    
    void setup()
    {
      //initialize the variables we're linked to
      Input =90;
      Setpoint = 90;
    
      //turn the PID on
      myPID.SetMode(AUTOMATIC);
      Serial.begin(9600);
    }
    
    void loop()
    {
      if(Serial.available() > 0)
       {
         char tip;
         tip=Serial.read();
    
        delay(2);
        int Gforce100 = Serial.read()- '0';
        delay(2);
        int Gforce10 = Serial.read()- '0';
        delay(2);
        int Gforce1 = Serial.read()- '0';
        
        if (Gforce1 < 0) { Gforce = Gforce10 + 10*Gforce100; }
        if (Gforce1 < 0 && Gforce10 < 0) { Gforce = Gforce100; }
        if (Gforce100 < 0) { Gforce = 127; }
        if (Gforce1 >=0 && Gforce10 >= 0 && Gforce100 >= 0) { Gforce = 100 * Gforce100 + 10 * Gforce10 + Gforce1; }
         
        if(tip == 'p') //simulate reading potentiometer value with manual inputting potentiometer value in console in format pxxx
        {
            //i=0;
            Serial.println(InputX:  );
            Serial.println(Gforce);
            Input=double(Gforce);
        }
    
        if(tip == 's') //simulate setting new setpint value from PC with manual inputting  value in console in format sxxx
        {
            Setpoint=double(Gforce);
            Serial.println(Setpoint:  );
            Serial.println(Setpoint); 
        }
         
       }
       
       
      //if(i<10)
      myPID.Compute();
      
      while((Input<Setpoint-1 || Input>Setpoint+1) && Output!=0.0)
      {
        Serial.println(Input:  );
        Serial.println(Input);
        
        {
          myPID.Compute();
        
            Serial.println(output: );
            Serial.println(Output);
            
          if(myPID.smer==1) // myPID.smer tell us in what direction motor should turn
            Input+=Output/10; //simulate motor turning and potentiometer new value
            else
             Input-=Output/10;
             
            Serial.println(Input:  );
            Serial.println(Input);
            Serial.println(Direction);
            Serial.println(myPID.smer);
            Serial.println(----------------);
         }
         
      }
      
    }
    
    
    
    when you read potentiometer value you should MAP it from 0 to 180.
    same thing you should do with values that PC sends to Arduino.

    Here is my modded library :D

    Attached Files:

  15. shomi87

    shomi87 New Member

    Joined:
    Nov 7, 2011
    Messages:
    10
    Location:
    Serbia
    Balance:
    57Coins
    Ratings:
    +0 / 0 / -0
    @jamesdio Can you explain me how to setup x-sim profile to work with arduino? I tried something but i am not sure about it?

    What values you get from game ? x,y axes ?
    Where we should mix x and y axe , arduino or x-sim?
    Are you sending x values to one motor and y values to another or you should mix x,y values and then separate to two motors?
  16. jamesdio

    jamesdio Member

    Joined:
    Feb 4, 2009
    Messages:
    66
    Location:
    Seoul, Korea
    Balance:
    763Coins
    Ratings:
    +59 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, AC motor, SCN5, SimforceGT, Motion platform, 4DOF

    @shomu87 Sorry for the late reply.

    Above all, thank you for your source code.

    Here're the answers.

    1. I got the G-force values and Car ratations from game such as lateral, vertical, longitudinal forces and roll, pitch, yaw.
    2. We should mix x, y axis on X-sim with profile setup attached below.
    3. I'm sending mixed x,y values to arduino for operating 2 wiper motors.



    I can't wait for testing your source code but I haven't made DSMhb yet :(

    Anyway I also hope we can make it work together.
    and I'm really happy for your big help! :thbup:

    Sorry for my english.
    Do I make myself clear? :)

    p.s. Here's my x-sim profile for arduino w/ 2 servos.

    Attached Files:

  17. shomi87

    shomi87 New Member

    Joined:
    Nov 7, 2011
    Messages:
    10
    Location:
    Serbia
    Balance:
    57Coins
    Ratings:
    +0 / 0 / -0
    Your English is Ok, and i understand it :)

    I was tested this code just with arduino and console, now a have your profile settings and can test with x-sim.

    What values you send from x-sim , something like 0-255 ? or 0-180?

    Do you know how to send values from arduino to x-sim? I want to know this because when i start x-sim and connect arduino on some port , arduino software won't let me open console terminal and i can't check values that arduino calculate :(
  18. BartS

    BartS Member

    Joined:
    Oct 10, 2010
    Messages:
    156
    Balance:
    417Coins
    Ratings:
    +5 / 1 / -0
    You could probably do with an LCD screen for debugging and returning whats going on inside your Arduino.
    You cannot share a com port between two programs without an on / off handshake or you could use 2 separate comports.
  19. jamesdio

    jamesdio Member

    Joined:
    Feb 4, 2009
    Messages:
    66
    Location:
    Seoul, Korea
    Balance:
    763Coins
    Ratings:
    +59 / 0 / -0
    My Motion Simulator:
    2DOF, 3DOF, DC motor, AC motor, SCN5, SimforceGT, Motion platform, 4DOF
    Mine for 0-255 values, you can see X-SIM with my profiles attached before. :)


    and If you want to check some arduino-calculated values or raw data values from X-SIM for debugging,
    I think you'd better follow what BartS said above, using LCD screen.
  20. shomi87

    shomi87 New Member

    Joined:
    Nov 7, 2011
    Messages:
    10
    Location:
    Serbia
    Balance:
    57Coins
    Ratings:
    +0 / 0 / -0
    I found way how to debug arduino code , there is a program called Eterlogic - VSPE virtual serial port emulator and it allows me to use same port in two app, i just make one virtual port COM1 and connect it to COM4 where is my arduino , use that virtual COM4 in arduino programming console and in x-sim and it works :D