0

Line Robot - Basic lessons - Exercises - Slope

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 forward-backward. This program is similar to the one in the previous (IMU) lesson:
void RobotLine::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 a slope.

Write a program that will increase robot's speed by 50 % when going uphill and reduce by 50 % when going downhill.