Team Virgo v3 / Orion_newPCB_test_LV

Dependencies:   mbed-rtos mbed QEI BNO055 MPU6050_DMP_Nucleo-I2Cdev virgo3_imuHandler_Orion_PCB MAX17048 Servo

Fork of Orion_newPCB_test by Team Virgo v3

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers localization.cpp Source File

localization.cpp

00001 #include "localization.h"
00002 
00003 Localization::Localization()
00004 {
00005     wheelDia = wheel_dia;
00006     trackWidth = track_width;
00007 
00008     for(int i=0; i<2; i++) {
00009         prevRevolutions[i]=0;
00010         position[i]=0;
00011     }
00012 }
00013 
00014 void Localization::updatePosition(float heading, float wheel_revolutions[2])
00015 {
00016     incrementalDistance = M_PI * wheelDia * ( (wheel_revolutions[0] - prevRevolutions[0]) + (wheel_revolutions[1] - prevRevolutions[1]) ) / 2.0;
00017 
00018     position[0] += cos(heading + M_PI/2) * incrementalDistance;
00019     position[1] += sin(heading + M_PI/2) * incrementalDistance;
00020 
00021     prevRevolutions[0] = wheel_revolutions[0];
00022     prevRevolutions[1] = wheel_revolutions[1];
00023 }
00024 
00025 void Localization::setPosition(float position_in[2]) //[x,y] position
00026 {
00027     position[0] = position_in[0];
00028     position[1] = position_in[1];
00029 }