Saturday, February 20, 2016

Motor Testing Successful!

Feb. 20th, 2016

Today allowed me a little time to set up the two motors on a board and do a little testing with an old power supply I made some years ago.
The main goal was to see if this motor control board would handle the two motors together without killing the board or the Arduino.

The board I am using here is the Adafruit Motor Stepper Servo Shield V2
( https://www.adafruit.com/products/1438 )
This board will allow you to hook up 2 stepper motors, or up to 4 DC motors up to 1.2A per channel and 3A peak current.  Since I did not know the current these motors are rated at, I was going to have to test and see if all would work.

First I hooked up the steering motor because it was the stepper motor and would be more complicated.  I wanted to get that working, knowing the wheel motor would be much simpler.
The stepper in this case is a 6 wire unipolar stepper.  The two coils each have a center tap which I connected together and connected to the ground on the board.  Each of the wires for the two other poles I connected to the Motor3 and Motor4 + and - connections.



I next connected the red and black wires from my homemade power supply up to the board to the Positive and Negative motor supply (see picture above).

Then I was able to go into the Arduino software and make a quick sketch to see if the motor would work...and success!  I had a rotating stepper motor!

I ran that stepper for a while to see if anything got hot and after several minutes all the components and the motor were still cool so I decided to take the next step and connect the DC wheel motor to see if both motors would work without issues.



I connected the DC Motor with the gearbox attached to it on to the board on the Motor1 connection and then went back into the software to make a test of that motor alone first to make sure it would work and not get anything too hot.

I made a quick sketch in the Arduino software and this motor worked well also!

So, it was time to take the plunge and made some code that would run both at the same time.

I could have stayed in the Arduino IDE, but since I am used to Visual Studio, I fired it up and made a program to test both motors simultaneously.  Now, on the robot, both motors would really only turn on at the same time when the robot was turning either right or left.   When going straight the steer wheel is really just released so that it does not draw any current.

After a little work on the program, I had a quick test  that ran the wheel motor forward, then moved both motors to turn right, then ran the wheel motor backward, then both motors together in a left turn.

That program was totally successful so now I have a good test program to start with when the board is mounted up on the robot and connected to the motors for some rolling tests.

I will include the program here for anyone to look at who might be curious.

/* Greg Spahn Feb. 20th 2016
 *  The eventual goal will be to make a motor library that
 *  has the functions of:
 *  Forward
 *  Left
 *  Right
 *  Backward
 *  Stop
 *  
 *  For now the testing will be for each function to see if they will work with
 *  this motor board and both motors connected to one micro controller powered
 *  by the one 12v battery.
 *  
 */

#include <Wire.h>
#include <Adafruit_MotorShield.h>
//#include "utility/Adafruit_MS_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 

// WHEEL MOTOR
// DC Wheel Motor connected to M1 on motor board.
Adafruit_DCMotor *wheelMotor = AFMS.getMotor(1);

// STEER MOTOR
// Steer Motor is a stepper motor with 48 steps per revolution (7.6 degree)
// to motor port #2
Adafruit_StepperMotor *steerMotor = AFMS.getStepper(48, 2);


void setup() {
  // Set up serial port at 9600 bps
  Serial.begin(115200);
  Serial.println("Motorshield v2 - Motor test");

  AFMS.begin();        // create with the default frequency 1.6KHz

  
  // Set the speed to start, from 0 (off) to 255 (max speed)
  wheelMotor->setSpeed(200);
  wheelMotor->run(FORWARD);
  wheelMotor->run(RELEASE);
  // Set the speed of the steering motor (stepper).
  steerMotor->setSpeed(10);  // 10 rpm 

}

void loop() {
  uint8_t i;
  uint8_t j;

  // j is going to be the stepper speed.
  j=1;

// Move Forward 
  Serial.print("\nFORWARD...");
  wheelMotor->run(FORWARD);
  for (i=50; i<200; i++) {
    wheelMotor->setSpeed(i);  
    delay(10);
  }

delay(5000);

// Move Right
 Serial.print("\nTURN RIGHT...");
 wheelMotor->run(FORWARD);
 for (i=50; i<200; i++) {
  wheelMotor->setSpeed(i);
  steerMotor->step(j, FORWARD, DOUBLE);
  delay(5);
 }

delay(1000);

// Move Backward
  Serial.print("\nBACKWARD...");
  wheelMotor->run(BACKWARD);
  for (i=50; i<200; i++) {
    wheelMotor->setSpeed(i);  
    delay(10);
  }

delay(5000);

// Move Left
 Serial.print("\nTURN LEFT...");
 wheelMotor->run(BACKWARD);
 for (i=50; i<200; i++) {
  wheelMotor->setSpeed(i);
  steerMotor->step(j, BACKWARD, DOUBLE);
  delay(5);
 }

delay(1000);

// Stop
  Serial.print("\nRELEASE MOTOR...");
   wheelMotor->run(RELEASE);
  delay(2000);
}

No comments:

Post a Comment