Answering in a separate thread to allow for expansion on this topic:
The GoPiGo3 red board has lots of set and get commands:
$ grep "GET_" ~/Dexter/GoPiGo3/Software/Python/gopigo3.py GET_MANUFACTURER, GET_NAME, GET_HARDWARE_VERSION, GET_FIRMWARE_VERSION, GET_ID, GET_VOLTAGE_5V, GET_VOLTAGE_VCC, GET_MOTOR_ENCODER_LEFT, GET_MOTOR_ENCODER_RIGHT, GET_MOTOR_STATUS_LEFT, GET_MOTOR_STATUS_RIGHT, GET_GROVE_VALUE_1, GET_GROVE_VALUE_2, GET_GROVE_STATE_1_1, GET_GROVE_STATE_1_2, GET_GROVE_STATE_2_1, GET_GROVE_STATE_2_2, GET_GROVE_VOLTAGE_1_1, GET_GROVE_VOLTAGE_1_2, GET_GROVE_VOLTAGE_2_1, GET_GROVE_VOLTAGE_2_2, GET_GROVE_ANALOG_1_1, GET_GROVE_ANALOG_1_2, GET_GROVE_ANALOG_2_1, GET_GROVE_ANALOG_2_2, $ grep "SET_" ~/Dexter/GoPiGo3/Software/Python/gopigo3.py SET_LED, SET_SERVO, SET_MOTOR_PWM, SET_MOTOR_POSITION, SET_MOTOR_POSITION_KP, SET_MOTOR_POSITION_KD, SET_MOTOR_DPS, SET_MOTOR_LIMITS, OFFSET_MOTOR_ENCODER, SET_GROVE_TYPE, SET_GROVE_MODE, SET_GROVE_STATE, SET_GROVE_PWM_DUTY, SET_GROVE_PWM_FREQUENCY,
But noticeably missing are:
When a user instantiates an EasyGoPiGo3 class object to talk with the red board GoPiGo3 controller, the EasyGoPiGo3 class performs these initializations even if the board was already initialized by another EasyGoPiGo3 object in a different process:
self.sensor_1 = None self.sensor_2 = None self.DEFAULT_SPEED = 300 self.NO_LIMIT_SPEED = 1000 self.set_speed(self.DEFAULT_SPEED) self.left_eye_color = (0, 255, 255) self.right_eye_color = (0, 255, 255) self.use_mutex = use_mutex
There is no such thing as a “single, visible to every EasyGoPiGo3 object, red board software object” that could remember the state of the speed limit, provide access to any initialized sensors, and remember the type and mode of the Grove ports.
For most use cases this really is esoteric. The GoPiGo3 is so phenomenally rich with learning capabilities, that only a very advanced user would need this complexity, and that advanced user is not prevented from creating a single software access point to the red board and a software system design that offers multi-threaded, multi-process red board state access and management.
Can classes have privately global flags/variables? That is, something local to the class that can be set and read by any instance of the class?
Yes, but not across different processes’ memory space. It would be a big security nightmare to default to allowing access to an object’s values from outside the process.
That said, Python is replete with packages that make interprocess communication and parallel processing easier than writing it from scratch. Albeit, simple APIs for complex concepts do not make designing with complex concepts easy.