Masterclass V1.0.6
Hexapod Walking Gait
The Challenge
"Coordinating 6 legs at once is usually a nightmare. Most people write hundreds of if statements and end up with a twitchy mess. I'm going to do it with math, because math actually works."
01. Installation
Before I do anything, let's get the engine installed on your machine. This gives me the high-speed "Heartbeat" I need for smooth walking.
$ cd kenate
02. The Walking Plan (Pseudo-Code)
START: Center all 6 legs so the robot is standing tall.
TRIPOD A: Lift legs 1, 3, and 5 together.
TRIPOD B: While Group A is lifting, legs 2, 4, and 6 push the ground.
COORDINATION: Use a Sine wave to make the transition smooth instead of bouncy.
SYSTEM CHECK: Constantly check the height sensor. If the robot 'sags', adjust power.
DATA: Save every single leg position to the Black Box for later.
03. The Implementation
from kenate import Robot, BaseState
from kenate.stdlib import WaitState, BlackBoxLogger
from kenate.diag import TerminalVisualizer
import math
import time
class HexapodWalking(BaseState):
"""
RATIONALE: I don't use 'if' statements to walk. I use Sine waves.
It makes the robot move like a living creature instead of a stuttering toy.
"""
def on_enter(self):
print("\n[GAIT] Initializing Biomimetic Tripod Sequence...")
self.logger = BlackBoxLogger()
self.viz = TerminalVisualizer(robot_id="HEXA-v1")
# Our internal "Clock" for the walking wave
self.cycle_time = 0.0
self.step_height = 5.0
self.walking_speed = 2.0
def on_update(self):
# 1. TIME: Constant 1ms heartbeat
self.cycle_time += 0.001
# 2. THE WAVE: Tripod pattern (Sine Wave transition)
wave_a = math.sin(self.cycle_time * self.walking_speed * 2 * math.pi)
# 3. LEG LIFT: Calculate lift heights
leg_group_a_height = max(0, wave_a * self.step_height)
leg_group_b_height = max(0, -wave_a * self.step_height)
# 4. SENSORS: Monitor ground and thermals
ground_distance = self.get_height_sensor()
temp = self.get_system_temperature()
# 5. DASHBOARD: Live Telemetry
self.viz.render(self.name, {
'height': ground_distance,
'distance': leg_group_a_height,
'battery': 95,
'temp': temp,
'signal': 100
})
# 6. BLACK BOX: High-frequency recording
self.logger.log(self.name, {
'height': ground_distance,
'distance': leg_group_a_height,
'temp': temp
})
def main():
robot = Robot(port="SIMULATION")
robot.create_state("TripodGait", HexapodWalking)
try:
robot.start()
for _ in range(100):
time.sleep(0.1)
finally:
robot.stop()Breakdown: To The Bone
Sine Wave Rationale
I don't use boolean gates for motion. I use math.sin() because physics exists. Jumping instantly from speed 0 to 100 will strip your cheap plastic servo gears in about three seconds. A Sine wave naturally ramps acceleration up and down. You're welcome.
The Cycle Clock
Because on_update() is fired precisely every 1ms by the C++ Kernel, adding 0.001 to our clock isn't a hope and a prayer—it's exactly one millisecond of real-world time. No jitter, no drift.
04. Moving to the Real Robot
When you're ready to see the legs move for real, copy this file onto your robot (SSH/Git). Change the port from "SIMULATION" to "GPIO" or "/dev/ttyUSB0".