Created
May 8, 2010 07:44
-
-
Save dekz/394431 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def pos_tracker(self, t_speed, r_speed): | |
| delta_th = r_speed*12 | |
| self.theta = self.theta + delta_th | |
| theta_rad = (self.theta * math.pi)/180 #convert to radians | |
| delta_r = t_speed*math.cos(delta_th) #change in rotation | |
| delta_x = delta_r * math.cos(theta_rad) #change in x | |
| delta_y = delta_r * math.sin(theta_rad) #change in y | |
| self.total_x = self.total_x + delta_x | |
| self.total_y = self.total_y + delta_y | |
| self.total_x = round(self.total_x, 3) | |
| self.total_y = round(self.total_y, 3) | |
| lastItem = [] | |
| positionsLength = len(self.positions) | |
| if (positionsLength > 0): | |
| lastItem = self.positions[positionsLength-1] | |
| #if the last stored item minus the new x and y is noticeable value store it | |
| if (abs(self.total_x)-abs(lastItem[0]) > 1.0 or abs(self.total_y)-abs(lastItem[1]) > 1.0) and (self.total_x != lastItem[0] and self.total_y != lastItem[1]): | |
| self.positions.append([round(self.total_x, 3), round(self.total_y, 3), delta_r]) | |
| print round(self.total_x, 3), round(self.total_y, 3), delta_r | |
| print lastItem[0], lastItem[1], lastItem[2] | |
| else: | |
| self.positions.append([self.total_x, self.total_y, delta_r]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment