- Timestamp:
- 05/09/10 13:17:28 (21 months ago)
- Files:
-
- 1 modified
-
trunk/software/rb/kalman.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/software/rb/kalman.py
r718 r737 1 # Copyright (C) 20 09 Thomas W. Most2 # 1 # Copyright (C) 2010 Thomas W. Most, Jon Klein 2 # 3 3 # This program is free software: you can redistribute it and/or modify 4 4 # it under the terms of the GNU General Public License as published by … … 14 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 15 16 # ___________________________________ 17 #/ I am wearing a hat, so I'm only \ 18 #\ probably a stegosaurus. / 19 # ----------------------------------- 20 #\ . . 21 # \ / `. .' " 22 # \ .---. < > < > .---. 23 # \ | \ \ - ~ ~ - / / | 24 # _____ ..-~ ~-..-~ 25 # | | \~~~\.' `./~~~/ 26 # --------- \__/ \__/ 27 # .' O \ / / \ " 28 # (_____, `._.' | } \/~~~/ 29 # `----. / } | / \__/ 30 # `-. | / | / `. ,~~| 31 # ~-.__| /_ - ~ ^| /- _ `..-' 32 # | / | / ~-. `-. _ _ _ 33 # |_____| |_____ 34 35 # for the theory beind this file, and if you want to know what the stegosaurus is talking about, 36 # see Mobile Robot Localization using Kalman Filters by Jon Klein, Trenton Tabor 37 # http://tarsonis.dhcp.rose-hulman.edu/robot_kalman.pdf 38 16 39 17 40 from thread import start_new_thread … … 19 42 from rb.utils import meter_offset 20 43 44 import pylab 45 from numpy import * 46 47 # constants for state matrix 48 LONGITUDE = 0 49 LATITUDE = 1 50 LOCATION = 0:2 51 LINEAR_VELOCITY = 2 52 ORIENTATION = 3 53 ANGULAR_VELOCITY = 4 54 55 STATE_SIZE = 5 # number of dimensions tracked in the state matrix 56 GPS_TIMESTEP = 1 # update rate for GPS 57 COMPASS_TIMESTEP = .1 # update rate for compass 58 MAX_LINEAR_ACCELERATION = 9.8 # maximum possible linear acceleration 21 59 22 60 class KalmanFilter(object): … … 44 82 self.gps_zero = None 45 83 46 # Raw sensor data for use before the filter has actually 47 # been implemented 48 self._x_y = (0, 0) 49 self._orient = 0 50 # TODO 84 # state matrix, see (10), initialize states to zero 85 self.state_matrix = mat(zeros((STATE_SIZE,1))) 86 self.state_matrix[LOCATION] = 0 87 self.state_matrix[LINEAR_VELOCITY] = 0 88 self.state_matrix[ANGULAR_VELOCITY] = 0 89 self.state_matrix[ORIENTATION] = 0 90 91 # constant modeling error matrix Q, see (11-15) 92 self.modeling_error = mat(zeros((STATE_SIZE,STATE_SIZE))) 93 location_error = (GPS_TIMESTEP ** 2) * MAX_LINEAR_ACCELERATION / 2 94 orientation_error = (COMPASS_TIMESTEP ** 2) * MAX_ANGULAR_ACCELERATION / 2 95 self.modeling_error[LATITUDE,LATITUDE] = location_error 96 self.modeling_error[LONGITUDE,LONGITUDE] = location_error 97 self.modeling_error[LINEAR_VELOCITY,LINEAR_VELOCITY] = ENCODER_TIMESTEP * MAX_LINEAR_ACCELERATION 98 self.modeling_error[ANGULAR_VELOCITY, ANGULAR_VELOCITY] = ENCODER_TIMESTEP * MAX_ANGULAR_ACCELERATION 99 self.modeling_error[ORIENTATION, ORIENTATION] = orientation_error 100 101 # noise model matrix R, let's assume we begin with no noise, see (19) 102 self.measurement_noise = mat(zeros((STATE_SIZE,STATE_SIZE))) 103 104 # boring, identity matrix 105 self.identity = mat(eye(STATE_SIZE,STATE_SIZE)) 106 107 # transistion matrix, see (16) 108 self.transistion = mat(eye(STATE_SIZE, STATE_SIZE); 109 110 def _update_(self) 111 def _update_transistion_matrx(self) 112 ''' 113 Update the transistion matrix to take into accout changes in one dimension effecting changes in another dimension 114 See robot model, (4.4) 115 ''' 116 117 self.transistion(ORIENTATION,ANGULAR_VELOCITY) = ENCODER_TIMESTEP 118 self.transistion(LATITUDE, VELOCITY) = ENCODER_TIMESTEP * cos(self.state_matrix(ANGULAR_VELOCITY)) 119 self.transistion(LONGITUDE, VELOCITY) = ENCODER_TIMESTEP * sin(self.state_matrix(ANGULAR_VELOCITY)) 51 120 52 121 def update_target_speed(self, data): … … 54 123 Update filter with the target speed. 55 124 ''' 56 125 57 126 def update_encoders(self, data): 58 127 ''' 59 128 Update the filter with encoder data. 129 data.left is change in distance, in meters, from the left encoder 130 data.right is the change in distance, in meters, from the right encoder 60 131 ''' 61 132 # updates the angular and linear velocity 133 # see (2.1.3), 134 135 H = mat(zeros((STATE_SIZE,1))); 136 H[LINEAR_VELOCITY] = 1 137 H[ANGULAR_VELOCITY] = 1 138 62 139 def update_microstrain(self, accel): 63 140 ''' 64 141 Update the filter with data from the Microstrain. 65 142 ''' 66 self._orient = accel.orient[2] 143 144 H = mat(zeros((STATE_SIZE,1))) 145 H[ORIENTATION] = 1 146 147 self._orient = accel.orient[2] 67 148 68 149 def update_gps(self, coords): … … 70 151 Update the filter with data from the GPS. 71 152 ''' 153 154 H = mat(zeros((STATE_SIZE,1))); 155 H[LONGITUDE] = 1 156 H[LATITUDE] = 1 157 72 158 if self.gps_zero is None: 73 159 # Use the robot's initial location as zero 74 160 self.gps_zero = coords.lat_lon 75 161 self._x_y = meter_offset(self.gps_zero, coords.lat_lon) 76 162 163 def measurement_update(self, H) 164 ''' 165 166 ''' 167 168 77 169 def update_drive_speed(self, (lspeed, rspeed)): 78 170 ''' 79 171 Update the filter with data based on the drive motors. Calculate the 80 172 rotational velocity and change in position based on dead reckoning. 173 Not actually used for anything, you may not want to call this function. . 81 174 ''' 82 175 pass # TODO

