Skip to content

Commit

Permalink
Merge pull request #1189 from knorth55/fetch-battery-warning-suppress
Browse files Browse the repository at this point in the history
[jsk_fetch_startup] do not speak often when is_charging is True
  • Loading branch information
k-okada authored Dec 9, 2019
2 parents 4fbd7c9 + 1f2171b commit 06047b1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion jsk_fetch_robot/jsk_fetch_startup/scripts/battery_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self):
self.timer = rospy.Timer(rospy.Duration(self.duration), self._timer_cb)
self.charge_level = None
self.prev_charge_level = None
self.is_charging = False

def _speak(self, sentence):
req = SoundRequest()
Expand All @@ -33,7 +34,7 @@ def _speak(self, sentence):
self.speak_client.wait_for_result(timeout=rospy.Duration(10))

def _warn(self):
if self.charge_level < self.threshold:
if self.charge_level < self.threshold and not self.is_charging:
rospy.logerr("Low battery: only {}% remaining".format(self.charge_level))
sentence = "バッテリー残り{}パーセントです。".format(self.charge_level)
sentence += "もう限界ですので、僕をお家にかえしてください。"
Expand All @@ -48,6 +49,7 @@ def _warn(self):
def _cb(self, msg):
is_first_time = self.charge_level is None
self.charge_level = int(msg.charge_level * 100)
self.is_charging = msg.is_charging
if is_first_time:
self.prev_charge_level = self.charge_level + self.step
self._warn()
Expand Down

0 comments on commit 06047b1

Please sign in to comment.