the fish that looks like a jet
Dependencies: ADXL345 ADXL345_I2C IMUfilter ITG3200 mbed Servo
Diff: main.cpp
- Revision:
- 6:a4d6f3e4bf28
- Parent:
- 5:090ef6275773
- Child:
- 7:e005cfaff8d1
--- a/main.cpp Tue Jan 28 23:59:21 2014 +0000 +++ b/main.cpp Wed Jan 29 05:04:50 2014 +0000 @@ -5,6 +5,14 @@ #include "Servo.h" #include "rtos.h" #include "PwmReader.h" + +#define THROTTLE_MAX 0.4 +#define THROTTLE_MIN 0.2 +#define FREQUENCY_MAX 0.4 +#define FREQUENCY_MIN 0.2 +#define RUDDER_MAX 0.4 +#define RUDDER_MIN 0.2 + bool quit=false; PololuMController mcon(p22, p6, p5); @@ -13,22 +21,25 @@ Serial xbee(p13, p14); Serial pc(USBTX, USBRX); +float throttle, frequency, rudder; //IMU imu(0.1, 0.3, 0.005, 0.005); void motor_thread(void const *args) { Timer t; t.start(); - PwmReader thrDutyCycl(p7); - - PwmReader freqDutyCycl(p8); + PwmReader thrDutyCycl(p7, THROTTLE_MIN, THROTTLE_MAX); + PwmReader freqDutyCycl(p8, FREQUENCY_MIN, FREQUENCY_MAX); + PwmReader rudDutyCycl(p9, RUDDER_MIN, RUDDER_MAX); while (quit==false) { - float td = thrDutyCycl.getDuty(); - float fd = freqDutyCycl.getDuty(); - pc.printf("throttle: %f frequency: %f\n",td,fd); - mcon.drive_sinusoidal(t.read(), 1, 2*3.141 ,0); // (time,amplitude,frequency,freqoffset) - Thread::wait(10); + throttle = thrDutyCycl.getDuty(); + frequency = freqDutyCycl.getDuty(); + rudder = rudDutyCycl.getDuty(); + + + mcon.drive_sinusoidal(t.read(), throttle, frequency); // (time,amplitude,frequency,freqoffset) + Thread::wait(5); } t.stop(); } @@ -48,8 +59,10 @@ // pc.puts(buf); // } // memset(buf, 0, 128); + + //print throttle and frequency to the terminal + pc.printf("throttle: %f frequency: %f rudder: %f\n\r",throttle,frequency,rudder); - - Thread::wait(10); + Thread::wait(500); } }