Spike V3 Sample
Simple Example Program
Last updated
Simple Example Program
Last updated
The following program describes the process that can be undertaken to develop a program for the SPIKE V3.
First this assumes that the robot is holonomic - that means that the robot is designed to face the goals while being able to move in any direction.
Students should first build up functions that move the robot in the common directions that the robot will move. The following layout shows the blocks that help students understand the desired movements:
Each of these blocks are filled with the movement motor blocks:
Be sure to include rotation movement, this will help us re-align our robot to the starting position.
The next part is to build a simple loop that reads the robot position, ball position and optionally the ball strength.
Have the students map out the direction they think the robot should undertake:
This is a non complete sample program:
The code above will have the robot rotate if the alignment is out by 20 degrees or more. The code then will move the robot depending on the position of the ball.
The ideal path is to create an orbit around the ball, the robot should be moving backwards behind the ball and only move forward when the ball is in front of the robot. Try to avoid forward movements until the ball is in front of the robot. As the sensor values and robot position changes, with the correct movement values the robot will naturally orbit the ball. Imagine that the ball is located at position 5 (back right). If the robot moves diagonal back right (assume the ball is stationary) the robot will eventually see the ball at sensor 3 or 4, which should also keep the robot moving to the right. The robot will then see sensor 1 or 12 and should then move forward, causing the orbit effect that is effective.
The challenge is to find the values and movement that work well for your robot. There is no secret combination, just lots of testing. Use the values of the ball strength to help make your path a little different (i.e. if the ball is on sensor 3 but far away, go directly towards the ball, not behind it). The ball signal strength is not a percentage value, you'll need to take readings and work out values that are meaningful to your robot.
Added Tip: Think about mounting the IR Seeker upside down or building structure over the sensors to limit light going into the board. You might find that this helps with better readings
Remember that all of the motor speeds should be defined, even if only two motors are used for a movement: