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 26.04.2012, 00:49

Re: 2DOF Arduino controller with integrated H-Bridge

Postby timothy on 26.04.2012, 00:49

thanks I'll build one for me , very nice work :clap:
timothy
new member
 
Posts: 5
Joined: 08.06.2011, 17:48
Local time: 22.05.2013, 23:20
Obtained thanks: 2


on 27.04.2012, 05:23
Re: 2DOF Arduino controller with integrated H-Bridge

Postby daymoney13 on 27.04.2012, 05:23

good job !!!! keep going I believe in you ! :D
daymoney13
new member
 
Posts: 4
Joined: 05.04.2012, 04:31
Local time: 23.05.2013, 00:20
Obtained thanks: 0 time


on 27.04.2012, 12:34
Re: 2DOF Arduino controller with integrated H-Bridge

Postby daymoney13 on 27.04.2012, 12:34

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 :)
daymoney13
new member
 
Posts: 4
Joined: 05.04.2012, 04:31
Local time: 23.05.2013, 00:20
Obtained thanks: 0 time


on 27.04.2012, 19:37
Re: 2DOF Arduino controller with integrated H-Bridge

Postby intructable on 27.04.2012, 19:37

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


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.
intructable
new member
 
Posts: 10
Joined: 16.09.2011, 10:47
Local time: 23.05.2013, 00:20
Obtained thanks: 5
The following user would like to thank intructable for this post
daymoney13


on 09.05.2012, 02:52
Re: 2DOF Arduino controller with integrated H-Bridge

Postby timothy on 09.05.2012, 02:52

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
timothy
new member
 
Posts: 5
Joined: 08.06.2011, 17:48
Local time: 22.05.2013, 23:20
Obtained thanks: 2
The following user would like to thank timothy for this post
intructable


on 09.05.2012, 19:04
Re: 2DOF Arduino controller with integrated H-Bridge

Postby intructable on 09.05.2012, 19:04

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
intructable
new member
 
Posts: 10
Joined: 16.09.2011, 10:47
Local time: 23.05.2013, 00:20
Obtained thanks: 5


on 22.06.2012, 05:09
Re: 2DOF Arduino controller with integrated H-Bridge

Postby astro on 22.06.2012, 05:09

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!
astro
full member
 
Posts: 16
Joined: 06.06.2012, 05:46
Location:Argentina Argentina
Local time: 22.05.2013, 20:20
Obtained thanks: 3


on 22.06.2012, 13:46
Re: 2DOF Arduino controller with integrated H-Bridge

Postby intructable on 22.06.2012, 13:46

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


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

Postby astro on 25.06.2012, 06:06

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: Select all
////////////////// 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:


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

Sorry for my english. :(
Thanks!!!!
astro
full member
 
Posts: 16
Joined: 06.06.2012, 05:46
Location:Argentina Argentina
Local time: 22.05.2013, 20:20
Obtained thanks: 3


on 02.07.2012, 02:15
Re: 2DOF Arduino controller with integrated H-Bridge

Postby astro on 02.07.2012, 02:15

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!!!!
astro
full member
 
Posts: 16
Joined: 06.06.2012, 05:46
Location:Argentina Argentina
Local time: 22.05.2013, 20:20
Obtained thanks: 3



PreviousNext

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 1 guest

cron