Skip to content

Add simulator support for Spike Prime - #1754

Open
chrschn wants to merge 5 commits into
OpenRoberta:developfrom
chrschn:spike_sim
Open

chrschn wants to merge 5 commits into
OpenRoberta:developfrom
chrschn:spike_sim

Conversation

@chrschn

@chrschn chrschn commented Sep 14, 2026

Copy link
Copy Markdown

This PR adds simulator support for Spike Prime.

- Implement visitor, validator, and generator workers for simulation
  opcode generation.
- Support driving, single motors, 5x5 display, tones, status RGB LED,
  buttons, and sensors (ultrasonic, color, touch/force, gyro, gestures).
- Add frontend RobotSpike, SpikeChassis, and SpikeDisplay with square
  pixels and interactive Hub SVG controls.
- Enable robot.multisim and getsimulationcode workflow in spike and
  spikePybricks properties.
The simulated touch sensor only returns the boolean pressed state, but
not the numeric force value. The new force sensor also returns a force
value so it can be used in simulation. The force value is simplified to
0 when not pressed and 100 when pressed.
@chrschng

Copy link
Copy Markdown

Thanks for the fixes, @AlvaroCalderonToledo! I pulled the commit locally and tested the simulator today while teaching a Roberta class with 23 kids. Everything works as expected, but I discovered one missing feature in my first commit:

The touch sensor did not work in the simulator with a numeric force value, only with the boolean "pressed" state. That's why I introduced a ForceSensor class which simulates the force value (pressed = 100, !pressed = 0). This change also localizes the boolean value in the touch sensor view.

LMK if you have any other comments or concerns.

@AlvaroCalderonToledo

Copy link
Copy Markdown
Contributor

Thanks, @chrschng ! I pushed a small follow-up on top of your force sensor commit.
ForceSensor now exposes both pressed and force directly in the simulated sensor state, and I removed the touch-specific handling from RobotSimBehaviour. SpikeStackMachineVisitor now always includes the sensor mode, so the generic lookup can resolve both values normally.
This keeps the force logic localized in ForceSensor and avoids calculating the 0/100 value twice. I tested both pressed and force locally and everything works as expected.

@chrschn

chrschn commented Oct 7, 2026

Copy link
Copy Markdown
Author

Thanks again, @AlvaroCalderonToledo, the code looks cleaner now. I tested the code with your fix for both the Spike and EV3 simulator, it works as expected. The code is good now from my side.

@AlvaroCalderonToledo

Copy link
Copy Markdown
Contributor

Thanks again @chrschn ! Everything looks good from my side as well.
One last thing I noticed while doing the final review: RobotSpike/pom.xml adds RobotMbed as a test dependency, but RobotSpike currently has no test sources and Maven reports that dependency as unused. Was this dependency added intentionally for something I’m missing, or can we remove it?

@chrschn

chrschn commented Oct 7, 2026

Copy link
Copy Markdown
Author

Good catch, @AlvaroCalderonToledo! This dependency was added for an attempt to add a unit test, but it didn't add much value, so I dropped it again. Now I also removed the dependency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants