My modifications/additions to the code
Dependencies: ADXL345 ADXL345_I2C IMUfilter ITG3200 Servo fishgait mbed-rtos mbed pixy_cam
Fork of robotic_fish_ver_4_8 by
Diff: main.cpp
- Revision:
- 7:e005cfaff8d1
- Parent:
- 6:a4d6f3e4bf28
- Child:
- 8:0574a5db1fc4
--- a/main.cpp Wed Jan 29 05:04:50 2014 +0000 +++ b/main.cpp Thu Jan 30 02:04:23 2014 +0000 @@ -1,9 +1,9 @@ #include "mbed.h" #include "motor_controller.h" #include "guardian.h" -#include "IMU.h" +//#include "IMU.h" #include "Servo.h" -#include "rtos.h" +//#include "rtos.h" #include "PwmReader.h" #define THROTTLE_MAX 0.4 @@ -15,54 +15,34 @@ bool quit=false; +InterruptIn event(p16); PololuMController mcon(p22, p6, p5); Servo servo(p21); Guardian ap(p21, p23, p24, p25, p26, p26); Serial xbee(p13, p14); Serial pc(USBTX, USBRX); +PwmReader ch3(p16, 0.054, 0.094); +PwmReader ch6(p15, 0.054, 0.094); +Timer t; float throttle, frequency, rudder; - -//IMU imu(0.1, 0.3, 0.005, 0.005); -void motor_thread(void const *args) { - - Timer t; +int main() +{ + //ap.calibrate(); + //ap.set2D(); + ap.setoff(); t.start(); - PwmReader thrDutyCycl(p7, THROTTLE_MIN, THROTTLE_MAX); - PwmReader freqDutyCycl(p8, FREQUENCY_MIN, FREQUENCY_MAX); - PwmReader rudDutyCycl(p9, RUDDER_MIN, RUDDER_MAX); - - while (quit==false) { - throttle = thrDutyCycl.getDuty(); - frequency = freqDutyCycl.getDuty(); - rudder = rudDutyCycl.getDuty(); + while(1) { + + float vol_norm=ch3.getDuty(); + float freq_norm=ch6.getDuty(); - - mcon.drive_sinusoidal(t.read(), throttle, frequency); // (time,amplitude,frequency,freqoffset) - Thread::wait(5); + pc.printf("channel 3: %f, channel 6: %f\n", vol_norm, freq_norm); + //mcon.drive_rectangular(t.read(), vol_norm*freq_norm, 3*freq_norm); + mcon.drive_sinusoidal(t.read(), vol_norm*freq_norm, 3*freq_norm); + //pc.printf("time: %f\n\r", t.read()); + //pc.printf("throttle: %f frequency: %f rudder: %f\n\r",throttle,frequency,rudder); + //wait_ms(10); } t.stop(); } - -int main() -{ - Thread thread(motor_thread); - //ap.calibrate(); - //ap.set2D(); - ap.setoff(); - while(1) { - //char buf[128]; -// if (xbee.readable()) -// { -// xbee.gets(buf, 128); -// //xbee.scanf("%d"); -// 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(500); - } -}