I recently purchased a Arduino Controlled Robot kit from Oreilly as the result of seeing it advertised in Make magazine. Very cool entry level project. The Robot is assembled and ready to conduct a test of the motors (4) operation. This is a exercise outlined in the book published by Oreilly titled “Make an Arduino Controlled Robot”. The sketch is shown on page 68. I have downloaded the Arduino software. Also, I have downloaded the library from Make an Arduino-Controlled Robot [Book] To run this test I have loaded the program titled “MotorTest4wd”. This application uses the Arduino Leonardo board.
When I attempt to execute a verify compile instruction I recieve errors that I have been unable to resolve. Any help on this issue would be greatly appreciated.
Note when previewing this post i noted that a icon appears after the blink command instead of an 8 followed by a ). I don't understand why.
Thanks- Bob C
/*******************************************
-
MotorTest4wd.ino
-
Initial motor test for 4WD
-
robot rotates clockwise
-
(Left motors driven forward, right backward)
-
Michael Margolis 24 July 2012
********************************************/
const int LED_PIN = 13;
const int speed = 60; // percent of maximum speed
#include <AFMotor.h> // adafruit motor shield library (modified my mm)
AF_DCMotor Motor_Left_Front(4, MOTOR34_1KHZ); // Motor 4
AF_DCMotor Motor_Right_Front(3, MOTOR34_1KHZ); // Motor 3
AF_DCMotor Motor_Left_Rear(1, MOTOR12_1KHZ); // Motor 1
AF_DCMotor Motor_Right_Rear(2, MOTOR12_1KHZ); // Motor 2
int pwm;
void setup()
{
Serial.begin(9600);
blinkNumber(8); // open port while flashing. Needed for Leonardo only
// scale percent into pwm range (0-255)
pwm= map(speed, 0,100, 0,255);
Motor_Left_Front.setSpeed(pwm);
Motor_Right_Front.setSpeed(pwm);
Motor_Left_Rear.setSpeed(pwm);
Motor_Right_Rear.setSpeed(pwm);
}
// run over and over
void loop()
{
Serial.println("rotate cw");
Motor_Left_Front.run(FORWARD);
Motor_Left_Rear.run(FORWARD);
Motor_Right_Front.run(BACKWARD);
Motor_Right_Rear.run(BACKWARD);
delay(5000); // run for 5 seconds
Serial.println("stopped");
Motor_Left_Front.run(RELEASE); // stop the motors
Motor_Right_Front.run(RELEASE);
Motor_Left_Rear.run(RELEASE); // stop the motors
Motor_Right_Rear.run(RELEASE);
delay(5000); // stop for 5 seconds
}
// function to indicate numbers by flashing the built-in LED
void blinkNumber( byte number) {
pinMode(LED_PIN, OUTPUT); // enable the LED pin for output
while(number--) {
digitalWrite(LED_PIN, HIGH); delay(100);
digitalWrite(LED_PIN, LOW); delay(400);
}
}``
Following are the error statements-
MotorTest4wd.cpp.o: In function ‘_static_initialization_and_destruction_0’:
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:14: undefined reference to ‘AF_DCMotor: :AF_DCMotor (unsigned char, unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:15: undefined reference to ‘AF_DCMotor: :AF_DCMotor (unsigned char, unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:16: undefined reference to ‘AF_DCMotor: :AF_DCMotor (unsigned char, unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:17: undefined reference to ‘AF_DCMotor: :AF_DCMotor (unsigned char, unsigned char)’
MotorTest4wd.cpp.o: In function ‘loop’:
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:38: undefined reference to ‘AF_DCMotor: ::run (unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:39: undefined reference to ‘AF_DCMotor: : run (unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:41: undefined reference to ‘AF_DCMotor: : run (unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:42: undefined reference to ‘AF_DCMotor: : run (unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:46: undefined reference to ‘AF_DCMotor: : run (unsigned char)’
MotorTest4wd.cpp.o: C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:47: more undefined references to ‘AF_DCMotor: :run(unsigned char)’follow
MotorTest4wd.cpp.o: In function ‘setup’:
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:28: undefined reference to ‘AF_DCMotor: :setSpeed(unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:29: undefined reference to ‘AF_DCMotor: :setSpeed(unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:30: undefined reference to ‘AF_DCMotor: :setSpeed(unsigned char)’
C:\Program Files\Arduino\arduino-1.04/MotorTest4wd.ino:31: undefined reference to ‘AF_DCMotor: :setSpeed(unsigned char)’
For refernce, here is the AFMotor.h file
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
// updated for Arduino 1.0.2 by mem 22 Nov 2012
#ifndef AFMotor_h
#define AFMotor_h
#include <inttypes.h>
#include <avr/io.h>
//#define MOTORDEBUG 1
#define MICROSTEPS 16 // 8 or 16
#if defined(AVR_ATmega8) ||
defined(AVR_ATmega48) ||
defined(AVR_ATmega88) ||
defined(AVR_ATmega168) ||
defined(AVR_ATmega328P)
#define MOTOR12_64KHZ _BV(CS20) // no prescale
#define MOTOR12_8KHZ _BV(CS21) // divide by 8
#define MOTOR12_2KHZ _BV(CS21) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS22) // divide by 64
#elif defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
#define MOTOR12_64KHZ _BV(CS10) // no prescale
#define MOTOR12_8KHZ _BV(CS11) // divide by 8
#define MOTOR12_2KHZ _BV(CS11) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS12) // divide by 64
#elif defined(AVR_ATmega32U4) // Leonardo (mem 22 Nov 2012)
#define MOTOR12_64KHZ _BV(CS00) // no prescale
#define MOTOR12_8KHZ _BV(CS01) // divide by 8
#define MOTOR12_2KHZ _BV(CS01) | _BV(CS20) // divide by 32
#define MOTOR12_1KHZ _BV(CS02) // divide by 64
#endif
#if defined(AVR_ATmega8) ||
defined(AVR_ATmega48) ||
defined(AVR_ATmega88) ||
defined(AVR_ATmega168) || \
defined(AVR_ATmega328P)
#define MOTOR34_64KHZ _BV(CS00) // no prescale
#define MOTOR34_8KHZ _BV(CS01) // divide by 8
#define MOTOR34_1KHZ _BV(CS01) | _BV(CS00) // divide by 64
#else
#define MOTOR34_64KHZ _BV(CS40) // no prescale
#define MOTOR34_8KHZ _BV(CS41) // divide by 8
#define MOTOR34_1KHZ _BV(CS41) | _BV(CS40) // divide by 64
#endif
#define MOTOR1_A 2
#define MOTOR1_B 3
#define MOTOR2_A 1
#define MOTOR2_B 4
#define MOTOR4_A 0
#define MOTOR4_B 6
#define MOTOR3_A 5
#define MOTOR3_B 7
#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4
#define SINGLE 1
#define DOUBLE 2
#define INTERLEAVE 3
#define MICROSTEP 4
/*
#define LATCH 4
#define LATCH_DDR DDRB
#define LATCH_PORT PORTB
#define CLK_PORT PORTD
#define CLK_DDR DDRD
#define CLK 4
#define ENABLE_PORT PORTD
#define ENABLE_DDR DDRD
#define ENABLE 7
#define SER 0
#define SER_DDR DDRB
#define SER_PORT PORTB
*/
// Arduino pin names
#define MOTORLATCH 12
#define MOTORCLK 4
#define MOTORENABLE 7
#define MOTORDATA 8
class AFMotorController
{
public:
AFMotorController(void);
void enable(void);
friend class AF_DCMotor;
void latch_tx(void);
};
class AF_DCMotor
{
public:
AF_DCMotor(uint8_t motornum, uint8_t freq = MOTOR34_8KHZ);
void run(uint8_t);
void setSpeed(uint8_t);
private:
uint8_t motornum, pwmfreq;
};
class AF_Stepper {
public:
AF_Stepper(uint16_t, uint8_t);
void step(uint16_t steps, uint8_t dir, uint8_t style = SINGLE);
void setSpeed(uint16_t);
uint8_t onestep(uint8_t dir, uint8_t style);
void release(void);
uint16_t revsteps; // # steps per revolution
uint8_t steppernum;
uint32_t usperstep, steppingcounter;
private:
uint8_t currentstep;
};
uint8_t getlatchstate(void);
#endif