00001 package com.github.c77.base_driver.kobuki; 00002 00003 import com.github.c77.base_driver.AbstractOdometryStatus; 00004 import com.github.c77.base_driver.BaseStatus; 00005 00006 import org.apache.commons.logging.Log; 00007 import org.apache.commons.logging.LogFactory; 00008 00012 public class KobukiOdometryStatus extends AbstractOdometryStatus { 00013 private short lastTimestamp; 00014 private static final double WIDTH = 0.280; // in m 00015 00016 Log log = LogFactory.getLog(KobukiOdometryStatus.class); 00017 00018 public KobukiOdometryStatus() { 00019 super(WIDTH); 00020 } 00021 00022 void update(BaseStatus baseStatus) { 00023 //log.info("Updating odometry. Left Ticks = " + baseStatus.getLeftDistance() + 00024 // ", Right Ticks = " + baseStatus.getRightDistance()); 00025 00026 if (baseStatus.getTimestamp() == lastTimestamp) { 00027 return; 00028 } 00029 00030 // Approximate speed using last known distance and time lapsed 00031 int timeLapsed = baseStatus.getTimestamp() - lastTimestamp; 00032 double leftSpeed = haveLastTravel ? (baseStatus.getLeftDistance() - lastLeftTravel) / timeLapsed : 0; 00033 double rightSpeed = haveLastTravel ? (baseStatus.getRightDistance() - lastRightTravel) / timeLapsed : 0; 00034 00035 // Calculate new robot pose 00036 calculateAndUpdate(baseStatus.getLeftDistance(), baseStatus.getRightDistance(), 00037 leftSpeed, rightSpeed); 00038 00039 lastTimestamp = baseStatus.getTimestamp(); 00040 } 00041 }