Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

estimator/estimator.cpp

Go to the documentation of this file.
00001 #include "estimator.h"
00002 #include "../truckd/hw_interface.h"
00003 
00044 void EncEstimator::update(double fr, double fl, double br, double bl) {
00045 
00046         // If the above formuals are multiplied through by a small
00047         // timestep then, instead of working with velocities we use
00048         // diffrential for position and angle 
00049         
00050         // Convert BL,BR values from encoder ticks into meters
00051         fr *= hwInterface::metersPerTick;
00052         fl *= hwInterface::metersPerTick;
00053         br *= hwInterface::metersPerTick;
00054         bl *= hwInterface::metersPerTick;       
00055 
00056         // Caclulate new angle and forward movement
00057         double forward = (fr + fl + br + bl) * 0.5;
00058         double newAngle = angle + (fr + br - fl - bl) * (0.5f / hwInterface::axleLength);
00059 
00060         // Calculate new x,y positions
00061         // instead of making an arc assume half the forward movement
00062         // was traveled at the old distance and half the forward 
00063         // movement was traveled at the new angle
00064         // Formula :
00065         // xpos = xpos + cos(angle) * forward * 0.5
00066         //             + cos(newangle) * forward * 0.5
00067         double newCosValue = cos(newAngle);
00068         double newSinValue = sin(newAngle);             
00069         xpos += 0.5 * forward * (cosValue + newCosValue);
00070         ypos += 0.5 * forward * (sinValue + newSinValue);
00071    
00072         // sin/cos is a slow operation so remember result
00073         cosValue = newCosValue;
00074         sinValue = newSinValue;
00075 
00076         angle = newAngle;
00077 }

Generated on Fri Sep 1 14:25:44 2006 for Raptor by  doxygen 1.4.4