Skip to content
This repository was archived by the owner on Nov 7, 2026. It is now read-only.

Commit ce4d7e7

Browse files
Web 0.6.0: VisuBot „mBot2 live“ beim Bearbeiten und mBot2-Elemente in Gruppen (#159)
Neues Fenster zeigt nach jeder Änderung, wohin das Programm den mBot2 fährt (im Hintergrund durchgerechnet, ▶ spielt die Fahrt ab). Als eigene Spalte oder unter dem Code in Programmieren, Größe ziehbar, einklappbar. mBot2-Befehle und -Sensoren unter Elemente sind wie im Nachschlagen gruppiert. Claude-Session: https://claude.ai/code/session_01K8C1HvVqFVDDiMJ5WasFzi Co-authored-by: Claude <noreply@anthropic.com>
1 parent 709fca0 commit ce4d7e7

20 files changed

Lines changed: 2254 additions & 1461 deletions

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The format is loosely inspired by Keep a Changelog.
88

99
### Added
1010

11+
- **Web 0.6.0, VisuBot “mBot2 live”:** a new window next to the structogram and the code shows right away where the program drives the mBot2: after every change the program is run in the background in the world of the exercise, the robot stands where it ends up and leaves its track; ▶ plays the drive with tones, LEDs and screen. The window can be its own column (width adjustable) or sit below the code in Programming (height adjustable), and it collapses into a narrow bar. Programs that need an input or run endlessly get a note.
12+
- **Web 0.6.0, VisuBot elements in groups:** the mBot2 commands and sensors under Elements are grouped like the reference (driving and turning, wheels separately, light/sound/screen, emotions, waiting and stopwatch; distance, line, colours, buttons and joystick, light and loudness, tilt and shaking, stopwatch and battery); each group folds up.
1113
- **Web 0.5.0, VisuBot basics with the robot:** five new VisuBot lessons teach the Java basics with the mBot2 as the example: 3 “Variables and output”, 9 “Case selection with colours”, 17 “Arrays and melodies”, 19 “Strings” and 22 “Your own methods” (de/en). Each has a structogram exercise, a Java exercise and ends with “Now without the robot”: plain Java with console output and no `mbot`, because real Java is the goal. The other VisuBot lessons move to 4–8, 10–16, 18, 20 and 21; learning progress is carried over.
1214
- **Web 0.5.0, VisuStruct or VisuBot:** two separate worlds instead of the VisuBot modes Off / In the course / Separate series. VisuStruct shows the course without any robot; VisuBot shows only the robot lessons, robot tasks and the mBot2 reference. You choose at the top of the start dialog or the gear menu. The address shows `?visubot` or `?visustruct`, so a link opens the right world. The 🤖 course steps of “In the course” were removed (a saved “In the course” now opens VisuBot). The website's lesson links open VisuStruct.
1315
- **Web 0.4.7, Programming:** a book button in the Programming header opens the reference (commands and terms) in the learning area, also when only Programming is open.

‎web/package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎web/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "visustruct-web",
33
"private": true,
4-
"version": "0.5.0",
4+
"version": "0.6.0",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

‎web/src/core/robotPreview.ts‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import type { VSDocument } from './model'
2+
import type { MBotSensorValues } from './mbot'
3+
import { ROBOT_STEP_MS, RobotWorld, type Point, type Pose, type RobotWorldSetup } from './robotWorld'
4+
import { SimulationEngine, type SimNotice, type SubprogramResolver } from './simulation'
5+
6+
/** Ein Bild der Fahrt: wo der mBot2 steht, seine Spur, LEDs und Bildschirm, dazu ein Ton in diesem Schritt. */
7+
export interface PreviewFrame {
8+
pose: Pose
9+
trail: Point[]
10+
leds: RobotWorld['leds']
11+
screen: string | undefined
12+
tone?: [number, number]
13+
}
14+
15+
export interface PreviewResult {
16+
frames: PreviewFrame[]
17+
/** Warum die Vorschau aufhört: Ende, Eingabe nötig, Fehler oder zu viele Schritte (Endlosschleife?). */
18+
stop: 'end' | 'input' | 'error' | 'limit'
19+
notice?: SimNotice
20+
bumps: number
21+
/** Strecke der Spur in cm. */
22+
distance: number
23+
}
24+
25+
export const maxPreviewSteps = 5000
26+
27+
/**
28+
* mBot2-Vorschau beim Bearbeiten: das Programm im Hintergrund ganz durchrechnen, wie in der Simulation
29+
* (die Welt liefert die Sensorwerte), und jedes Bild der Fahrt merken.
30+
*/
31+
export function previewRun(doc: VSDocument, subprograms: SubprogramResolver | undefined, setup: RobotWorldSetup, controls: MBotSensorValues = {}): PreviewResult {
32+
const engine = new SimulationEngine(doc, subprograms)
33+
const robot = new RobotWorld(setup)
34+
const frame = (tone?: [number, number]): PreviewFrame => ({
35+
pose: { ...robot.pose },
36+
trail: robot.trail.map((p) => ({ ...p })),
37+
leds: [...robot.leds],
38+
screen: robot.screen,
39+
tone,
40+
})
41+
const frames: PreviewFrame[] = [frame()]
42+
let applied = 0
43+
const result = (stop: PreviewResult['stop'], notice?: SimNotice): PreviewResult => ({
44+
frames,
45+
stop,
46+
notice,
47+
bumps: robot.bumps,
48+
distance: Math.round(robot.trail.slice(1).reduce((sum, p, i) => sum + Math.hypot(p.x - robot.trail[i].x, p.y - robot.trail[i].y), 0)),
49+
})
50+
for (let i = 0; i < maxPreviewSteps; i++) {
51+
const { state } = engine
52+
if (state.inputRequest) return result('input')
53+
if (state.isHalted) return result('error', state.notice)
54+
if (!engine.canStep) return result('end')
55+
engine.robotSensors = { ...controls, ...robot.sensors() }
56+
engine.step()
57+
// jeder neue Befehl ist ein Bild; mit `mbot.drive` fährt er auch ohne Befehl weiter
58+
for (; applied < state.robotActions.length; applied++) {
59+
const action = state.robotActions[applied]
60+
robot.apply(action)
61+
frames.push(frame(action.method === 'playTone' ? [action.args[0], action.args[1]] : undefined))
62+
}
63+
const moving = robot.wheels.some((p) => p !== 0)
64+
robot.tick(ROBOT_STEP_MS)
65+
if (moving) frames.push(frame())
66+
}
67+
return result('limit')
68+
}

‎web/src/i18n/de.strings‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,27 @@
356356
"web_learn_start_folder" = "VisuStruct-Dateien";
357357
"web_learn_start_without" = "Ohne Ordner weiter";
358358
"web_learn_start_without_hint" = "Dann ist dein Lernstand nach dem Schließen weg.";
359+
"web_visubot_preview_title" = "mBot2 live";
360+
"web_visubot_preview_hint" = "Zeigt sofort, wohin dein Programm den mBot2 fährt.";
361+
"web_visubot_preview_play" = "Fahrt abspielen";
362+
"web_visubot_preview_stop" = "Anhalten";
363+
"web_visubot_preview_hide" = "mBot2 live einklappen";
364+
"web_visubot_preview_show" = "mBot2 live zeigen";
365+
"web_visubot_preview_resize" = "Größe von mBot2 live ändern";
366+
"web_visubot_preview_stack" = "Unter den Code in Programmieren";
367+
"web_visubot_preview_side" = "Als eigene Spalte";
368+
"web_visubot_preview_distance_fmt" = "Strecke: %d cm";
369+
"web_visubot_preview_input" = "braucht eine Eingabe, dafür die Simulation starten";
370+
"web_visubot_preview_limit" = "läuft sehr lange (Endlosschleife?), gezeigt ist der Anfang";
371+
"web_visubot_group_drive" = "Fahren und Drehen";
372+
"web_visubot_group_wheels" = "Räder einzeln";
373+
"web_visubot_group_output" = "Licht, Ton und Bildschirm";
374+
"web_visubot_group_emotion" = "Gefühle";
375+
"web_visubot_group_wait" = "Warten und Stoppuhr";
376+
"web_visubot_group_distance" = "Abstand";
377+
"web_visubot_group_line" = "Linie";
378+
"web_visubot_group_color" = "Farben";
379+
"web_visubot_group_buttons" = "Tasten und Joystick";
380+
"web_visubot_group_light" = "Licht und Lautstärke";
381+
"web_visubot_group_tilt" = "Neigung und Schütteln";
382+
"web_visubot_group_timer" = "Stoppuhr und Akku";

‎web/src/i18n/en.strings‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,27 @@
356356
"web_learn_start_folder" = "VisuStruct-Files";
357357
"web_learn_start_without" = "Continue without a folder";
358358
"web_learn_start_without_hint" = "Your learning progress is then lost when you close the page.";
359+
"web_visubot_preview_title" = "mBot2 live";
360+
"web_visubot_preview_hint" = "Shows right away where your program drives the mBot2.";
361+
"web_visubot_preview_play" = "Play the drive";
362+
"web_visubot_preview_stop" = "Stop";
363+
"web_visubot_preview_hide" = "Collapse mBot2 live";
364+
"web_visubot_preview_show" = "Show mBot2 live";
365+
"web_visubot_preview_resize" = "Resize mBot2 live";
366+
"web_visubot_preview_stack" = "Below the code in Programming";
367+
"web_visubot_preview_side" = "As a column of its own";
368+
"web_visubot_preview_distance_fmt" = "Distance: %d cm";
369+
"web_visubot_preview_input" = "needs an input, start the simulation for that";
370+
"web_visubot_preview_limit" = "runs for a very long time (endless loop?), showing the start";
371+
"web_visubot_group_drive" = "Driving and turning";
372+
"web_visubot_group_wheels" = "Wheels separately";
373+
"web_visubot_group_output" = "Light, sound and screen";
374+
"web_visubot_group_emotion" = "Emotions";
375+
"web_visubot_group_wait" = "Waiting and stopwatch";
376+
"web_visubot_group_distance" = "Distance";
377+
"web_visubot_group_line" = "Line";
378+
"web_visubot_group_color" = "Colours";
379+
"web_visubot_group_buttons" = "Buttons and joystick";
380+
"web_visubot_group_light" = "Light and loudness";
381+
"web_visubot_group_tilt" = "Tilt and shaking";
382+
"web_visubot_group_timer" = "Stopwatch and battery";

‎web/src/i18n/pt-PT.strings‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,27 @@
354354
"web_learn_start_folder" = "VisuStruct-Ficheiros";
355355
"web_learn_start_without" = "Continuar sem pasta";
356356
"web_learn_start_without_hint" = "Assim o teu progresso perde-se ao fechar a página.";
357+
"web_visubot_preview_title" = "mBot2 ao vivo";
358+
"web_visubot_preview_hint" = "Mostra logo para onde o teu programa leva o mBot2.";
359+
"web_visubot_preview_play" = "Reproduzir o percurso";
360+
"web_visubot_preview_stop" = "Parar";
361+
"web_visubot_preview_hide" = "Recolher mBot2 ao vivo";
362+
"web_visubot_preview_show" = "Mostrar mBot2 ao vivo";
363+
"web_visubot_preview_resize" = "Alterar o tamanho de mBot2 ao vivo";
364+
"web_visubot_preview_stack" = "Por baixo do código em Programação";
365+
"web_visubot_preview_side" = "Como coluna própria";
366+
"web_visubot_preview_distance_fmt" = "Percurso: %d cm";
367+
"web_visubot_preview_input" = "precisa de uma entrada, inicia a simulação para isso";
368+
"web_visubot_preview_limit" = "demora muito (ciclo infinito?), mostra-se o início";
369+
"web_visubot_group_drive" = "Andar e rodar";
370+
"web_visubot_group_wheels" = "Rodas separadas";
371+
"web_visubot_group_output" = "Luz, som e ecrã";
372+
"web_visubot_group_emotion" = "Emoções";
373+
"web_visubot_group_wait" = "Esperar e cronómetro";
374+
"web_visubot_group_distance" = "Distância";
375+
"web_visubot_group_line" = "Linha";
376+
"web_visubot_group_color" = "Cores";
377+
"web_visubot_group_buttons" = "Botões e joystick";
378+
"web_visubot_group_light" = "Luz e volume";
379+
"web_visubot_group_tilt" = "Inclinação e abanar";
380+
"web_visubot_group_timer" = "Cronómetro e bateria";

0 commit comments

Comments
 (0)