| 27 | void exit_signal_handler(int signo); |
| 28 | |
| 29 | int main(){ |
| 30 | signal(SIGINT, exit_signal_handler); // register the exit function for Ctrl+C |
| 31 | |
| 32 | GPG.detect(); // Make sure that the GoPiGo3 is communicating and that the firmware is compatible with the drivers. |
| 33 | |
| 34 | // Reset the encoders |
| 35 | GPG.offset_motor_encoder(MOTOR_LEFT, GPG.get_motor_encoder(MOTOR_LEFT)); |
| 36 | GPG.offset_motor_encoder(MOTOR_RIGHT, GPG.get_motor_encoder(MOTOR_RIGHT)); |
| 37 | |
| 38 | while(true){ |
| 39 | // Read the encoders |
| 40 | int32_t EncoderLeft = GPG.get_motor_encoder(MOTOR_LEFT); |
| 41 | int32_t EncoderRight = GPG.get_motor_encoder(MOTOR_RIGHT); |
| 42 | |
| 43 | // Use the encoder value from the left motor to control the position of the right motor |
| 44 | GPG.set_motor_position(MOTOR_RIGHT, EncoderLeft); |
| 45 | |
| 46 | // Display the encoder values |
| 47 | printf("Encoder Left: %6d Right: %6d\n", EncoderLeft, EncoderRight); |
| 48 | |
| 49 | // Delay for 20ms |
| 50 | usleep(20000); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // Signal handler that will be called when Ctrl+C is pressed to stop the program |
| 55 | void exit_signal_handler(int signo){ |
nothing calls this directly
no test coverage detected