-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot_config_manager.py
More file actions
57 lines (37 loc) · 1.24 KB
/
Copy pathrobot_config_manager.py
File metadata and controls
57 lines (37 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import json
def load_config():
try:
with open("robot_config.json", "r") as file:
config = json.load(file)
return config
except FileNotFoundError:
print("Error: configuration file not found.")
except json.JSONDecodeError:
print("Error: configuration file contains invalid JSON.")
return None
def display_config(config):
print("\n--- Robot Configuration ---")
print("Name:", config["name"])
print("Wheel radius:", config["wheel_radius"])
print("Maximum speed:", config["max_speed"])
print("Sensors:", config["sensors"])
print("Battery capacity:", config["battery_capacity"])
def save_config(config):
try:
with open("robot_config.json", "w") as file:
json.dump(config, file, indent=4)
print("Configuration saved successfully.")
except OSError:
print("Error: could not save configuration.")
def main():
config = load_config()
if config is None:
return
display_config(config)
#Modify configuratioon
new_speed = float(input("\nEnter new maximum speed: "))
config["max_speed"] = new_speed
print("\nUpdated configuration:")
display_config(config)
save_config(config)
main()