1. German Larrain
  2. ars

Commits

German Larrain  committed 74679c8

RSS1: bugfix regarding the last step of the (time,speed) pairs sequence

  • Participants
  • Parent commits 6b83d3d
  • Branches dev

Comments (0)

Files changed (1)

File bin/RSS1.py

View file
 			time = self.sim.sim_time
 			#print(time)
 			
-			if self.speed_i < len(self.speeds) - 2:
+			if self.speed_i < len(self.speeds) - 1:
 				if time > self.speeds[self.speed_i + 1][0]:
 					self.speed_i += 1
+			elif self.speed_i == len(self.speeds) - 1:
+				pass
 			
 			sp = self.calc_desired_speed(time)
 			linear_vel = self.sim.get_object(self.chassis).get_linear_velocity()
 	
 	def calc_desired_speed(self, time):
 		
-		time_diff = time - self.speeds[self.speed_i][0]
-		time_period = self.speeds[self.speed_i + 1][0] - self.speeds[self.speed_i][0]
-		
 		if self.speed_i == len(self.speeds) - 1:
 			return float(self.speeds[self.speed_i][1])
+		
 		elif 0 <= self.speed_i < len(self.speeds) - 1:
+			time_diff = time - self.speeds[self.speed_i][0]
+			time_period = self.speeds[self.speed_i + 1][0] - self.speeds[self.speed_i][0]
 			prev_speed = float(self.speeds[self.speed_i][1])
 			next_speed = float(self.speeds[self.speed_i + 1][1] )
 			return (next_speed - prev_speed) * (time_diff / time_period) + prev_speed