Decorative header image for LEGO SPIKE move_tank_for_time Motion Sequencer

LEGO SPIKE move_tank_for_time Motion Sequencer

Design timed tank-drive routines step-by-step with animated previews and loop-ready Python code for LEGO SPIKE Prime performances.

By Gray-wolf Tools Team Content Team
Updated 11/3/2025 ~800 words
robotics LEGO SPIKE Prime move_tank_for_time motion sequencer robot routine education

LEGO SPIKE move_tank_for_time Motion Sequencer

Executive Summary

The LEGO SPIKE move_tank_for_time Motion Sequencer is a specialized timeline-based planning tool for creating choreographed robot routines, performances, and timed motion sequences. Unlike position-based control that specifies wheel rotation amounts, time-based control focuses on duration—running motors at specified velocities for exact periods measured in seconds. This makes it ideal for synchronized demonstrations, music-driven performances, and educational projects where timing predictability matters more than positional accuracy.

The Motion Sequencer provides an intuitive visual timeline interface where you build sequences step-by-step, setting duration, left/right motor speeds, and stop behaviors for each segment. Real-time path animation shows your robot’s predicted trajectory, helping you refine movements for aesthetic appeal and smooth transitions. When your routine is complete, export async Python code optimized for LEGO SPIKE Prime’s event-driven programming model, complete with helpful annotations for students.

Key Benefits:

  • Timeline-Based Design: Visual timeline editor with draggable step durations
  • Synchronized Timing: Perfect for music, light shows, or multi-robot coordination
  • Animated Preview: See the full motion path before deploying to hardware
  • Async Code Export: Generate modern Python async routines with proper await syntax
  • Educational Focus: Built-in templates and comments scaffolding student learning

Feature Tour

Visual Timeline Editor

The heart of the Motion Sequencer is its horizontal timeline interface, similar to video editing software. Each motion step appears as a colored block on the timeline, with width proportional to duration. Click to select steps, drag edges to adjust timing, and reorder by dragging blocks left or right. Time markers at the top show cumulative elapsed time, helping you align movements to specific beats, cues, or event triggers.

This visual representation makes abstract timing concrete. Students can see at a glance that their 10-second routine consists of five 2-second segments, or that a dramatic pause is 3 seconds while quick maneuvers are only 0.5 seconds. The timeline transforms temporal thinking into spatial layout, leveraging visual-spatial reasoning skills.

Step Configuration Panel

For each timeline step, configure three critical parameters:

Duration (seconds): How long the motors run. Supports decimal precision (e.g., 1.5s, 0.75s) for fine-grained control. The interface provides presets for common durations (0.5s, 1s, 2s, 5s) and a custom input field for exact values.

Left/Right Motor Speeds: Velocity values from -100 (full speed backward) to 100 (full speed forward). Independent control enables straight motion (equal speeds), turns (differential speeds), and spins (opposite-sign speeds). Visual sliders provide immediate feedback, with numeric readouts for precision.

Stop Action: Choose between “coast” (motors power off, momentum carries robot), “brake” (active resistance, quick stop), or “hold” (maintains position with force). This parameter critically affects motion quality—brake mode produces crisp, predictable stops for precise choreography.

The configuration panel updates the timeline immediately, with color-coding to indicate speed patterns (green for forward, red for backward, yellow for mixed/turning).

Animated Path Visualizer

As you build your sequence, the integrated path visualizer animates your robot’s predicted trajectory. Click the “Play Preview” button to watch a top-down view of your robot executing the full routine, with timing matched to your sequence. The animation shows:

  • Robot position at each moment in time
  • Heading changes during turns
  • Path traces showing the full trajectory
  • Time markers synchronized with the timeline

This animation is invaluable for spotting problems before hardware testing. You’ll immediately see if a turn is too sharp, a straight section is too long, or transitions between steps create jarring direction changes. Adjust step parameters and replay until the animation matches your vision.

Async Python Code Generator

Modern LEGO SPIKE programming uses asynchronous (async) patterns for responsive, event-driven code. The Motion Sequencer generates production-ready async functions that can be easily integrated into larger programs:

async def perform_routine():
    # Step 1: Move forward (2.0 seconds)
    await motor_pair.move_tank_for_time(2.0, 80, 80)
    
    # Step 2: Spin right (1.5 seconds)
    await motor_pair.move_tank_for_time(1.5, 60, -60)
    
    # ... additional steps

The await keyword ensures each step completes before the next begins, maintaining precise timing. Generated code includes:

  • Proper async function definition
  • Import statements for required modules
  • Motor pair initialization with your configured ports
  • Stop action commands between steps
  • Inline comments explaining each movement

For classroom use, this scaffolding helps students understand async programming concepts in a concrete, testable context.

Loop and Repeat Controls

Many robot routines require repetition—dancing in circles, patrolling a perimeter, or repeating a sequence multiple times. The Motion Sequencer includes loop controls that let you:

  • Mark a selection of steps as a “loop group”
  • Set repeat count (2x, 3x, infinite)
  • Generate code with proper for loops or while True structures
  • Preview the looped animation to verify behavior

For infinite loops (common in patrol or monitoring scenarios), the exported code includes safety comments reminding students to add exit conditions (sensor triggers, user button press) to prevent runaway robots.

Preset Motion Templates

Accelerate common tasks with built-in templates:

Figure-Eight: Alternating curved paths creating an infinity symbol pattern Square Patrol: Four forward segments with 90-degree turns at corners Spin and Stop: Dramatic spins with pauses for audience effect Smooth Arc: Gradual curved motion for elegant demonstrations Stutter Step: Rapid alternating forward/backward for “dancing” effect

Select a template, adjust durations and speeds to match your robot and performance context, then use as-is or modify further. Templates serve as learning examples, showing students proven motion patterns they can adapt.

Usage Scenarios

Scenario 1: Music Synchronized Robot Dance

A high school robotics club is preparing a demonstration for a school assembly where their robot “dances” to a 30-second music clip. Using the Motion Sequencer:

  1. They load the music file and mark beat boundaries at 2-second intervals
  2. Create a timeline with 15 steps, each 2 seconds long to match beats
  3. Design movements that match the music’s energy: quick spins during fast sections, smooth arcs during melodic parts, dramatic pauses at crescendos
  4. Use the animated preview to verify visual appeal from audience perspective
  5. Export the async code and add light/sound effects using SPIKE’s LED and speaker commands
  6. Test on the physical robot, making minor timing adjustments to perfect synchronization

The final performance earns applause, with students explaining how time-based control enabled precise musical coordination that position-based methods couldn’t achieve.

Scenario 2: Multi-Robot Choreography

For a district robotics showcase, a team wants three robots to perform coordinated movements—moving in formation, separating, and reuniting. Each robot needs identical timing to maintain synchronization:

  1. Use the Motion Sequencer to design the master routine on one computer
  2. Export the code and deploy to all three robots simultaneously
  3. Test in formation, noting any drift due to battery differences or motor variations
  4. Adjust individual robot speeds (e.g., 78 instead of 80) to compensate for hardware differences
  5. Add wireless communication commands so robots can signal each other at key transition points
  6. Rehearse the full routine, refining timing until all three robots move as one unit

The showcase performance demonstrates advanced coordination, with judges praising the team’s understanding of distributed systems and timing synchronization.

Scenario 3: Timed Obstacle Course

In a middle school STEM challenge, robots must complete an obstacle course where gates open and close at fixed intervals. Success requires precise timing, not just position:

  1. Students observe gate timing patterns: Gate 1 opens for 3 seconds every 10 seconds, Gate 2 opens for 2 seconds every 8 seconds
  2. Use the Motion Sequencer to plan movements: rush forward during Gate 1’s open window, wait 7 seconds, then sprint through Gate 2
  3. The timeline editor visualizes the wait periods, helping students understand the time budget
  4. Add “coast” stop actions during waits to conserve battery
  5. Export code and test, measuring actual gate passage times
  6. Iterate on motor speeds to optimize transit times while maintaining timing alignment

Teams using the Motion Sequencer complete the course with 85% success rate compared to 40% for teams coding manually, demonstrating the value of visual planning tools.

Scenario 4: Robot Theater Performance

An elementary school class is creating a robot-acted play where robots represent characters moving on a stage. Each scene has specific timing and blocking:

  1. Students script the play with scene durations noted (Scene 1: 15 seconds, Scene 2: 20 seconds)
  2. For each robot character, they create a motion sequence matching their scene role
  3. Use the animated preview to check that robots don’t collide and hit their marks on time
  4. Export code for each robot with scene comments (e.g., ”# Scene 2: Robot B enters stage left”)
  5. Rehearse with the class, adding dialog and sound effects synced to robot movements
  6. Perform for parents, demonstrating cross-curricular integration of storytelling and engineering

The project shows students that robotics can be creative and expressive, not just technical, broadening appeal and engagement across diverse learner interests.

Code Examples

Example 1: Simple Forward-Turn-Forward Routine

from spike import MotorPair
import runloop

async def main():
    motor_pair = MotorPair('A', 'B')
    
    # Step 1: Move forward for 2 seconds at moderate speed
    await motor_pair.move_tank_for_time(2.0, 70, 70)
    
    # Step 2: Turn right for 1 second (right wheel backward)
    await motor_pair.move_tank_for_time(1.0, 60, -60)
    
    # Step 3: Move forward again for 3 seconds
    await motor_pair.move_tank_for_time(3.0, 70, 70)
    
    # Stop with brake for clean finish
    motor_pair.stop()

runloop.run(main())

Use Case: Basic navigation routine demonstrating sequential async movements with timing control.

Example 2: Looped Patrol Pattern

from spike import MotorPair
import runloop

async def patrol_routine():
    motor_pair = MotorPair('A', 'B')
    
    # Patrol square perimeter 3 times
    for i in range(3):
        # Move forward one side (2 seconds)
        await motor_pair.move_tank_for_time(2.0, 80, 80)
        
        # Turn 90 degrees right (0.8 seconds - calibrated for this robot)
        await motor_pair.move_tank_for_time(0.8, 60, -60)
    
    motor_pair.stop()

runloop.run(patrol_routine())

Use Case: Repeated patrol pattern for security or monitoring demonstrations, showing loop integration.

Example 3: Figure-Eight Choreography

from spike import MotorPair
import runloop

async def figure_eight():
    motor_pair = MotorPair('A', 'B')
    
    # First loop: curve right
    await motor_pair.move_tank_for_time(3.0, 80, 50)  # Right slower → curve right
    
    # Transition turn
    await motor_pair.move_tank_for_time(1.0, 50, -50)  # Point turn
    
    # Second loop: curve left
    await motor_pair.move_tank_for_time(3.0, 50, 80)  # Left slower → curve left
    
    # Return transition
    await motor_pair.move_tank_for_time(1.0, -50, 50)  # Reverse point turn
    
    motor_pair.stop()

runloop.run(figure_eight())

Use Case: Aesthetic demonstration routine showing smooth curved paths and symmetrical motion.

Example 4: Music-Synced Dance with Pauses

from spike import MotorPair
import runloop

async def dance_routine():
    motor_pair = MotorPair('A', 'B')
    motor_pair.set_stop_action('brake')  # Clean stops between moves
    
    # Beat 1-2: Quick spin (2 seconds)
    await motor_pair.move_tank_for_time(2.0, 80, -80)
    
    # Beat 3: Pause (1 second) - motors off
    await runloop.sleep_ms(1000)
    
    # Beat 4-5: Forward rush (2 seconds)
    await motor_pair.move_tank_for_time(2.0, 100, 100)
    
    # Beat 6: Dramatic pause (1 second)
    await runloop.sleep_ms(1000)
    
    # Beat 7-8: Backward with curve (2 seconds)
    await motor_pair.move_tank_for_time(2.0, -70, -50)
    
    motor_pair.stop()

runloop.run(dance_routine())

Use Case: Performance choreography with precise timing and pauses synchronized to music beats.

Troubleshooting

Issue: Robot movements are inconsistent across multiple runs of the same sequence.

Solutions:

  • Ensure battery is fully charged; voltage affects motor speed and timing relationships
  • Use “brake” stop action instead of “coast” for more predictable transitions between steps
  • Test on consistent surfaces; carpet vs. tile dramatically affects friction and momentum
  • Add motor encoder resets at the start of your routine with motor_pair.set_motor_rotation(0, 'both')
  • Reduce maximum speeds to 70-80 instead of 100 for more reliable behavior

Issue: Animated preview doesn’t match actual robot behavior.

Solutions:

  • The preview uses idealized physics without modeling tire slip, surface friction, or motor response curves
  • Treat the preview as a design guide, not a simulation; always validate on hardware
  • For curved paths, preview assumes constant radius arcs which may not match actual robot dynamics
  • Adjust wheel spacing and diameter settings in the tool’s configuration panel to improve preview accuracy

Issue: Generated code produces “NameError” or “ImportError” when run on SPIKE hub.

Solutions:

  • Verify you’re using SPIKE Prime firmware 2.0 or later which supports async/await syntax
  • Check that motor ports in generated code match your physical connections (e.g., ‘A’, ‘B’)
  • Ensure runloop module is available (introduced in SPIKE Prime Python API v2)
  • If using older firmware, manually convert async code to synchronous by removing async/await keywords

Issue: Looped sequences create cumulative timing drift after several iterations.

Solutions:

  • Time-based commands are susceptible to small execution delays that compound in loops
  • Add await runloop.sleep_ms(50) between loop iterations to give motors time to fully stop
  • Use brake stop action to prevent momentum from affecting next iteration’s starting conditions
  • For critical timing, replace infinite loops with fixed iteration counts and add calibration pauses

Issue: Multiple robots synchronized at start drift out of sync during routine.

Solutions:

  • Calibrate individual robot speeds to match; even identical hardware varies slightly
  • Use wireless communication to resynchronize at key waypoints (e.g., all robots wait for “start step 5” signal)
  • Reduce routine length; sync drift compounds over time
  • Test all robots on the same surface with the same battery charge levels
  • Consider using sensor triggers (e.g., color sensor detecting floor marks) as sync points

Frequently Asked Questions

1. What’s the difference between move_tank_for_time and move_tank_for_degrees?

move_tank_for_time runs motors for a specified duration (seconds) at given speeds, while move_tank_for_degrees rotates wheels a specified number of degrees. Time-based control is predictable in timing but not in distance traveled (varies with surface, battery, etc.). Degree-based control is predictable in position but not in duration. Use time-based for performances and choreography; use degree-based for precise navigation.

2. How do I synchronize robot movements to music?

Load your music file into audio editing software and mark beat boundaries with timestamps. In the Motion Sequencer, create steps with durations matching the intervals between beats. Use the preview animation while playing music in the background to verify visual synchronization. Export code and test on the robot, fine-tuning durations by ±0.1 seconds to perfect alignment.

3. Can I combine time-based and position-based commands in one routine?

Yes! The Motion Sequencer generates standard SPIKE Prime API calls that can be mixed with other commands. After exporting, manually add move_tank_for_degrees or sensor reading calls between the generated move_tank_for_time steps. Just maintain the async/await pattern for proper sequencing.

4. Why does my robot drift to one side during “straight” movements with equal motor speeds?

Motor manufacturing tolerances, wheel wear, and mechanical friction cause slight differences between left and right drive trains. Compensate by adjusting one motor’s speed (e.g., 78 instead of 80) until the robot tracks straight. The Motion Sequencer lets you set independent speeds for precisely this reason. Test on a long straight run (5+ seconds) to identify the drift direction and amount.

5. How do I create smooth transitions between steps instead of jerky stops and starts?

Use the “coast” stop action for gentler transitions, or reduce speed differences between consecutive steps. For example, instead of jumping from 100 speed to -100, insert intermediate steps at 50, 0, -50, then -100. Gradual speed changes feel smoother. Alternatively, adjust motor acceleration curves in SPIKE hub settings (advanced feature requiring firmware configuration).

6. Can I import an existing Python routine into the Motion Sequencer?

The current version supports design-to-export workflow only. However, you can manually recreate sequences by extracting duration and speed values from existing code and entering them as new steps in the timeline. This is useful for visualizing and optimizing legacy routines. A future update may include code parsing and import capabilities.

7. What’s the maximum routine length the Motion Sequencer supports?

The tool itself supports up to 100 timeline steps and total durations exceeding 10 minutes. However, practical limits exist: SPIKE Prime hub memory constrains code size, and long routines increase the likelihood of cumulative timing errors. For performances exceeding 2-3 minutes, consider breaking into segments and triggering each via button press or sensor events.

References and Further Learning


Accessibility Note: The Motion Sequencer supports keyboard navigation for all timeline operations (Tab to navigate, Space to play/pause preview, Arrow keys to adjust durations), screen reader announcements for step properties, and high-contrast visual themes. Audio feedback options provide non-visual confirmation of step additions and playback events for users with visual impairments.

Get Started: Visit the LEGO SPIKE move_tank_for_time Motion Sequencer and begin choreographing your next robot performance with precision timing and creative flair.