This class is used for controlling a `GoPiGo3`_ robot. With this class you can do the following things with your `GoPiGo3`_: * Drive your robot in any number of directions. * Have precise control over the direction of the robot. * Set the speed of the robot. * Turn *on
| 75 | |
| 76 | |
| 77 | class EasyGoPiGo3(gopigo3.GoPiGo3): |
| 78 | """ |
| 79 | This class is used for controlling a `GoPiGo3`_ robot. |
| 80 | |
| 81 | With this class you can do the following things with your `GoPiGo3`_: |
| 82 | |
| 83 | * Drive your robot in any number of directions. |
| 84 | * Have precise control over the direction of the robot. |
| 85 | * Set the speed of the robot. |
| 86 | * Turn *on* or *off* the blinker LEDs. |
| 87 | * Control the `GoPiGo3`_' Dex's *eyes*, *color* and so on ... |
| 88 | |
| 89 | .. needs revisiting |
| 90 | |
| 91 | .. warning:: |
| 92 | |
| 93 | Without a battery pack connected to the `GoPiGo3`_, the robot won't move. |
| 94 | |
| 95 | """ |
| 96 | |
| 97 | def __init__(self, config_file_path="/home/pi/Dexter/gpg3_config.json", use_mutex=False): |
| 98 | """ |
| 99 | This constructor sets the variables to the following values: |
| 100 | |
| 101 | :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. |
| 102 | :param bool use_mutex = False: When using multiple threads/processes that access the same resource/device, mutex has to be enabled. |
| 103 | :var int speed = 300: The speed of the motors should go between **0-1000** DPS. |
| 104 | :var tuple(int,int,int) left_eye_color = (0,255,255): Set Dex's left eye color to **turqoise**. |
| 105 | :var tuple(int,int,int) right_eye_color = (0,255,255): Set Dex's right eye color to **turqoise**. |
| 106 | :var int DEFAULT_SPEED = 300: Starting speed value: not too fast, not too slow. |
| 107 | :raises IOError: When the GoPiGo3 is not detected. It also debugs a message in the terminal. |
| 108 | :raises gopigo3.FirmwareVersionError: If the GoPiGo3 firmware needs to be updated. It also debugs a message in the terminal. |
| 109 | :raises Exception: For any other kind of exceptions. |
| 110 | |
| 111 | The ``config_file_path`` parameter represents the path to a JSON file. The presence of this configuration file is optional and is only required in cases where |
| 112 | the GoPiGo3 has a skewed trajectory due to minor differences in these two constants: the **wheel diameter** and the **wheel base width**. In most cases, this won't be the case. |
| 113 | |
| 114 | By-default, the constructor tries to read the ``config_file_path`` file and silently fails if something goes wrong: wrong permissions, non-existent file, improper key values and so on. |
| 115 | To set custom values to these 2 constants, use :py:meth:`~easygopigo3.EasyGoPiGo3.set_robot_constants` method and for saving the constants to a file call |
| 116 | :py:meth:`~easygopigo3.EasyGoPiGo3.save_robot_constants` method. |
| 117 | |
| 118 | """ |
| 119 | try: |
| 120 | super(self.__class__, self).__init__() |
| 121 | except IOError as e: |
| 122 | print("FATAL ERROR:\nGoPiGo3 is not detected.") |
| 123 | raise e |
| 124 | except gopigo3.FirmwareVersionError as e: |
| 125 | print("FATAL ERROR:\nTo update the firmware on Raspbian for Robots you need to run DI Software Update and choose Update Robot") |
| 126 | raise e |
| 127 | except Exception as e: |
| 128 | raise e |
| 129 | |
| 130 | # load wheel diameter & wheel base width |
| 131 | # should there be a problem doing that then save the current default configuration |
| 132 | try: |
| 133 | self.load_robot_constants() |
| 134 | except Exception: |
no outgoing calls
no test coverage detected