Open latest posts
motion simulator DIY community 

2DOF Arduino controller with integrated H-Bridge

Aufbau, Betrieb, Reparatur und der Entwicklung von Kontrollern oder sonstiger externer Hardware - Assembly, handling, repair and construction of controllers or external hardware.
on 31.03.2012, 18:36

2DOF Arduino controller with integrated H-Bridge

Postby intructable on 31.03.2012, 18:36

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

Here is a video where I am testing the controller with a potentiometer (acting as a speed regulator) and the emergency button.


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

Cheers
Attachments
typon.pdf
(50.71 KiB) Downloaded 252 times
Last edited by intructable on 09.05.2012, 18:50, edited 3 times in total.
intructable
new member
 
Posts: 10
Joined: 16.09.2011, 10:47
Local time: 19.06.2013, 02:14
Obtained thanks: 5
The following user would like to thank intructable for this post
tronicgr


on 05.04.2012, 04:35
Re: 2DOF Arduino controller with integrated H-Bridge

Postby daymoney13 on 05.04.2012, 04:35

can you please post some code and a tutorial, i have been trying this stuff for months and nothings working :(
daymoney13
new member
 
Posts: 4
Joined: 05.04.2012, 04:31
Local time: 19.06.2013, 02:14
Obtained thanks: 0 time


on 05.04.2012, 06:27
Re: 2DOF Arduino controller with integrated H-Bridge

Postby stowaway on 05.04.2012, 06:27

absolutely excellent.

love the design.

Would also love to see the code.
http://www.hotsnail.com.au - Electrifying Snail Mail
stowaway
X-SIMER
 
Posts: 220
Joined: 16.03.2009, 13:09
Location:Australia Gold Coast - Australia
Local time: 19.06.2013, 01:14
Obtained thanks: 8


on 05.04.2012, 20:31
Re: 2DOF Arduino controller with integrated H-Bridge

Postby intructable on 05.04.2012, 20:31

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: Select all
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: Select all
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?
intructable
new member
 
Posts: 10
Joined: 16.09.2011, 10:47
Local time: 19.06.2013, 02:14
Obtained thanks: 5
The following user would like to thank intructable for this post
daymoney13


on 05.04.2012, 20:56
Re: 2DOF Arduino controller with integrated H-Bridge

Postby daymoney13 on 05.04.2012, 20:56

thanks ! i cant wait ! :D
daymoney13
new member
 
Posts: 4
Joined: 05.04.2012, 04:31
Local time: 19.06.2013, 02:14
Obtained thanks: 0 time


on 17.04.2012, 09:23
Re: 2DOF Arduino controller with integrated H-Bridge

Postby intructable on 17.04.2012, 09:23

Hello everybody,

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



Here you can see the rotation speed versus the duty of the PWM.
Attachments
Last edited by intructable on 17.04.2012, 19:32, edited 1 time in total.
intructable
new member
 
Posts: 10
Joined: 16.09.2011, 10:47
Local time: 19.06.2013, 02:14
Obtained thanks: 5


on 17.04.2012, 09:28
Re: 2DOF Arduino controller with integrated H-Bridge

Postby intructable on 17.04.2012, 09:28

Just a new video of my testing machine using Flight Simulator + XSim.



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.
intructable
new member
 
Posts: 10
Joined: 16.09.2011, 10:47
Local time: 19.06.2013, 02:14
Obtained thanks: 5


on 17.04.2012, 20:32
Re: 2DOF Arduino controller with integrated H-Bridge

Postby intructable on 17.04.2012, 20:32

Here is the source code I used in the previous video, probably not the most efficient but it works :
Code: Select all

////////////////// 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
}
intructable
new member
 
Posts: 10
Joined: 16.09.2011, 10:47
Local time: 19.06.2013, 02:14
Obtained thanks: 5
The following user would like to thank intructable for this post
astro


on 25.04.2012, 01:09
Re: 2DOF Arduino controller with integrated H-Bridge

Postby timothy on 25.04.2012, 01:09

can you post the electronic componente list? thank and a very nice work, good job
timothy
new member
 
Posts: 5
Joined: 08.06.2011, 17:48
Local time: 19.06.2013, 01:14
Obtained thanks: 2
The following user would like to thank timothy for this post
tronicgr


on 25.04.2012, 21:00
Re: 2DOF Arduino controller with integrated H-Bridge

Postby intructable on 25.04.2012, 21:00

Sure,

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

from the thanos list (I removed the unneeded parts) :
1x - 74HC08 (DIP14)
4x - IRF4905 (TO-220)
4x - IRFZ44 (TO-220)
4x - BC546 (TO-92)

4x - 3.6K Ohm 1/4 watt resistor 1%
4x - 2.2K Ohm 1/4 watt resistor 1%
4x - 1.5K Ohm 1/4 watt resistor 1%
4x - 160 Ohm 1/4 watt resistor 1%

8x - 1N5819 Schottky Barrier Rectifier (its better to Use 1N5819 as I did)
8x - Zener 15volt 1/2 watt (The smallest was 1/2 watt not 1/4)

2x - 100uF / 63v capacitor

1x - 80mm 12v PC case fan

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

1x - DIP 14 IC header

8x - pieces of aluminiun to cool the mosfets (use silicon paste if possible).



+

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
Last edited by intructable on 09.05.2012, 18:51, edited 1 time in total.
intructable
new member
 
Posts: 10
Joined: 16.09.2011, 10:47
Local time: 19.06.2013, 02:14
Obtained thanks: 5



Next

Similar topics

Return to X-Simulator compatible hardware


Add this Thread to:
Add this page to Mr. Wong Add this page to Del.icio.us Add this page to Webnews Add this page to Icio Add this page to Oneview Add this page to Linkarena Add this page to Newskick Add this page to Folkd Add this page to Yigg Add this page to Digg Add this page to Reddit Add this page to Simpy Add this page to StumbleUpon Add this page to Slashdot Add this page to Netscape Add this page to Furl Add this page to Yahoo Add this page to Spurl Add this page to Google Add this page to Blinklist Add this page to Blogmarks Add this page to Diigo Add this page to Technorati Add this page to Newsvine Add this page to Blinkbits Add this page to Ma.Gnolia Add this page to Smarking Add this page to Netvouz

Who is online

Users browsing this forum: No registered users and 0 guests