AbstractOdometryStatus.java
Go to the documentation of this file.
00001 package com.github.c77.base_driver;
00002 
00006 public class AbstractOdometryStatus implements OdometryStatus {
00007     // Actual data properties
00008     protected double poseX;
00009     protected double poseY;
00010     protected double poseTheta;
00011     protected double speedLinearX;
00012     protected double speedAngularZ;
00013 
00014     // Work variables
00015     protected int lastLeftTravel;
00016     protected int lastRightTravel;
00017     protected boolean haveLastTravel = false;
00018 
00019     private final double WIDTH;
00020 
00021     public AbstractOdometryStatus(double width) {
00022         WIDTH = width;
00023     }
00024 
00025     @Override
00026     public double getPoseX() {
00027         return poseX;
00028     }
00029 
00030     @Override
00031     public double getPoseY() { return poseY; }
00032 
00033     @Override
00034     public double getPoseTheta() {
00035         return poseTheta;
00036     }
00037 
00038     @Override
00039     public double getSpeedLinearX() {
00040         return speedLinearX;
00041     }
00042 
00043     @Override
00044     public double getSpeedAngularZ() {
00045         return speedAngularZ;
00046     }
00047 
00051     protected void calculateAndUpdate(int leftTravel, int rightTravel, double leftSpeed,
00052                                       double rightSpeed) {
00053 
00054         // Special case: first time ever we can't calculate differences
00055         if(!haveLastTravel) {
00056             lastLeftTravel = leftTravel;
00057             lastRightTravel = rightTravel;
00058             haveLastTravel = true;
00059             return;
00060         }
00061 
00062         // Calculate deltas
00063         double dr = ((leftTravel - lastLeftTravel) + (rightTravel - lastRightTravel))/2000.0;
00064         double da = ((rightTravel - lastRightTravel) - (leftTravel - lastLeftTravel))/(1000.0*WIDTH);
00065         lastLeftTravel = leftTravel;
00066         lastRightTravel = rightTravel;
00067 
00068         // Update data
00069         synchronized (this) {
00070             this.speedLinearX = (leftSpeed + rightSpeed) / 2000.0;
00071             speedAngularZ = (rightSpeed - leftSpeed) / (1000.0*WIDTH);
00072             poseX += dr * Math.cos(poseTheta);
00073             poseY += dr * Math.sin(poseTheta);
00074             poseTheta += da;
00075         }
00076     }
00077 }


android_base_controller
Author(s):
autogenerated on Fri Aug 28 2015 10:04:47