Pages: 1 [2]   Go Down
Author Topic: Wishing my Tamiya Motors Had More Drive  (Read 1206 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 1
Posts: 273
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did come to realize spinning 2 wheels in opposite directions wasn't going to work.  If it did, then a car's wheels would be able to do it.  haha!  I was thinking to attach a servo in the front changing the angle 45degrees in each direction.  My vehicle performs badly without the battery.  While moving forward or backward why would I want to spin 1 wheel faster than the other?

Corrected Code:

Code:
/*
Evan Johnson
Description: A bluetooth remote controlled car. The car has FA-130 motors,
a Tamiya universal plate and axel hinges for front end wheels, and a SM-S4303R servo.
Most likely using a LiPo 3.7v 1000mA battery to power the car.
 
*/


#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo

char serInStr[30];  // array that will hold the serial input string

int val = 45; // change angle of servo 45 degrees left from center
int val2 = 90; // change angle of servo to 90 degree center
int val3 = 135; // change angle of servo 45 degrees right from center
   

void setup()
{
 
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin
  pinMode(3, OUTPUT); //Initiates Speed Channel A pin

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel B pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel B pin
  pinMode(11, OUTPUT); //Initiates Speed Channel B pin

  myservo.attach(10);  // attaches the servo on pin 10 to the servo object
   
  //Start the UART TX1/RX0 (D1/D0) communication at defined rate
  Serial.begin(115200);
  delay(1000);
 
  //Call menu function
  menu();
  delay(1000);
}

void loop()
{
  //read the serial port and create a string out of what you read
  if(readSerialString())
  {
    Serial.println(serInStr);
    char cmd = serInStr[0];
    int num = atoi(serInStr+1);

    switch(cmd)
    {
      case '8':
      {
        Serial.println("8");
        Serial.println("MADE IT IN 8 FOR FORWARD");
       
        //Motor A and Motor B engage breaks
        digitalWrite(9, HIGH); // ENGAGE BREAK ON CHANNEL A MOTOR
        digitalWrite(8, HIGH); // ENGAGE BREAK ON CHANNEL B MOTOR
       
        //Motor A background @ full speed
        digitalWrite(12, LOW); //Establish forward direction of channel A
        digitalWrite(9, LOW);   //Disengage the brake for channel A
        analogWrite(3, 255);   //Spins the motor on channel A at full speed
       
        //Motor B background @ full speed
        digitalWrite(13, LOW);  //Establishes forward direction of Channel B
        digitalWrite(8, LOW);   //Disengage the Brake for Channel B
        analogWrite(11, 255);    //Spins the motor on Channel B at full speed
      }
      case '2':
      {
        Serial.println("2");
        Serial.println("MADE IT IN 2 FOR BACKWARDS");
       
        //Motor A and Motor B engage breaks
        digitalWrite(9, HIGH); // ENGAGE BREAK ON CHANNEL A MOTOR
        digitalWrite(8, HIGH); // ENGAGE BREAK ON CHANNEL B MOTOR
       
        //Motor A forward @ full speed
        digitalWrite(12, HIGH); //Establish forward direction of channel A
        digitalWrite(9, LOW);   //Disengage the brake for channel A
        analogWrite(3, 255);   //Spins the motor on channel A at half speed
       
        //Motor B forward @ full speed
        digitalWrite(13, HIGH);  //Establishes forward direction of Channel B
        digitalWrite(8, LOW);   //Disengage the Brake for Channel B
        analogWrite(11, 255);    //Spins the motor on Channel B at half speed
      }
      case '4':
      {
        Serial.println("4");
        Serial.println("MADE IT IN 4 FOR LEFT SERVO");
     
        myservo.write(val); // sets the servo position 45 degrees for right position
        delay(15);          // waits for the servo to get there
      }
      case '0':
      {
        Serial.println("0");
        Serial.println("MADE IT IN 0 FOR CENTER SERVO");
     
        myservo.write(val2); // sets the servo position 90 degrees for center position
        delay(15);          // waits for the servo to get there
      }
      case '6':
      {
        Serial.println("6");
        Serial.println("MADE IT IN 6 FOR RIGHT SERVO");
     
        myservo.write(val3); // sets the servo position 45 degrees for left position
        delay(15);          // waits for the servo to get there
      }
      case '5':
      {
        Serial.println("5");
        Serial.println("MADE IT IN 5 FOR BREAK MOTORS");
       
        //Motor A and Motor B engage breaks
        digitalWrite(9, HIGH); // ENGAGE BREAK ON CHANNEL A MOTOR
        digitalWrite(8, HIGH); // ENGAGE BREAK ON CHANNEL B MOTOR
      }
      default:
      {
        Serial.println("Invalid Selection. Please try again!");
        return;
      }
    }
  }
  delay(2);
}


//****************************************************
//1) Menu void/void function
void menu()
{
  Serial.print("\r\nEvan's Double Gearbox Control!\n"
                  "'8' for forward motors\n"
                  "'2' for reverse motors\n"
                  "'4' for left servo\n"
                  "'0' for center servo\n"
                  "'6' for right servo\n"
                  "'5' for break motors\n"
                  "Please enter your command: ");
}


//2) Read a string from the serial and store it in an array
//you must supply the array variable
uint8_t readSerialString()
{
  if(!Serial.available())
  {
    return 0;
  }
  delay(10);  // wait a little for serial data
  int i = 0;
  while (Serial.available())
  {
    serInStr[i] = Serial.read();   // FIXME: doesn't check buffer overrun
    i++;
  }
  serInStr[i] = 0;  // indicate end of read string
  return i;  // return number of chars read
}
« Last Edit: February 04, 2013, 11:11:13 am by encryptor » Logged

peace*&^

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Spinning one wheel faster than the other provides the turn motion. I will be the guy asking the really dumb question... the non-driven wheels. They are not connected to the same axle are they? They are independently free-running, right?

Spinning in opposite directions provides rotation along the center of the axle. In your configuration, that won't work because you are trying to spin along the center of the rear axle and the other wheels will act as brakes trying to move sideways. Omniwheels would work like this, but not normal wheels. Having some swing (even it is not controlled) would allow the front wheels to change angle with the friction, which would help since they are not trying to move sideways) would probably work, but not optimal. This is what a caster does.

Spinning one motor faster than the other puts the center of rotation on the center of the wheel spinning slower. Since the whole base continues to move forward while it does this, you are also causing the front wheels to spin at the same speed (assuming they are free-running). Now, your rotation is in an arc, with the center of rotation along one side of the base, instead of in the middle.

With a four wheeled base like you have, this is the correct way to do it.

Basically just image trying to turn a push-cart with wheels fixed in straight forward direction. You cant just pull one side back and push the other forward. You would have to push harder on one side. Of course, the turn radius is much larger. To decrease the turn radius, you use casters on the front wheels. This is why a car turns the front wheels to steer.

(I'm sure I boggled up that explanation.)
« Last Edit: February 04, 2013, 04:47:24 pm by Retroplayer » Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 273
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I see now.  What if I use the casters as the back wheels?
Logged

peace*&^

Offline Offline
God Member
*****
Karma: 27
Posts: 829
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's a bit early for me, but that should work. I would however link the casters so that they follow each other or you will likely have wobbling and jumping while they adjust unless you have alot of the weight centered over and evenly distributed over the casters. The longer the wheel base, the worse this will be. Also, you are not going to have a while lot of  power this way. Might be better to drive from the front, and put casters in the rear in that case.

As long as it would work on my cart analogy, it will work. It's not ideal, but it will work.
Logged

Pages: 1 [2]   Go Up
Jump to: