Here's the full Blockly code for the basic rolling ball robot:

The code consists of three sections:
- Configuration - Configuration sets up the hardware when the robot is first powered. In this example it configures the PWM outputs (naming each we want to use) and configuring a continuous servo attached to each of these PWM outputs.
- Setup - Setup is code run once after the configuration is complete. Here it defines a constant used to scale the motor velocities.
- Activities - Activities are the heart of the robot (there is one here, but you can have many). Each activity monitors changing inputs used within itself and when a change is detected, runs the code to process those changes. For the rolling ball robot, the activity is monitoring the input joystick and, when it changes, runs to code to change to velocity of each of the robot's wheels.
One of the major changes I've made to the Blockly setup since I started this project is the addition of Parts. Parts are stateful objects which can either be the software representation of additional hardware (such as a Continuous Servo) or an entirely virtual thing (such as a Tank axle).
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.