sonyccd / roboclaw_ros

ros for roboclaw
BSD 2-Clause "Simplified" License
50 stars 92 forks source link

Fix to avoid TypeError with encoder count value of 'None' #16

Open Roger-random opened 6 years ago

Roger-random commented 6 years ago

SYMPTOM: Unpredictable errors occurring at runtime File "roboclaw_node.py", line 232, in run rospy.logdebug(" Encoders %d %d" % (enc1, enc2)) TypeError: %d format: a number is required, not NoneType

SEE: Issue #13

CAUSE: Error when calling roboclaw.ReadEnc would result in encoder values 'enc1' or 'enc2' to be None instead of a number. This triggers TypeError as described above.

FIX: Do exactly what TypeError wants us to do: make sure both 'enc1' and 'enc2' are numbers before trying to format them as numbers for logging. (Note this does not address root cause of ReadEnc failure, that will be submitted as a separate fix.)

REFERENCE: Python number check courtesy of StackOverflow: https://stackoverflow.com/questions/3441358/what-is-the-most-pythonic-way-to-check-if-an-object-is-a-number