0

Soccer Robot C - Basic lessons - Exercises - Inclination

As we are familiarized with the compass already, we can learn about 2 other functions IMU offers:
  • pitch() - measures how much the robot is inclined forward or backward.
  • roll() - measures how much the robot is inclined left or right.
Left-right and forward-backward are relative terms because they depend on the direction MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32) is mounted on the robot. If You followed building instructions, pitch() will be for left-right. This program is similar to the one in the previous (IMU) lesson:
void RobotSoccer::loop() {
	print("%i° %i°\n\r", (int)pitch(), (int)roll());
}
The difference is that print() now contains 2 times "%i" part. That means: "leave placeholders for 2 integer numbers". The numbers must be supplied after the string, separated with commas, and that's how it is: the first one is pitch, the second one roll. Run this program and check that the pitch changes when You incline the robot with front-end up or down.

Task: detect inclination.

Write a program that will move the robot straight ahead but will shut down robot's motors when the operator picks it up. Assume that in that case pitch will be either more than 5° or less than -5°.