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
Revision 2:430c068cf570, committed 2014-01-24
- Comitter:
- sandwich
- Date:
- Fri Jan 24 21:55:00 2014 +0000
- Parent:
- 0:ff9bc5f69c57
- Child:
- 3:666c1bae1a34
- Commit message:
- all parts working
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Fri Jan 24 21:55:00 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/Servo/#36b69a7ced07
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/guardian.cpp Fri Jan 24 21:55:00 2014 +0000 @@ -0,0 +1,84 @@ +#include "guardian.h" + +Guardian::Guardian(PinName ailpin, PinName modpin, PinName elvpin, PinName rudpin, PinName auxpin, PinName gainpin) +{ + ail=new Servo(ailpin); + mod=new Servo(modpin); + elv=new Servo(elvpin); + /*rud=new Servo(rudpin); + aux=new Servo(auxpin); + */ + gain=new Servo(gainpin); + mod->write(0.5); + ail->write(0.5); + elv->write(0.5); + /*rud->write(0.5); + aux->write(0.00); + */ + gain->write(1.00); +} + +Guardian::~Guardian() +{ + delete ail, mod, elv, rud, aux, gain; +} + +void Guardian::set3D() +{ + mod->write(1.00); + return; +} + +void Guardian::set2D() +{ + mod->write(0.00); + return; +} + +void Guardian::setoff() +{ + mod->write(0.5); + return; +} + +void Guardian::calibrate() //must be done within 15 sec of power on +{ + set2D(); + wait(500); + set3D(); + wait(500); + set2D(); + wait(2000); + //now look for the twitch + return; +} + +void Guardian::setail(float val) +{ + ail->write(val); + return; +} + +void Guardian::setmod(float val) +{ + mod->write(val); + return; +} + +void Guardian::setelv(float val) +{ + elv->write(val); + return; +} + +void Guardian::setrud(float val) +{ + rud->write(val); + return; +} + +void Guardian::setaux(float val) +{ + aux->write(val); + return; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/guardian.h Fri Jan 24 21:55:00 2014 +0000 @@ -0,0 +1,26 @@ +#pragma once +#include "mbed.h" +#include "Servo.h" + +class Guardian +{ +private: +Servo* ail; +Servo* mod; +Servo* elv; +Servo* rud; +Servo* aux; +Servo* gain; +public: +Guardian(PinName ailpin, PinName modpin, PinName elvpin, PinName rudpin, PinName auxpin, PinName gainpin); +~Guardian(); +void set2D(); +void set3D(); +void setoff(); +void calibrate(); +void setail(float val); +void setmod(float val); +void setelv(float val); +void setrud(float val); +void setaux(float val); +}; \ No newline at end of file
--- a/main.cpp Tue Jan 21 21:32:05 2014 +0000 +++ b/main.cpp Fri Jan 24 21:55:00 2014 +0000 @@ -1,23 +1,41 @@ #include "mbed.h" #include "motor_controller.h" +#include "guardian.h" #include "IMU.h" +#include "Servo.h" +#include "rtos.h" + +bool quit=false; PololuMController mcon(p22, p6, p5); -IMU imu(0.1, 0.3, 0.005, 0.005); +Servo servo(p21); +Guardian ap(p21, p23, p24, p25, p26, p26); +Serial xbee(p13, p14); +Serial pc(USBTX, USBRX); -int main() { +//IMU imu(0.1, 0.3, 0.005, 0.005); + +void motor_thread(void const *args) { Timer t; t.start(); - while(1) { - /* if (speed>=1) - { - speed=0; - mcon.reverse(); - } - mcon.setspeed(speed); - */ - mcon.drive_sinusoidal(t.read(), 1, 0.25*3.14, 0); - wait(0.2); + while (quit==false) { + mcon.drive_sinusoidal(t.read(), 1, 2*3.14, 0); } t.stop(); } + +int main() +{ + Thread thread(motor_thread); + ap.calibrate(); + ap.set2D(); + while(1) { + char buf[128]; + if (xbee.readable()) + { + xbee.gets(buf, 128); + pc.puts(buf); + } + memset(buf, 0, 128); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Fri Jan 24 21:55:00 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#f88660a9bed1