ryan lin
/
wheeldriveassistance
wheelchair code for driver assitance
Fork of wheelchairalexa by
wheelchair.cpp
- Committer:
- ryanlin97
- Date:
- 2018-07-22
- Revision:
- 7:5e38d43fbce3
- Parent:
- 6:0cd57bdd8fbc
- Child:
- 8:381a4ec3fef8
File content as of revision 7:5e38d43fbce3:
#include "wheelchair.h" 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); } void Wheelchair::turn_right() { out->printf("turning right\n"); double start = imu->yaw(); double final = start + 90; out->printf("final %f \n", final); out->printf("start %f \n", start); if(final > 360) { final -= 360; out->printf("final %f \n", final); while(imu->yaw() - 360 <= final) { Wheelchair::right(); if( out->readable()) { out->printf("stopped\n"); Wheelchair::stop(); return; } } } else { out->printf("final %f \n", final); while(imu->yaw() <= final) { Wheelchair::right(); if( out->readable()) { out->printf("stopped\n"); Wheelchair::stop(); return; } } } out->printf("done turning\n"); } void Wheelchair::turn_left() { double start = imu->yaw(); double final = start - 90; if(final <0) final += 360; while(imu->yaw() >= final) { Wheelchair::left(); } }