wheelchair code for driver assitance

Dependencies:   mbed

Fork of wheelchairalexa by ryan lin

wheelchair.cpp

Committer:
ryanlin97
Date:
2018-07-17
Revision:
4:29a27953fe70
Parent:
3:a5e71bfdb492
Child:
5:e0ccaab3959a

File content as of revision 4:29a27953fe70:

#include "wheelchair.h"

Wheelchair::Wheelchair(PinName xPin, PinName yPin)
{
    x = new PwmOut(xPin);
    y = new PwmOut(yPin);
}
/*
* joystick has analog out of 200-700, scale values between 1.3 and 3.3
*/
void Wheelchair::move(float x_coor, float y_coor)
{
    printf("raw is %f %f \n", x_coor, y_coor);
    printf("x is %f y is %f \n", ((x_coor*1.6f) + 1.7f), ((y_coor*1.6f) + 1.7f)); 
    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);
}