Software

From Bespoke Robot Society
Jump to navigation Jump to search
Software
Programming robots to perform tasks and managing their behavior
Difficulty Range Beginner to Advanced
Time to Basic 2-3 weeks
Essential Tools Text editor or IDE (Thonny), USB cable, microcontroller
Optional Tools Debugger, serial monitor, version control (Git)
Get Started MicroPython Basics
Unlocks (Basic) All robot capabilities (software is required for every robot)
Unlocks (Advanced) Capability:IMU Sensing, Capability:Camera Vision, Activity:Autonomous Navigation

Software is the competency of programming robots and managing their behavior. In robotics, software is the brain that coordinates sensors, actuators, and decision-making logic. It encompasses writing code, debugging programs, using libraries, and managing complex multi-process systems.

Software is distinct from Electronics (the hardware interface) and Mechanics (the physical structure). This competency focuses on programming: writing algorithms, controlling hardware through code, and building intelligent behaviors.

Why Software Matters for Robotics

Software brings robots to life:

  • Sensors provide data, but software interprets it
  • Actuators can move, but software decides when and how
  • Behaviors emerge from code that combines sensing and action
  • Intelligence comes from algorithms, state machines, and decision logic

Without software knowledge, you're limited to pre-programmed behaviors and cannot create custom robot capabilities.

Skill Progression

Beginner (SimpleBot Level)

Skills you need to program SimpleBot:

  • MicroPython basics - Variables, functions, loops, conditionals
  • Flashing firmware - Install MicroPython on Raspberry Pi Pico
  • Using an IDE - Write and upload code with Thonny
  • REPL interaction - Interactive Python shell for testing
  • GPIO control - Read sensors, control motors with digital I/O
  • Simple programs - Blink LED, read button, control motor direction
  • Debugging - Print statements, LED indicators, REPL error messages

Unlocks:

Tutorials: MicroPython Basics, MicroPython Programming

At this level you can:

  • Write simple MicroPython programs for Raspberry Pi Pico
  • Control LEDs, buttons, and motors with GPIO
  • Read sensor values and make decisions based on them
  • Debug basic program errors
  • Implement simple robot behaviors (line following, obstacle detection)

Intermediate (Expanding Capabilities)

Skills for implementing complex robot behaviors:

  • Interrupts - Hardware interrupts for encoder counting, timing-critical events
  • PWM generation - Precise motor speed control, servo positioning
  • Timers - Periodic tasks, non-blocking delays
  • Communication protocols - I2C and SPI libraries for sensors
  • State machines - Organize complex behaviors with states and transitions
  • Sensor fusion - Combine multiple sensors for robust perception
  • Asynchronous programming - Use asyncio for concurrent tasks
  • Calibration - Tune sensor thresholds, motor speeds, PID parameters

Unlocks:

Tutorials: MicroPython Programming, State Machine Design

At this level you can:

  • Implement interrupt-driven encoder counting
  • Control motor speeds with PWM
  • Read I2C and SPI sensors using libraries
  • Design state machines for complex behaviors
  • Write asynchronous code for concurrent tasks
  • Calibrate sensors and tune control parameters
  • Debug timing and concurrency issues

Advanced (Autonomous Systems)

Skills for building sophisticated autonomous robots:

  • Computer vision - OpenCV for camera-based perception
  • ROS (Robot Operating System) - Distributed system for complex robots
  • Path planning - A*, Dijkstra, RRT algorithms
  • SLAM - Simultaneous Localization and Mapping
  • Multi-process systems - Separate processes for perception, planning, control
  • Docker containers - Portable, reproducible software environments
  • Real-time systems - Guarantee timing constraints for safety-critical tasks
  • Machine learning - Neural networks for perception and control

Unlocks:

Tutorials: ROS Basics, OpenCV for Robotics, Docker for Robots

At this level you can:

  • Build ROS-based systems with multiple nodes
  • Implement computer vision algorithms with OpenCV
  • Deploy robot software in Docker containers
  • Design path planning and navigation algorithms
  • Integrate machine learning models for perception
  • Build real-time control systems
  • Manage complex multi-process robotic systems

Learning Paths

Path 1: MicroPython Beginner (SimpleBot)

  1. Start with MicroPython Basics - Learn Python, GPIO, and basic control
  2. Build SimpleBot - Apply programming to a real robot
  3. Complete MicroPython Programming - Learn interrupts, PWM, and I2C

Result: You can program SimpleBot and implement basic robot behaviors.

Path 2: Embedded Systems Developer (Intermediate)

  1. Complete Path 1 (MicroPython Beginner)
  2. Study State Machine Design - Organize complex behaviors
  3. Implement Behavior:PID Control - Closed-loop motor control
  4. Add advanced sensors (IMU, encoders) to your robot

Result: You can write sophisticated control algorithms and handle multiple sensors.

Path 3: Autonomous Robotics Engineer (Advanced)

  1. Complete Path 2 (Embedded Systems Developer)
  2. Learn ROS Basics - Distributed robotics framework
  3. Study OpenCV for Robotics - Computer vision for perception
  4. Build a robot with camera-based navigation

Result: You can build autonomous robots with vision, mapping, and planning capabilities.

Essential Concepts

Programming Fundamentals

  • Variables - Store sensor readings, motor states, calculated values
  • Functions - Organize code into reusable blocks (read_sensor, drive_forward)
  • Loops - Repeat actions (while True: read sensors, decide, act)
  • Conditionals - Make decisions (if line_detected: turn_left)

Hardware Control

  • Digital I/O - Read HIGH/LOW from sensors, write HIGH/LOW to motors
  • Analog I/O - Read variable voltages with ADC (battery level, photoresistor)
  • PWM - Generate pulse-width modulation for motor speed, servo position
  • Interrupts - Respond immediately to events (encoder pulse, button press)

Communication Protocols

  • I2C - Communicate with sensors (IMU, distance sensor, OLED display)
  • SPI - High-speed communication (SD card, some sensors)
  • UART/Serial - Debug output, GPS modules, Bluetooth communication

Control Structures

  • State machines - Organize behaviors with states (SEARCHING, FOLLOWING, TURNING)
  • PID control - Closed-loop control for speed, position, line following
  • Sensor fusion - Combine multiple sensors for robust measurements
  • Event-driven programming - Respond to interrupts, timers, external events

Debugging Techniques

  • Print debugging - Print sensor values, state transitions to serial console
  • LED indicators - Visual feedback for program state (blinking patterns)
  • REPL testing - Test functions interactively before running full program
  • Oscilloscope/logic analyzer - Visualize PWM signals, I2C communication

Tools and Equipment

Essential Tools (Start Here)

  • Text editor or IDE (Free) - Thonny (recommended for beginners), VS Code, Mu Editor
  • USB cable ($2-5) - Connect microcontroller to computer
  • Microcontroller ($4-10) - Raspberry Pi Pico (MicroPython), ESP32, Arduino
  • Serial terminal (Free, built into IDE) - View debug output, REPL interaction

Intermediate Tools

  • Version control (Free) - Git and GitHub for code management
  • Logic analyzer ($10-60) - Debug I2C, SPI, UART communication
  • Oscilloscope ($100-400) - Visualize PWM, timing, analog signals
  • Debugger ($10-50) - Hardware debugger for stepping through code

Advanced Tools

  • Single-board computer ($35-100) - Raspberry Pi for ROS, OpenCV
  • Development board ($50-200) - Jetson Nano for computer vision, neural networks
  • Docker (Free) - Container platform for reproducible environments
  • ROS (Free) - Robot Operating System for distributed robotics

Common Pitfalls

  • Blocking delays - Using time.sleep() prevents interrupt handling and responsiveness
  • Floating-point errors - Use integers for encoder counts, careful with division
  • Race conditions - Interrupts can modify variables during main loop calculations
  • Uninitialized variables - Always initialize variables before using them
  • Infinite loops without exit - Always include a way to stop or reset your program
  • Ignoring hardware timing - I2C/SPI require specific timing, PWM frequency affects motors
  • Memory leaks - MicroPython has limited RAM; avoid creating objects in tight loops

Programming Environments

MicroPython (Beginner-Friendly)

  • Platforms: Raspberry Pi Pico, ESP32, PyBoard
  • Pros: Easy to learn, interactive REPL, extensive libraries
  • Cons: Slower than C/C++, limited RAM
  • Best for: SimpleBot, learning robotics, rapid prototyping

Arduino (C/C++) (Popular)

  • Platforms: Arduino Uno, Nano, Mega, ESP32, Teensy
  • Pros: Fast execution, huge community, extensive libraries
  • Cons: Steeper learning curve, less interactive
  • Best for: Performance-critical tasks, larger community support

Python on SBC (Advanced)

  • Platforms: Raspberry Pi, Jetson Nano, Rock Pi
  • Pros: Full Python ecosystem (NumPy, OpenCV, ROS), multitasking
  • Cons: Not real-time, more expensive hardware
  • Best for: Computer vision, ROS, complex algorithms

ROS (Robot Operating System) (Advanced)

  • Platforms: Linux on SBC (Raspberry Pi, Jetson, x86)
  • Pros: Distributed system, reusable nodes, rich ecosystem
  • Cons: Steep learning curve, complex setup
  • Best for: Multi-sensor robots, navigation, manipulation

Tutorials and Resources

BRS Tutorials

Implementation Pages

External Resources

Related Competencies

  • Electronics - Understand the hardware that software controls
  • Mechanics - Design the physical systems that software commands
  • Soldering - Build the circuits that software interfaces with
  • 3D Printing - Create robot chassis to mount sensors and actuators

Example Programs

Blink LED (Hello World)

from machine import Pin
import time

led = Pin(25, Pin.OUT)  # Raspberry Pi Pico onboard LED

while True:
    led.toggle()
    time.sleep(0.5)  # 0.5 seconds

Read Button, Control LED

from machine import Pin

button = Pin(14, Pin.IN, Pin.PULL_UP)  # Active LOW button
led = Pin(25, Pin.OUT)

while True:
    if button.value() == 0:  # Button pressed (LOW)
        led.on()
    else:
        led.off()

PWM Motor Speed Control

from machine import Pin, PWM

motor_pwm = PWM(Pin(16))
motor_pwm.freq(1000)  # 1 kHz PWM frequency

# 50% speed
motor_pwm.duty_u16(32768)  # 50% of 65535 (16-bit)

# 75% speed
motor_pwm.duty_u16(49152)  # 75% of 65535

Interrupt-Driven Encoder

from machine import Pin

encoder_count = 0

def encoder_callback(pin):
    global encoder_count
    encoder_count += 1

encoder = Pin(15, Pin.IN, Pin.PULL_UP)
encoder.irq(trigger=Pin.IRQ_RISING, handler=encoder_callback)

# Count pulses while doing other work
while True:
    print(f"Count: {encoder_count}")
    time.sleep(1)

See Also