Load wheel diameter and wheel base width constants for the GoPiGo3 from file. This method gets called by the constructor. :param str config_file_path = "/home/pi/Dexter/gpg3_config.json": Path to JSON config file that stores the wheel diameter and wheel base width for the
(self, config_file_path="/home/pi/Dexter/gpg3_config.json")
| 144 | self.use_mutex = use_mutex |
| 145 | |
| 146 | def load_robot_constants(self, config_file_path="/home/pi/Dexter/gpg3_config.json"): |
| 147 | """ |
| 148 | Load wheel diameter and wheel base width constants for the GoPiGo3 from file. |
| 149 | |
| 150 | This method gets called by the constructor. |
| 151 | |
| 152 | :param str config_file_path = "/home/pi/Dexter/gpg3_config.json": Path to JSON config file that stores the wheel diameter and wheel base width for the GoPiGo3. |
| 153 | :raises FileNotFoundError: When the file is non-existent. |
| 154 | :raises KeyError: If one of the keys is not part of the dictionary. |
| 155 | :raises ValueError: If the saved values are not positive numbers (floats or ints). |
| 156 | :raises TypeError: If the saved values are not numbers. |
| 157 | :raises IOError: When the file cannot be accessed. |
| 158 | :raises PermissionError: When there are not enough permissions to access the file. |
| 159 | :raises json.JSONDecodeError: When the config file fails at parsing. |
| 160 | |
| 161 | Here's how the JSON config file must look like before reading it. Obviously, the supported format is JSON so that anyone can come in |
| 162 | and edit their own config file if they don't want to go through saving the values by using the API. |
| 163 | |
| 164 | .. code-block:: json |
| 165 | |
| 166 | { |
| 167 | "wheel-diameter": 66.5, |
| 168 | "wheel-base-width": 117 |
| 169 | } |
| 170 | |
| 171 | """ |
| 172 | with open(config_file_path, 'r') as json_file: |
| 173 | data = json.load(json_file) |
| 174 | if data['wheel-diameter'] > 0 and data['wheel-base-width'] > 0: |
| 175 | self.set_robot_constants(data['wheel-diameter'], data['wheel-base-width']) |
| 176 | else: |
| 177 | raise ValueError('positive values required') |
| 178 | |
| 179 | def save_robot_constants(self, config_file_path="/home/pi/Dexter/gpg3_config.json"): |
| 180 | """ |
no test coverage detected