Greetings!
Inviting @cleoqc to the discussion.
I have been studying the gopigo3.py file to understand how to read configuration data into a program at runtime, and I noticed something odd. . .
Note the following segment of the code where the read data is parsed:
[Lines 391 - 406]
try:
with open(config_file_path, 'r') as json_file:
data = json.load(json_file)
# Check for the presence of ticks and positive value
if 'ticks' in data:
ticks = data['ticks']
# Check for the presence of motor_gear_ratio
if motor_gear_ratio in data:
motor_gear_ratio = data['motor_gear_ratio']
if data['wheel-diameter'] > 0 and data['wheel-base-width'] > 0 and ticks > 0 and motor_gear_ratio > 0:
self.set_robot_constants(data['wheel-diameter'], data['wheel-base-width'], ticks, motor_gear_ratio )
else:
raise ValueError('positive values required')
Note that there are two lines in the if stack that read values directly
if 'ticks' in data:
if motor_gear_ratio in data:
Also note that “ticks” is surrounded by single quotes but “motor_gear_ratio” is not.
Earlier in the file, the structure of the json configuration file is described within a comment block:
"""
[snip]
{
"wheel-diameter": 66.5,
"wheel-base-width": 117,
"ticks": 6,
"motor_gear_ratio": 120
}
"""
Correct me if I am wrong, but both “ticks” and “motor_gear_ratio” are enumerated values within the configuration json file, and get loaded into a dictionary variable named “data”.
That being the case, shouldn’t “motor_gear_ratio” be quoted since it also appears to be a “key” value in the “data” dictionary?
What say ye?