Writing the code
The code you are going to create is one where the robot will be able to do the following:
- Stay in the arena by stopping and backing up when the white rim of the arena is detected.
- Speed up to push an opponent out of the arena when the ultrasonic sensor detects an object up close.
- Speed up to push an opponent out of the arena when the force sensor detects touch from behind.
In all, there are six code stacks to make this happen. Let's begin.
The ports
You will connect the medium motors to ports C and F, the color sensor to port A, the ultrasonic sensor to port D, and the force sensor to port E:
Before you code, you will need to add a More Movement extension block to your coding options. At the bottom left of your coding canvas, there is an extension block icon. Click on this icon, click on Show block extensions and select More Movement: