|
Jolijar
Joined: 22 Feb 2013
Posts: 96
Location: Dekalb, IL
|
Homebuilt ESC for small motors
I am working on making a speed controller for small robots. It works using the
Ti - 754410NE chipset which is a dual H-bridge capable of driving up to 1 Amp per side.
I am planning on using it to drive two of these motors
http://www.sciplus.com/p/MABUCHI-12VDC-SPROCKET-MOTOR_50259
to make a small wedge for me to chase with Death by 1000 cuts.
I am not an Electrical Engineer or a computer programmer so this is messy.
Right now I am researching about the programming and the hardware
TODO
1. make the code accept proportional control right now it is full on or off
2. find out exactly what the arduino amtel 328p chip needs to be stand alone or possibly use the attiny chipset
3. design a pcb for ease of construction and programming.
here is my code so far.
code:
/////////////////////////////////////////////////////////////////////
// Really messy rc code for tank style driving version 0.01 //
// by Jeffrey Olijar //
// Now you know who to blame if it doesn't work. //
/////////////////////////////////////////////////////////////////////
unsigned long Ch1;
unsigned long Ch2;
unsigned long Lch1; // Last good value for Ch 1
unsigned long Lch2; // Last good value for Ch 2
unsigned long Ich1; // Initial Value for Ch 1
unsigned long Ich2; // Initial Value for Ch 2
const int motor1Pin = 3;
const int motor2Pin = 4;
const int motor3Pin = 6;
const int motor4Pin = 5;
void setup() {
Serial.begin(9600);
Serial.print ("Ready!");
pinMode(10, INPUT); // Ch1
pinMode(11, INPUT); // Ch2
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(motor3Pin, OUTPUT);
pinMode(motor4Pin, OUTPUT);
Ich1 = pulseIn(10, HIGH, 20000); // Read the pulse width of Ch1
Ich2 = pulseIn(10, HIGH, 20000); // Read the pulse width of Ch2
Lch1 = Ich1; // Sets the Last good value to the Initial value
Lch2 = Ich2; // Sets the Last good value to the Initial value
}
void loop() {
Ch1 = pulseIn(10, HIGH, 20000); // Read the pulse width of Ch1
if (Ch1 == 0) {Ch1 = Lch1;} else {Lch1 = Ch1;}
Ch2 = pulseIn(11, HIGH, 20000); // Read the pulse width of Ch2
if (Ch2 == 0) {Ch2 = Lch2;} else {Lch2 = Ch2;}
Serial.print ("Channel 1: ");
Serial.print (Ch1);
Serial.println("");
Serial.print ("Channel 2: ");
Serial.print (Ch2);
Serial.println("");
if(Ch2<1400) {
Serial.println("Left");
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
digitalWrite(motor4Pin, HIGH); // set leg 1 of the H-bridge low
digitalWrite(motor3Pin, LOW); // set leg 2 of the H-bridge high
}
else if(Ch2>1600) {
Serial.println("Right");
digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge high
digitalWrite(motor4Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor3Pin, HIGH); // set leg 2 of the H-bridge high
}
else {
if(Ch1<1400){
Serial.println("Reverse");
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
digitalWrite(motor4Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor3Pin, HIGH); // set leg 2 of the H-bridge high
}
else if (Ch1>1600) {
Serial.println("Foreward");
digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
digitalWrite(motor4Pin, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motor3Pin, LOW); // set leg 2 of the H-bridge low
}
else {
Serial.println("Neutral");
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
digitalWrite(motor3Pin, LOW); // set leg 1 of the H-bridge high
digitalWrite(motor4Pin, LOW); // set leg 2 of the H-bridge low
}
}
//delay(1000); //makes the console not as spammy.
}
So far I have it working with the small square slot car motors via usb
I need to go get a voltage regulator so I can use my lipo batteries to power it.
If anyone wants to help feel free to contribute.
|
Sat Mar 30, 2013 5:07 pm |
|
|
|
|
|
|
Jolijar
Joined: 22 Feb 2013
Posts: 96
Location: Dekalb, IL
|
Okay so I found a library for Arduino called Halfbridge
and I figured out how to control the motors via PWM
Right now with the code below
CH1 controls one motor
CH2 controls the other motor
I need to figure out mixing then it should be good
code:
#include <HalfBridge.h>
int ch1;
int ch2;
int ch1speed;
int ch2speed;
Motor motors[2] = { Motor(10, 3, 5), Motor(11, 6, 9) };
void setup()
{
pinMode(12, INPUT); // Set our input pins as such
pinMode(13, INPUT);
Serial.begin(9600);
motors[0].init();
motors[1].init();
}
void loop()
{
ch1 = pulseIn(12, HIGH, 25000); // Read the pulse width of
ch2 = pulseIn(13, HIGH, 25000); // each channel
ch1speed = map(ch1,1000,2000,-500,500);
ch1speed = constrain(ch1speed, -255, 255);
ch2speed = map(ch2, 1000,2000, -500, 500); //center over zero
ch2speed = constrain(ch2speed, -255, 255); //only pass valid pwm values
Serial.print("ch1: "); //Serial debugging stuff
Serial.println(ch1speed);
Serial.print("ch2: "); //Serial debugging stuff
Serial.println(ch2speed);
Serial.println(); //Serial debugging stuff
motors[0].setSpeed((ch1speed));
motors[1].setSpeed((ch2speed));
//delay(1000);
}
|
Mon Apr 01, 2013 12:42 pm |
|
|
Jolijar
Joined: 22 Feb 2013
Posts: 96
Location: Dekalb, IL
|
And got it
code:
#include <HalfBridge.h>
int ch1;
int ch2;
int ch1speed;
int ch2speed;
int ch1motor;
int ch2motor;
Motor motors[2] = { Motor(10, 3, 5), Motor(11, 6, 9) };
void setup()
{
pinMode(12, INPUT); // Set our input pins as such
pinMode(13, INPUT);
Serial.begin(9600);
motors[0].init();
motors[1].init();
}
void loop()
{
ch1 = pulseIn(12, HIGH, 25000); // Read the pulse width of
ch2 = pulseIn(13, HIGH, 25000); // each channel
ch1speed = map(ch1,1000,2000,-500,500);
ch1speed = constrain(ch1speed, -250, 250);
ch2speed = map(ch2, 1000,2000, -500, 500); //center over zero
ch2speed = constrain(ch2speed, -250, 250); //only pass valid pwm values
ch1motor = ch1speed + ch2speed;
ch2motor = ch1speed - ch2speed;
Serial.print("ch1: "); //Serial debugging stuff
Serial.println(ch1motor);
Serial.print("ch2: "); //Serial debugging stuff
Serial.println(ch2motor);
Serial.println(); //Serial debugging stuff
motors[0].setSpeed((ch1motor));
motors[1].setSpeed((ch2motor));
delay(10);
}
|
Mon Apr 01, 2013 12:58 pm |
|
|
|
|
|
|
|
|
|
|
|