System:
Pi-4 running GoPiGo O/S
Issue:
If you attach a similar and/or identical piece of hardware to more than one robot, the behaviors will be different, requiring differing adjustments and/or calibration constants that can vary based on which piece of equipment is running the code.
Solution:
You can read the robot’s unique serial number with the getid()
method within the easygopigo3
library, and use that to make specific adjustments or changes based on the serial number of the hardware itself.
Background:
I now have two robots that may, (or may not), run the same code - for example moving the two servos on the robot’s pan and tilt to indicate that the robot is awake and alive.
Due to unavoidable manufacturing and construction tolerances, “center/center” for one 'bot won’t be the same as “center/center” for the other one.
Solution:
I wrote code that can read the robot’s serial number and - in this case - apply a specified “center/center” calibration factor to the robot running the code.
Viz:
# Read the connected robot's serial number
serial_number = easy_gpg.get_id() # read and display the serial number
# For testing only - invalid or testing serial number
#serial_number = "A0F6E45F4E514B4B41202020FF152B10"
print("Robot's serial number is", serial_number, "\n")
# Servo constants for each robot
# Charlene:
if serial_number == "A0F6E45F4E514B4B41202020FF152B11":
# Charlene's servo constants
print("Robot is \"Charlene\"")
center_1 = 86
center_2 = 80
right = center_1 - 45
left = center_1 + 45
up = center_2 - 45
down = center_2 + 45
# Charlie:
elif serial_number == "64B61037514E343732202020FF111A05":
# Charlie's servo constants
print("Robot is \"Charlie\"")
center_1 = 86
center_2 = 90
right = center_1 - 45
left = center_1 + 45
up = center_2 - 45
down = center_2 + 45
else:
print("I don't know who robot", serial_number, "is,")
print("(or if it's even a robot for that matter. . .)\n")
print("Servo's may not exist so this process is aborting.")
quit()
Using code like this in your Python scripts can allow you to customize behaviors based on the particular robot you’re using.