I bought this controller from Sparkfun
http://www.sparkfun.com/commerce/product_info.php?products_id=9670, it is an L298 based motor controller.
This controller has 3 pins for each motor ( ENA, IN1, IN2 for the one motor, ENB, IN3, IN4 for the other) and you can control the motors by just setting "high" or "low"
the corresponding pins.
For example, fi you have one motor connected to ENA, IN1 and IN2 you stop the motor by setting the IN1 and IN2 pins to both "high" or "low". To change direction you set one of them to "high" or "low".
I plugged one motor and made a little code to test it, but the problem is that it doesn't change the rotation direction despite the fact that the leds on the controller change ( red and yellow) each time I set a command to change direction.
Below is the code, I used the Webbotlib and L298 header.
#include "sys/axon2.h"
//#include "servos.h"
//#include "rprintf.h"
//#include "i2c_master.h"
#include"C:\My_Robot\WebbotLib\Motors/Solarbotics/L298.h"
#include "C:\My_Robot\WebbotLib\motorPWM.h"
#include "hardware2.h"
pin_make_output(B4); // ENA pin on motor controller
pin_make_output(B5); // IN1 pin on motor controller
pin_make_output(B6); // IN2 pin on motor controller
pin_high(B4); // motor starts rotation
pin_low(B6); // move front
pin_high(B5); // move front
MOTOR right = MAKE_SOLAR_L298_MOTOR(FALSE,B4,B5,B6);
SOLAR_L298_MOTOR_LIST motors[] = {&right};
// Create a driver for the list of motors
SOLAR_L298_MOTOR_DRIVER bank1 = MAKE_SOLAR_L298_MOTOR_DRIVER(motors);
void appInitHardware(void){
// Initialise the solarL298Init(&bank1);
solarL298Init(&bank1);
act_setSpeed(&right,DRIVE_SPEED_MAX);
}
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0;
}
int dir=1;
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){
pin_high(B4);
DRIVE_SPEED speed=act_getSpeed(&right);
speed+=dir;
if(speed==DRIVE_SPEED_MAX){
dir=-1;
}else if(speed==DRIVE_SPEED_MIN){
dir=1;
}
pin_low(B5); // change direction - move back
pin_high(B6); // change direction - move back
act_setSpeed(&right,speed);
speed=act_getSpeed(&right);
speed+=dir;
if(speed==DRIVE_SPEED_MAX){
dir=-1;
}else if(speed==DRIVE_SPEED_MIN){
dir=1;
}
delay_ms(200);
act_setSpeed(&right,speed);
return 0;
}
Any help would be much appreciated.
Thanks