Skip to content

Program Sequence

Adam-Englebright edited this page Apr 15, 2024 · 2 revisions

Core Program Sequence

At the core of our ShakeyTable program are two threads that run in parallel. One collects measurements from the MPU6050, and the other collects measurements from the INA260. Each thread has a loop that is blocked until their corresponding sensor raises its interrupt pin. Once the interrupt pin is raised, the loop will unblock and data will be read over I2C from the sensor. This data is then processed and passed to other objects to create the physical manipulation of the reaction wheel required to balance the cup holder.

One object, innerPID, is common to both threads. This object is what ultimately sends messages to the MD20 object that controls the motor driver. Both threads can send messages to innerPID in an asynchronous fashion. The MPU6050 thread will call the setSetpoint() method to set the PID setpoint (the desired plant output, in this case torque/current). The INA260 thread will call the calculate() method to pass a process variable (the actual plant output), calculate the PID output, and pass this output to a callback that will call the setDutyCycleDelta() method of the MD20 object to try achieve the desired torque.

Since it is the calculate() method called by the INA260 thread that ultimately controls the motor driver, it is this thread that really drives the program and causes the physical control of the reaction wheel. The MPU6050 thread simply sets the variable used for the setpoint of the PID controller. As such, the update rate of the motor driver output is set by the sampling rate of the INA260. Generally, the sample rate of the INA260 should be much higher than the MPU6050, since it is measuring an electrical system (motor current) that responds much faster than the mechanical system (cup holder angular position) measured by the MPU6050.

MPU6050 Data Acquisition

Below is the sequence diagram for the MPU6050 data acquisition thread. It can also be viewed here.

MPU6050 Sequence Diagram

INA260 Data Acquisition

Below is the sequence diagram for the INA260 data acquisition thread. It can also be viewed here.

INA260 Sequence Diagram

Clone this wiki locally