Watch the builds (opens in a new tab)
Build // Code // Launch02

Code

Short notes from the bench. Copy them, change the pin numbers, and run them. The repos below are still empty slots.

01 // Wait for the step Arduino

A joint that is still moving should not get the next angle. Hold the pose, then move.

#include <Servo.h>

Servo knee;
const int STEP_MS = 280;

void setup() {
  knee.attach(9);
}

void loop() {
  knee.write(40);
  delay(STEP_MS);
  knee.write(110);
  delay(STEP_MS);
}
02 // Mix a stick into two motors Python

Throttle and turn come off the stick as -1 to 1. This keeps each wheel inside that range.

def mix(throttle, turn):
    # Stick axes from -1 to 1. Returns left and right motor speeds.
    left = max(-1.0, min(1.0, throttle + turn))
    right = max(-1.0, min(1.0, throttle - turn))
    return left, right
03 // Stop before you hit it Arduino

Read the distance sensor. If something is inside 18 cm, stop. Otherwise keep rolling.

const int TRIG = 7;
const int ECHO = 8;
const int STOP_CM = 18;

long distanceCm() {
  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  long us = pulseIn(ECHO, HIGH, 30000);
  return us / 58;
}

void loop() {
  long cm = distanceCm();
  if (cm > 0 && cm < STOP_CM) stopMotors();
  else driveForward();
}

REPOS

Public repos are not up yet. Names and URLs below are placeholders.

  • [REPO NAME]Walker step · Arduino[REPO URL]
  • [REPO NAME]Motor mix · Python[REPO URL]
  • [REPO NAME]Range stop · Arduino[REPO URL]