MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / main

Function main

Software/C/Examples/motors.cpp:29–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27void exit_signal_handler(int signo);
28
29int 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
55void exit_signal_handler(int signo){

Callers

nothing calls this directly

Calls 4

detectMethod · 0.80
offset_motor_encoderMethod · 0.45
get_motor_encoderMethod · 0.45
set_motor_positionMethod · 0.45

Tested by

no test coverage detected