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: mbed mbed-rtos MotionSensor EthernetInterface
Revision 7:27516a2b504b, committed 2016-04-17
- Comitter:
- drelliak
- Date:
- Sun Apr 17 01:07:25 2016 +0000
- Parent:
- 6:c930555fd872
- Child:
- 8:a1067fcde341
- Commit message:
- added the main loop
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Apr 17 01:05:16 2016 +0000
+++ b/main.cpp Sun Apr 17 01:07:25 2016 +0000
@@ -58,55 +58,23 @@
void debug();
int main(){
- int teste = 0;
- setVelocity(0);
- switch(teste){
- case 0: // vai para tras duas vezes
- brakeMotor();
- wait(1);
- setVelocity(-1);
- setVelocity(0);
- setVelocity(-30);
- wait(2);
- brakeMotor();
- wait(2);
- setVelocity(-1);
- setVelocity(0);
- setVelocity(-30);
- break;
- case 1: // vai para a frente e depois para tras
- brakeMotor();
- wait(1);
- setVelocity(20);
- wait(2);
- brakeMotor();
- wait(2);
- setVelocity(-1);
- setVelocity(0);
- setVelocity(-30);
- break;
- case 2: // vai para tras e depois para frente
- brakeMotor();
- wait(1);
- setVelocity(-1);
- setVelocity(0);
- setVelocity(-30);
- wait(2);
- brakeMotor();
- wait(2);
- setVelocity(20);
- break;
- case 3: // vai para frente duas vezes
- brakeMotor();
- wait(1);
- setVelocity(20);
- wait(2);
- brakeMotor();
- wait(2);
- setVelocity(20);
- break;
- }
- while(1);
+ printf("Initializing controller....\r\n\r\n");
+ initializeController();
+ printf("Controller Initialized. \r\n");
+ magCal();
+ gyro_angle = processMagAngle();
+ velocity = MINIMUM_VELOCITY;
+ setMotorPWM(velocity,motor);
+ startGyro();
+ while (true){
+ processGyroAngle();
+ controlAnglePID(P,I,D,N);
+ debug();
+ if(t.read_us() < Ts*1000000)
+ wait_us(Ts*1000000 - t.read_us());
+ if(pc.readable())
+ readProtocol();
+ }
}
void readProtocol(){
char msg = ser.getc();