Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXOS8700CQ SDFileSystem mbed
lib/motors.cpp
- Committer:
- gerardo_carmona
- Date:
- 2014-10-16
- Revision:
- 0:3a322aad8c88
File content as of revision 0:3a322aad8c88:
// ----- Libraries ------------------------------------------------------------------
#include "mbed.h"
#include "motors.h"
// ----- I/O Pins -------------------------------------------------------------------
// MOTORS (Control)
DigitalOut dir_left(D7);
DigitalOut dir_right(D8);
PwmOut pwm_left(D9);
PwmOut pwm_right(D10);
// ----- Functions ------------------------------------------------------------------
void move_motors(char _move_command, int _power_left, int _power_right){
switch (_move_command){
case MOVE_FWD:
motor_fwd(_power_left, _power_right);
break;
case MOVE_REV:
motor_rev(_power_left, _power_right);
break;
case MOVE_LEF:
motor_left(_power_left, _power_right);
break;
case MOVE_RIG:
motor_right(_power_left, _power_right);
break;
case MOVE_STO:
motor_stop();
break;
//case MOVE_90L:
// move_90(1);
// break;
//case MOVE_90R:
// move_90(2);
// break;
default:
// bt.printf("%f\r\n", get_mag_angle());
break;
}
}
void motor_fwd(int _power_left, int _power_right){
dir_left = 1;
dir_right = 1;
pwm_left = (float)_power_left/100;
pwm_right = (float)_power_right/100;
//pc.printf("FWD\n");
}
void motor_rev(int _power_left, int _power_right){
dir_left = 0;
dir_right = 0;
pwm_left = (float)_power_left/100;
pwm_right = (float)_power_right/100;
//pc.printf("REV\n");
}
void motor_left(int _power_left, int _power_right){
dir_left = 0;
dir_right = 1;
pwm_left = (float)_power_left/100;
pwm_right = (float)_power_right/100;
//pc.printf("LEFT\n");
}
void motor_right(int _power_left, int _power_right){
dir_left = 1;
dir_right = 0;
pwm_left = (float)_power_left/100;
pwm_right = (float)_power_right/100;
//pc.printf("RIGHT\n");
}
void motor_stop(){
dir_left = 1;
dir_right = 1;
pwm_left = 0;
pwm_right = 0;
//pc.printf("STOP\n");
}