Exemple #1
0
 def get_raw_value(self, position):
   """
   @param position: a human-friendly servo position, specified as a
     floating-point number between -1.0 and 1.0
   @return: the corresponding raw PWM integer value
   """
   if self._id is None:
     raise ServoError(
       "The servo '%s' has not been configured" % self._name)
   if position < 0:
     return int(saturate(position, -1.0, 0.0, self._min, self._center))
   else:
     return int(saturate(position, 0.0, 1.0, self._center, self._max))
Exemple #2
0
 def get_raw_value(self, position):
     """
 @param position: a human-friendly servo position, specified as a
   floating-point number between -1.0 and 1.0
 @return: the corresponding raw PWM integer value
 """
     if self._id is None:
         raise ServoError("The servo '%s' has not been configured" %
                          self._name)
     if position < 0:
         return int(saturate(position, -1.0, 0.0, self._min, self._center))
     else:
         return int(saturate(position, 0.0, 1.0, self._center, self._max))
Exemple #3
0
 def get_level(self):
     """
 @return: the current charge of the battery as a percentage.
 """
     if self.charge is None:
         return None
     return saturate(self.charge, self.empty, self.full, 0, 100)
 def get_level(self):
   """
   @return: the current charge of the battery as a percentage.
   """
   if self.charge is None:
     return None
   return saturate(self.charge, self.empty, self.full, 0, 100)
Exemple #5
0
 def get_command(self, now):
   """
   Queries the status of the subcomponents and returns the 
   final Recommendation object that sets the throttle and 
   steering.
   @return: Recommendation
   """
   rec = self._get_command_core(now)
   if rec.throt > 0.0:
     rec.throt = saturate(rec.throt, 
                          0.01, 1.0,
                          self.min_throttle, self.max_throttle)
   return rec
Exemple #6
0
  def on_update(self, msg, now):
    forward = msg.x
    turn = msg.y

    if self.status == Ranger.PANIC:
      self.rec = Recommendation(0.0, 0.0)
      if self.panic_until < now:
        self.status = Ranger.ESCAPE
        self.escape_until = now + self.escape_duration

    elif self.status == Ranger.ESCAPE:
      self.rec = Recommendation(self.escape_speed,
                                turn * self.kp_steering_rev)
      if self.escape_until < now:
        self.status = Ranger.REGROUP
        self.regroup_until = now + self.regroup_duration

    elif self.status == Ranger.REGROUP:
      self.rec = Recommendation(0.0, 0.0)
      if self.regroup_until < now:
        self.status = Ranger.GO

    elif forward < self.panic_threshold:
      self.rec = Recommendation(0.0, 0.0)
      self.status = Ranger.PANIC
      self.panic_until = now + self.panic_duration

    else:
      new_throttle = saturate(forward, self.x_low,
                                       self.x_high,
                                       0.01, 1.0)
      new_steering = turn * self.kp_steering
      if self.rec:
        if abs(new_steering) < abs(self.rec.steer):
          new_steering = self.smooth(new_steering, self.rec.steer)
      self.rec = Recommendation(new_throttle, new_steering)
Exemple #7
0
 def on_update(self, msg, now):
   throttle = saturate(msg.x, 
                       self.x_low, self.x_high,
                       0.01, 1.0)
   steering = msg.y * self.kp_steering
   self.rec = Recommendation(throttle, steering)