Theory
🤖🚗 13. Light sensors in Open Roberta Lab
Step 1: 🚀 Start Your Project:
- Once the page is open, look for “Choose your system.”
- Select “Open Robot Sim” and click on it.
Step 2: 🎚️ Set Variables:
Click on the variable section four times to create four variables.
Name them:
- Error
- Gain
- Steer
Light Target:
- Step 3: 📝 Enter Values:
- For ‘Gain’, enter the value 10.
- For ‘Light Target’, enter the value 50.
- Step 4: ⚙️ Set Up Actions:
- Go to the action block and select “drive forward.”
- Then, go to the control block and choose “repeat identity T.”
- Step 5: 🛣️ Program the Drive:
- In the drive block, set the drive speed to 60.
- Use the variable block to set errors, then go to the math block to adjust the values.
- Choose the light target from the variables and subtract it from the sensor block’s light sensor value.
- Step 6: 🚏 Adjust Steering:
- Set steer using the variable block.
- Choose a math block and add the error variable.
- Multiply it by the gain you set earlier.
- Step 7: 🧭 Finalize the Direction:
- Go to the action block, select “right,” and adjust the value.
- Replace it with the steer variable from the variable block.
- Step 8: 🎮 Simulate and Test:
- Click on the simulation view button.
- Change your background to show red and green lights.
- Start your program and watch your robot react to the green and red lights. When it’s green, the robot moves; when it’s red, it stops.
- Step 9: 👀 Observe and Learn:
- Watch how your robot navigates towards the green light and avoids the red light.
- See how changing the values affects the robot’s behaviour.
🎉 Congratulations!
You’ve successfully programmed a robot in Open Roberta Lab to respond to red and green lights. Great job! Remember, if you get stuck or something doesn’t work, don’t worry! Ask an adult or a friend for help, and keep trying. Learning to program is all about experimenting and solving problems. Good luck! 🤖💖