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 controller with integrated H-Bridge

Discussion in 'SimTools compatible interfaces' started by intructable, Mar 31, 2012.

  1. intructable

    intructable New Member

    Joined:
    Sep 16, 2011
    Messages:
    10
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    Hello everybody,
    I am pleased to show you my 2DOF Joyrider controller using an Arduino interface.
    This controller has an integrated H-Bridge based from the Thanos (Tronicgr) Dual Mosfet H-Bridge (all credit goes to him :clap: ).

    This controller is composed of :

    -An Arduino Uno to communicate with the computer
    -2 plugs (ground,signal, +5V) for position sensors (10K potentiometers)
    -1 plugs for an emergency button (using the interrupt pin (pin 2) of the Ardunio
    -2 H-Bridges to supply the two axis motors

    Here is a video where I am testing the controller by rotating in 2 different ways
    http://www.youtube.com/watch?v=vIm0q84zlrg
    Here is a video where I am testing the controller with a potentiometer (acting as a speed regulator) and the emergency button.
    http://www.youtube.com/watch?v=yF9FLZGv9No

    Hope you like it, I try to give you the circuit model asap, feel free to ask questions.

    Cheers

    Attached Files:

  2. daymoney13

    daymoney13 New Member

    Joined:
    Apr 5, 2012
    Messages:
    4
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    can you please post some code and a tutorial, i have been trying this stuff for months and nothings working :(
  3. stowaway

    stowaway New Member

    Joined:
    Mar 16, 2009
    Messages:
    213
    Location:
    Gold Coast - Australia
    Balance:
    1Coins
    Ratings:
    +0 / 0 / -0
    absolutely excellent.

    love the design.

    Would also love to see the code.
  4. intructable

    intructable New Member

    Joined:
    Sep 16, 2011
    Messages:
    10
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    Hi
    I updated the post : I added the mask and the components map.

    to daymoney13 :
    I haven't yet a code with a PID because I am making the setup with a wiper motor, once done I will start to code.
    The controller works like a standard h-bridge; you have 3 pins to control a motor (2 for the direction A and B, 1 for the speed called PWM).
    The Motor 1 is controlled by the pins : A = pin 3, B = pin 4, PWM = 5
    The Motor 2 is controlled by the pins : A = pin 8, B = pin 9, PWM = 10

    To use it you could code a class like that :
    (code not tested and could be faster by using direct bus control, but anyway...)

    Code:
    class Motor
    {
      public :
        Motor(int Pin_E, int Pin_MA, int Pin_MB)
        {
          E= Pin_E;
          MA =Pin_MA;
          MB =Pin_MB;
          
          pinMode(MA, OUTPUT);
          digitalWrite(MA, LOW); 
          pinMode(MB, OUTPUT);
          digitalWrite(MB, LOW);       
          pinMode(E, OUTPUT);
      
          setspeed(255);
    
        }
       
       void setspeed(int mspeed)
       {
          analogWrite(E, mspeed); 
       }
       
       void stopper()
       {
         digitalWrite(MA, LOW); 
         digitalWrite(MB, LOW);
         compteur =0;
       }
       
       void marche(bool Direction)
       {
          stopper();
          if(Direction)digitalWrite(MA, HIGH);
          else digitalWrite(MB, HIGH);      
       }
       
       private :
       int E,MA,MB;  
       
    };
    
    then you use it like that :

    Code:
    Motor motor1(10,8,9); //intialisation
    
    motor1.setspeed(150);
    motor1.marche(true);
    
    hope this little code help you.

    PS: if somebody know how can I make the youtube video works?
  5. daymoney13

    daymoney13 New Member

    Joined:
    Apr 5, 2012
    Messages:
    4
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    thanks ! i cant wait ! :D
  6. intructable

    intructable New Member

    Joined:
    Sep 16, 2011
    Messages:
    10
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    Hello everybody,

    I just post a new video of my wiper-testing-machine.

    http://www.youtube.com/watch?v=qDH5WK3ajzQ

    Here you can see the rotation speed versus the duty of the PWM.
    vitessetension.png

    Attached Files:

  7. intructable

    intructable New Member

    Joined:
    Sep 16, 2011
    Messages:
    10
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    Just a new video of my testing machine using Flight Simulator + XSim.

    http://www.youtube.com/watch?v=MZLgtIKqRMI

    This video shows my controller using a servo loop. As the movements are quite slow I just code a P regulator (instead of a PID).
    Soon I will add the source code.
  8. intructable

    intructable New Member

    Joined:
    Sep 16, 2011
    Messages:
    10
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    Here is the source code I used in the previous video, probably not the most efficient but it works :
    Code:
    
    ////////////////// Arduino controller V0.1 15/04/12  ///////////////
    ///  coded by : intructable                                      ///
    ///  under public domain                                         ///
    ////////////////////////////////////////////////////////////////////
    
    #include <PID_v1.h>
    
    // motor 1
    #define M1PWM 5
    #define M1A 4
    #define M1B 3
    
    // motor 2
    #define M2PWM 10
    #define M2A 9
    #define M2B 8
    
    //Motor constante
    //PWM value when the motor sart to move
    #define MINPOWER 110
    
    //sensors
    #define SENSOR1 4
    #define SENSOR2 5
    
    //sensors range
    #define S1MIN 350
    #define S1MAX 680
    
    //Emergency button
    #define EMERGENCYBUTTON 0
    
    //Serail command
    #define COMMAND_SIZE 128
    char aWord[COMMAND_SIZE];
    int nb_char=0;
    char c;
    
    //PID controller, actually a P controller (ei I =D =0)
    double Setpoint, Input, Output;
    double P=1;
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    //Motor class
    // function : 
    //          Motor(int Pin_E, int Pin_MA, int Pin_MB)      creator
    //          void setspeed(int mspeed)                     change the motor speed from -255 to 255
    //          void stopper()                                stop the motor
    //          void marche(bool Direction)                   change the motor direction
    
    class Motor
    {
      public :
        Motor(int Pin_E, int Pin_MA, int Pin_MB)
        {
          E= Pin_E;
          MA =Pin_MA;
          MB =Pin_MB;
         
          pinMode(MA, OUTPUT);
          digitalWrite(MA, LOW);
          pinMode(MB, OUTPUT);
          digitalWrite(MB, LOW);       
          pinMode(E, OUTPUT);
     
          
    
        }
       
       void setspeed(int mspeed)
       {  
         stopper();
         if(mspeed<0)
         {  
            mspeed=-mspeed;       
            marche(false);
         }
         else
         {
            marche(true);
         } 
    
         analogWrite(E,map(mspeed,0,255,MINPOWER,255));     
       }
       
       void stopper()
       {
         digitalWrite(MA, LOW);
         digitalWrite(MB, LOW);
       }
       
       void marche(bool Direction)
       {
          stopper();
          if(Direction)digitalWrite(MA, HIGH);
          else digitalWrite(MB, HIGH);
          dir = Direction;     
       }
       
       private :
       int E,MA,MB;
       bool dir;
       
    };
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    Motor motor1(M1PWM,M1A,M1B);  //create a motor
    
    void setup()
    { 
      Serial.begin(9600);             //start serial comunication
      Serial.println(Demarrage);    //hello world
      
      TCCR0B =TCCR0B &0b11111000 | 0x01; //change PWM frequency to avoid noise
      
      attachInterrupt(EMERGENCYBUTTON, emergencyStop, CHANGE); //attach the emergency button to the emergency function
      
      motor1.stopper(); //stop the motor 1
      
      Setpoint =127; // set the setpoint to the medium value
    
      
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    void loop()
    {
    
      serialread(); //read command, it understands command in the format A00 X~a01~~13~ with ~a01~ a decimal value from 0 to 255
      
      Input = analogRead(SENSOR1); // read the potentiometer value
      Input = map(Input,S1MIN,S1MAX,0,255); // convert the value in the range of the potentiometer, 0=min amplitude, 255=max amplitude
      
      Output = P*(Setpoint-Input); //regulate with a proportional controller
      motor1.setspeed(Output); //set the motor speed
    
      delay(64*2); //wait 2 ms, the delay must be multiplied by 64 because we changed the TCCR0B timer value of the arduino
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    void emergencyStop()
    { 
        motor1.stopper(); // in case of emergency we stop the motor
        
        while(true) // and go into an infinite loop, so the user need to restart the arduino
        {
          
        }
     
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    void serialread()
    {
      
        if (Serial.available() > 0) //check for new character
        {
          c = Serial.read(); //store the character
          
          if(c!=13 && nb_char<COMMAND_SIZE) //if not the end of a command, store it into aWord
          {
            
            aWord[nb_char] =c;
            nb_char++; 
          }
          else                              //if yes, start the command function
          {      
            command(aWord,nb_char);  
            nb_char =0;                     // clear aWord
            aWord[nb_char] ='\0';        
            Serial.flush();                 //flush the Serial
          } 
        } 
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    char entete[4];
    bool ok=true;
    
    void command(char * cmd, int nb_char)
    {
      ok=true;                            //if something goes wrong, ok is pull to wrong
      if(nb_char<3)                       //the command should have at least 3 characters
      {
         return;
      }
      
      for(int i =0; i<3;i++)              //store the header of the command
      {
        entete[i]= cmd[i];
      }
      entete[3]='\0';
      
      //////////////////////////////////////////////////////////////////
      if(strcmp(entete,A00)==0)        //if the header is A00
      {
         
         int X= getvalue(cmd,  nb_char, 'X', &ok); //read the value after X
         
         if(ok)
         {
            X=X*8-896; //we multiplie the value by 8 to improve the sensation, could be done in XSim
            if(X<0)X=0; //we check is X is not to low
            if(X>255)X=255; //or to high
            Setpoint =X; //we store the new setpoint
            
         }
        
        
      }
      else  
      {
    
      }
       
    }
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    int getvalue(char *cmd, int nb_char, char c, bool *ok) //this function store the decimal value written after the character c
    {
       int i=0, j=0;
       char value[COMMAND_SIZE];
       while( i<nb_char)
       {
         if(cmd[i] == c)break; //find the place where th character is
         i++;
       }
       
       i++;
       
       
       while( i<nb_char&& cmd[i] != ' ') //search for any blank
       {
        value[j] =cmd[i];//store the value
        i++;j++;
       }
       if(j == 0) *ok=false;
       value[j]='\0';
       
       return atof(value); //convert into an integer
    }
  9. timothy

    timothy New Member

    Joined:
    Jun 8, 2011
    Messages:
    5
    Balance:
    - 8Coins
    Ratings:
    +0 / 0 / -0
    can you post the electronic componente list? thank and a very nice work, good job
  10. intructable

    intructable New Member

    Joined:
    Sep 16, 2011
    Messages:
    10
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    Sure,

    The parts list is quite the same than Tronicgr's HBridge :

    from the thanos list (I removed the unneeded parts) :
    +

    1x - 100 Ohm 1/4 watt resistor 1%
    1x - 10K Ohm 1/4 watt resistor 1%

    1x - Terminal connectors (two legs) atleast 15amp rated on 125volt
    2x - Terminal connectors (three legs) atleast 15amp rates on 125volt

    2x 8 pinhead
    2x 6 pinhead

    1x Arduino UNO (of course)


    Cheers
  11. timothy

    timothy New Member

    Joined:
    Jun 8, 2011
    Messages:
    5
    Balance:
    - 8Coins
    Ratings:
    +0 / 0 / -0
    thanks I'll build one for me , very nice work :clap:
  12. daymoney13

    daymoney13 New Member

    Joined:
    Apr 5, 2012
    Messages:
    4
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    good job !!!! keep going I believe in you ! :D
  13. daymoney13

    daymoney13 New Member

    Joined:
    Apr 5, 2012
    Messages:
    4
    Balance:
    0Coins
    Ratings:
    +0 / 0 / -0
    hey instructable can you post a tutorial on how to test your code ? I uploaded it to my arduino but now im stuck with the x sim software.

    thanks :)
  14. intructable

    intructable New Member

    Joined:
    Sep 16, 2011
    Messages:
    10
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    hi daymoney,

    To try my code you have to start X-Sim Profiler and X-Sim Sender (I recommend you to launch the Testplugin instead of a real game).

    On the Math Setup add a new axis (or two if you have 2 degrees of freedom), you can check on Input which slot you can choose.

    Then go to Output Setup, USO, then add the com address of your Arduino (for me com 8 )
    Fill the line Datapacket with axisinformations: with A00 X~a01~~~13~
    (or for a 2dof :A00 X~a01~ Y~a02~~13~)
    Set the options as shown on this picture
    X-sim.png

    Then press start.

    I also recommend you to install VSPE, a program which allows you to create a virtual port.
    You can then connect X-Sim to this port (while connected to your Arduino).
    You can then check the commands sent by X-Sim by using the hyperterminal. (or Tera Term if you are on Win Seven).

    I hope it help you, fill free to ask more precision.
  15. timothy

    timothy New Member

    Joined:
    Jun 8, 2011
    Messages:
    5
    Balance:
    - 8Coins
    Ratings:
    +0 / 0 / -0
    hello thks for the list but where i use de R680ohm?????? You can get a picture with the sites of the components to be easier to solder the components. the image that has only the component type is not what amount. and now already not find resistances of 3.6K, only 3.3k / 3.9K whatDo you recommend ?
    thank you and hug
  16. intructable

    intructable New Member

    Joined:
    Sep 16, 2011
    Messages:
    10
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    hello timothy,
    thanks for this post, actually I did not erase the 680ohm on the thanos component list, you won't need it for the controller.
    I added a new picture with the resistor value, tell me if you need more informations.
    For the 3.3K/3.9K, I not enough skilled to tell you what is the best solution. I recommend you to ask directly thanos.
    If your provider can sell you 3.3k and a 300ohm resistor, you can use them in a serial way to get the good resistor value (this wouldn't be the most beautiful solution but a least it works perfectly)

    I hope it help you, I look forward seeing you controller
  17. astro

    astro New Member

    Joined:
    Jun 6, 2012
    Messages:
    16
    Location:
    Argentina
    Balance:
    25Coins
    Ratings:
    +0 / 0 / -0
    Hi intructable,
    Very god job. I'm building my simulator, following your instructions. Did you finish the code for arduino?, I tried to complete to work with 2 motors, but no luck, there is much noise in the second engine and does not move as it should.

    Thanks!
  18. intructable

    intructable New Member

    Joined:
    Sep 16, 2011
    Messages:
    10
    Balance:
    14Coins
    Ratings:
    +0 / 0 / -0
    Hi astro,
    Nice to see that you are building the controller.
    I have not worked on the arduino code since my friend started to build the seat. What would you like to add to the former arduino code?
    To help you I will need more information :
    Did you first try to swap the two motors to see if you get the same response with the other one?
    What do you mean by does not move as it should?
    Does the noise sound like a typical frequency or more or less like switching on and off rapidly?

    Cheers
  19. astro

    astro New Member

    Joined:
    Jun 6, 2012
    Messages:
    16
    Location:
    Argentina
    Balance:
    25Coins
    Ratings:
    +0 / 0 / -0
    Hi intructable,
    I try to explain better.
    In your code, you start program for two motors, but at the end, is for one.
    There are no commands for the second motor.
    Like:
    Motor motor2(M2PWM,M2A,M2B);
    motor2.stopper();

    The reading of the Y part.

    So I try to complete. I don't understand PID, I am new in arduino so I'm sure I'm doing something wrong.

    I think there is a problem when I use commands to see the variables in the monitor using VSPE, like:
    Serial.print(pot1=);
    Serial.print(pot1);
    I think that is interfering in some way.

    This is the code:

    Code:
    ////////////////// Arduino controller V0.1 03/06/12  ///////////////
    ///  coded by : intructable                                      ///
    ///  mofified with a lot of errors by : astro  :(   sorry        ///
    ///  under public domain                                         ///
    ////////////////////////////////////////////////////////////////////
    
    #include <PID_v1.h>
    
    
    // motor 1
    #define M1PWM 5
    #define M1A 4
    #define M1B 3
    
    // motor 2
    #define M2PWM 10
    #define M2A 9
    #define M2B 8
    
    //Motor constante
    //PWM value when the motor sart to move
    #define MINPOWER 110
    
    //sensors
    #define SENSOR1 4
    #define SENSOR2 5
    
    //sensors range
    #define S1MIN 188
    #define S1MAX 768
    
    #define S2MIN 288
    #define S2MAX 720
    
    //Emergency button
    #define EMERGENCYBUTTON 0
    
    //Serial command
    #define COMMAND_SIZE 128
    char aWord[COMMAND_SIZE];
    int nb_char=0;
    int pot1=0;
    int pot2=0;
    char c;
    
    //PID controller, actually a P controller (ei I =D =0)
    double Setpoint1, Input1, Output1;
    double Setpoint2, Input2, Output2;
    double P=1;
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///
    
    //Motor class
    // function : 
    //          Motor(int Pin_E, int Pin_MA, int Pin_MB)      creator
    //          void setspeed(int mspeed)                     change the motor speed from -255 to 255
    //          void stopper()                                stop the motor
    //          void marche(bool Direction)                   change the motor direction
    
    class Motor
    {
    public :
      Motor(int Pin_E, int Pin_MA, int Pin_MB){
        E= Pin_E;
        MA =Pin_MA;
        MB =Pin_MB;
    
        pinMode(MA, OUTPUT);
        digitalWrite(MA, LOW);
        pinMode(MB, OUTPUT);
        digitalWrite(MB, LOW);       
        pinMode(E, OUTPUT);
      }
    
      void setspeed(int mspeed)
      {  
        stopper();
        if(mspeed<0)
        {  
          mspeed=-mspeed;       
          marche(false);
        }
        else
        {
          marche(true);
        } 
        analogWrite(E,map(mspeed,0,255,MINPOWER,255));     
      }
    
      void stopper()
      {
        digitalWrite(MA, LOW);
        digitalWrite(MB, LOW);
      }
    
      void marche(bool Direction)
      {
        stopper();
        if(Direction)digitalWrite(MA, HIGH);
        else digitalWrite(MB, HIGH);
        dir = Direction;     
      }
    
    private :
      int E,MA,MB;
      bool dir;
    
    };
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /////
    
    Motor motor1(M1PWM,M1A,M1B);  //create a motor
    Motor motor2(M2PWM,M2A,M2B);  //create a motor
    
    void setup()
    { 
      Serial.begin(9600);      //start serial comunication
      Serial.print(START: );    //hello world
    
      TCCR0B =TCCR0B &0b11111000 | 0x01; //change PWM frequency to avoid noise
    
      attachInterrupt(EMERGENCYBUTTON, emergencyStop, CHANGE); //attach the emergency button to the emergency function
    
      motor1.stopper(); //stop the motor 1
      motor2.stopper(); //stop the motor 2
      
      ///////////CENTER//////////////////////
      Setpoint1 =127; // set the setpoint to the medium value
      Setpoint2 =127; // set the setpoint to the medium value
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///
    
    
    void loop()
    {
    
      serialread(); //read command, it understands command in the format A00 X~a01~ Y~a02~~13~ with ~a01~ a decimal value from 0 to 255
    
      Input1 = analogRead(SENSOR1); // read the potentiometer value
      Input2 = analogRead(SENSOR2); // read the potentiometer value
      pot1 = Input1; // read the potentiometer value
      pot2 = Input2; // read the potentiometer value
    
      Input1 = map(Input1,S1MIN,S1MAX,0,255); // convert the value in the range of the potentiometer, 0=min amplitude, 255=max amplitude
      Input2 = map(Input2,S2MIN,S2MAX,0,255); // convert the value in the range of the potentiometer, 0=min amplitude, 255=max amplitude
    
      Output1 = P*(Setpoint1-Input1); //regulate with a proportional controller
      Output2 = P*(Setpoint2-Input2); //regulate with a proportional controller
      motor1.setspeed(Output1); //set the motor speed
      motor2.setspeed(Output2); //set the motor speed
      
    // Serial.println(Input); 
     Serial.print(pot1=); 
     Serial.print(pot1);
     Serial.print( | MapInput1=); 
     Serial.print(Input1); 
     Serial.print( | Target1=); 
     Serial.print(Setpoint1);
     Serial.print( | Move=); 
     Serial.print(Output1);
    
     Serial.print(\t | \t pot2=); 
     Serial.print(pot2); 
     Serial.print( | MapInput2=); 
     Serial.print(Input2);
     Serial.print( | Target2=); 
     Serial.print(Setpoint2);
     Serial.print( | OUT2=); 
     Serial.println(Output2);
    
      //Serial.println(Input2);     
    
      delay(64*2); //wait 2 ms, the delay must be multiplied by 64 because we changed thme TCCR0B timer value of the arduino
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///
    void emergencyStop()
    { 
      motor1.stopper(); // in case of emergency we stop the motor
      motor2.stopper(); // in case of emergency we stop the motor
      delay(10);  
      while(true) // and go into an infinite loop, so the user need to restart the arduino
      {
    
      }
    
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///
    
    void serialread()
    {
    
      if (Serial.available() > 0) //check for new character
      {
        c = Serial.read(); //store the character
    
        if(c!=13 && nb_char<COMMAND_SIZE) //if not the end of a command, store it into aWord
        {
    
          aWord[nb_char] =c;
          nb_char++; 
        }
        else                              //if yes, start the command function
        {      
          command(aWord,nb_char);  
          nb_char =0;                     // clear aWord
          aWord[nb_char] ='\0';        
          Serial.flush();                 //flush the Serial
        } 
      } 
    }
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///
    
    char entete[4];
    bool ok=true;
    
    void command(char * cmd, int nb_char)
    {
      ok=true;                            //if something goes wrong, ok is pull to wrong
      if(nb_char<3)                       //the command should have at least 3 characters
      {
        return;
      }
    
      for(int i =0; i<3;i++)              //store the header of the command
      {
        entete[i]= cmd[i];
      }
      entete[3]='\0';
    
      //////////////////////////////////////////////////////////////////
      if(strcmp(entete,A00)==0)        //if the header is A00
      {
        int X= getvalue(cmd,  nb_char, 'X', &ok); //read the value after X
        int Y= getvalue(cmd,  nb_char, 'Y', &ok); //read the value after Y
    
        if(ok)
        {
          X=X*8-896; //we multiplie the value by 8 to improve the sensation, could be done in XSim
          Y=Y*8-896; //we multiplie the value by 8 to improve the sensation, could be done in XSim
          if(X<0)X=0; //we check is X is not to low
          if(Y<0)Y=0; //we check is X is not to low
          if(X>255)X=255; //or to high
          if(Y>255)Y=255; //or to high
          Setpoint1 =X; //we store the new setpoint
          Setpoint2 =Y; //we store the new setpoint
        }
      }
      else  
      {
      }
    }
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ///
    
    int getvalue(char *cmd, int nb_char, char c, bool *ok) //this function store the decimal value written after the character c
    {
      int i=0, j=0;
      char value[COMMAND_SIZE];
      while( i<nb_char)
      {
        if(cmd[i] == c)break; //find the place where th character is
        i++;
      }
    
      i++;
    
      while( i<nb_char&& cmd[i] != ' ') //search for any blank
      {
        value[j] =cmd[i];//store the value
        i++;
        j++;
      }
      if(j == 0) *ok=false;
      value[j]='\0';
      return atof(value); //convert into an integer
    }
    
    
    
    The noise in the second motor is like high frequency and does not move.
    I change all de components to the other side of H-bridge, to see if something is burn, but nothing change, everything seems to be ok.

    I 'm using TestPlugin.
    Can you post your screen Simple resize math setup?
    This is what I have:
    x-sim_math.jpg

    Can you test your motor in the other conector to see if working?

    Sorry for my english. :(
    Thanks!!!!
  20. astro

    astro New Member

    Joined:
    Jun 6, 2012
    Messages:
    16
    Location:
    Argentina
    Balance:
    25Coins
    Ratings:
    +0 / 0 / -0
    Hi intructable,
    I'm trying to understand the code.
    Do I need a line to change the frequency for the second motor, and the delay too?

    What is this?
    X=X*8-896;

    896?
    How I can get that number?

    Sorry for my english.
    Thanks!!!!