a
Dependencies: QEI2 chair_BNO055 PID Watchdog VL53L1X_Filter ros_lib_kinetic
Dependents: wheelchairControlSumer19 Version1-0
wheelchair.cpp
- Committer:
- ryanlin97
- Date:
- 2018-07-23
- Revision:
- 10:e5463c11e0a0
- Parent:
- 8:381a4ec3fef8
- Child:
- 11:d14a1f7f1297
File content as of revision 10:e5463c11e0a0:
#include "wheelchair.h" bool manual_drive = false; Wheelchair::Wheelchair(PinName xPin, PinName yPin, Serial* pc, Timer* time ) { x = new PwmOut(xPin); y = new PwmOut(yPin); //imu = new chair_BNO055(); imu = new chair_MPU9250(pc, time); imu->setup(); out = pc; out->printf("wheelchair setup done \n"); } /* * joystick has analog out of 200-700, scale values between 1.3 and 3.3 */ void Wheelchair::move(float x_coor, float y_coor) { float scaled_x = ((x_coor * 1.6f) + 1.7f)/3.3f; float scaled_y = (3.3f - (y_coor * 1.6f))/3.3f; x->write(scaled_x); y->write(scaled_y); } void Wheelchair::forward() { x->write(high); y->write(def+offset); } void Wheelchair::backward() { x->write(low); y->write(def); } void Wheelchair::right() { x->write(def); y->write(high); } void Wheelchair::left() { x->write(def); y->write(low); } void Wheelchair::stop() { x->write(def); y->write(def); } // counter clockwise is + // clockwise is - void Wheelchair::turn_right() { bool overturn = false; out->printf("turning right\n"); double start = imu->yaw(); double final = start - 90; if(final < 0) { final += 360; overturn = true; } out->printf("start %f, final %f\n", start, final); double curr = 361; while(curr >= final) { Wheelchair::right(); if( out->readable()) { out->printf("stopped\n"); Wheelchair::stop(); return; } curr = imu->yaw(); if(overturn && curr >= 0 && curr <= start ) { curr = 361; } } out->printf("done turning\n"); Wheelchair::stop(); } void Wheelchair::turn_left() { bool overturn = false; out->printf("turning left\n"); double start = imu->yaw(); double final = start + 90; if(final > 360) { final -= 360; overturn = true; } out->printf("start %f, final %f\n", start, final); double curr = -1; while(curr <= final) { Wheelchair::left(); if( out->readable()) { out->printf("stopped\n"); Wheelchair::stop(); return; } curr = imu->yaw(); if(overturn && curr > (360 - 90) ) { curr = 0; } } out->printf("done turning\n"); Wheelchair::stop(); }