Names from 2.x to 3.0
Firmware 3.0 gave the Python names a clean-up. Some names changed, a few were removed and a few are new. A robot on 3.0 does not know the 2.x names, and a robot on 2.x does not know the 3.0 names. This page lists every change, kit by kit.
Find the old name in the list for your kit. What comes after the arrow is what to write now. The pages of the reference describe the new names.
Jump to a kit: Smart Car, Mini, Smart Home.
How to use this page
Section titled “How to use this page”These rules come with the map. They are for anyone changing old code, by hand or with a program.
- Apply the
rootentry first: everymobotROBOTICS./mobotMINI.becomesrobot., everymobotIOT.becomeshome.. - Then the longer
oldpaths before the shorter ones (an entry forrobot.ble.xbefore the attribute entryrobot.ble->robot.bluetooth). oldandneware written from the root object;[name],(n),(pattern)mark where an argument goes.newwith' | 'lists the two names a call can become; itsrulesays which one.- Entries with a
rulechange their arguments;examplesare [old, new] pairs. - Nothing in
removedhas an alias on 3.0.0;insteadis what a program writes now. internalis for the simulator and the firmware’s own tests: a program does not use those names.
Smart Car
Section titled “Smart Car”On firmware 2.x, a program for the Smart Car used mobotROBOTICS. On 3.0 it is robot.
Smart Car: names that changed
Section titled “Smart Car: names that changed”mobotROBOTICS→robot: an instance of class SmartCar (smart_car.py), bound in__main__by_boot.py. EverymobotROBOTICS.prefix becomesrobot.; the entries below are the members whose own name changes toomobotROBOTICS.ble→robot.bluetooth: the BLEController; every otherble.*member not listed here keeps its name under bluetoothmobotROBOTICS.init()→robot._init(): internal since 3.0.0: the mode runner and the simulator call it, a program does notmobotROBOTICS.cleanup()→robot._cleanup(): internal since 3.0.0: the mode runner and the simulator call itmobotROBOTICS.left_motor.setSpeed→robot.left_motor.set_speed: 0-100, keeps the directionmobotROBOTICS.right_motor.setSpeed→robot.right_motor.set_speed: 0-100, keeps the directionmobotROBOTICS.led1.setState→robot.led1.set:True/Falseor 1/0, as beforemobotROBOTICS.led1.setLedBrightness→robot.led1.set_brightness: the argument was already a percent, 0-100mobotROBOTICS.led2.setState→robot.led2.set:True/Falseor 1/0, as beforemobotROBOTICS.led2.setLedBrightness→robot.led2.set_brightness: the argument was already a percent, 0-100mobotROBOTICS.buzzer.get_current_song()→robot.buzzer.current_songmobotROBOTICS.ble.x→robot.gamepad.x: -128 (left) to 127 (right)mobotROBOTICS.ble.y→robot.gamepad.y: -128 (down) to 127 (up)mobotROBOTICS.ble.changeName→robot.set_namemobotROBOTICS.ble.mobot_name→robot.namemobotROBOTICS.ble.control_mode→robot.mode: 255 = Programmablefrom BLE import map_range→from mobot import map_rangemobotROBOTICS.irs→robot.line_sensormobotROBOTICS.irs.readAllIRs()→robot.line_sensor.read(): one value per eye, left to right, as beforemobotROBOTICS.irs.readSingleIR(n)→robot.line_sensor.read(n)mobotROBOTICS.irs.compIRs(pattern)→robot.line_sensor.matches(pattern)mobotROBOTICS.ultrasonic→robot.distance_sensormobotROBOTICS.ultrasonic.get_distance_cm()→robot.distance_sensor.distance_cm()mobotROBOTICS.ultrasonic.get_distance_mm()→robot.distance_sensor.distance_mm()mobotROBOTICS.color_sensor.readColor()→robot.color_sensor.read(): (r, g, b, clear) raw counts, as beforemobotROBOTICS.color_sensor.printColors()→robot.color_sensor.print_reading()mobotROBOTICS.compass.read()→robot.compass.heading(): degrees, 0 up to 360mobotROBOTICS.compass.angle_error→robot.compass.heading_errormobotROBOTICS.battery_sensor→robot.batterymobotROBOTICS.battery_sensor.read_battery_voltage()→robot.battery.voltage(): voltsmobotROBOTICS.joystick1.readX()→robot.joystick1.x(): raw ADC, 0-1023mobotROBOTICS.joystick1.readY()→robot.joystick1.y(): raw ADC, 0-1023mobotROBOTICS.joystick2.readX()→robot.joystick2.x(): raw ADC, 0-1023mobotROBOTICS.joystick2.readY()→robot.joystick2.y(): raw ADC, 0-1023mobotROBOTICS.servo1.move→robot.servo1.set_angle: degrees, 0-180mobotROBOTICS.servo2.move→robot.servo2.set_angle: degrees, 0-180mobotROBOTICS.servo3.move→robot.servo3.set_angle: degrees, 0-180mobotROBOTICS.servo4.move→robot.servo4.set_angle: degrees, 0-180mobotROBOTICS.servos[i].move→robot.servos[i].set_anglemobotROBOTICS.init_servo()→robot.enable_servos()mobotROBOTICS.init_joysticks()→robot.enable_joysticks()
Smart Car: names that change how you call them
Section titled “Smart Car: names that change how you call them”For these, the arguments change too. Each one comes with its rule, and an example when the map has one.
mobotROBOTICS.left_motor.setDirectionAndSpeed
Section titled “mobotROBOTICS.left_motor.setDirectionAndSpeed”Write robot.left_motor.forward or robot.left_motor.backward.
setDirectionAndSpeed(d, s) -> robot.left_motor.forward(s) when d == 1 (forward on the Smart Car), else robot.left_motor.backward(s). A d that is not a literal: robot.left_motor.drive(s if d == 1 else -s)
mobotROBOTICS.left_motor.setDirectionAndSpeed(1, 60) # 2.xrobot.left_motor.forward(60) # 3.0
mobotROBOTICS.left_motor.setDirectionAndSpeed(0, 60) # 2.xrobot.left_motor.backward(60) # 3.0mobotROBOTICS.left_motor.set_direction_and_speed
Section titled “mobotROBOTICS.left_motor.set_direction_and_speed”Write robot.left_motor.forward or robot.left_motor.backward.
the snake_case twin of setDirectionAndSpeed on the 2.x Smart Car shim: the same rule, forward when d == 1
mobotROBOTICS.left_motor.setDirection
Section titled “mobotROBOTICS.left_motor.setDirection”Write robot.left_motor.forward or robot.left_motor.backward.
setDirection(d) followed by a speed write -> forward(s) / backward(s) with d == 1 meaning forward; setDirection(d) alone (keep the speed, change the way) -> robot.left_motor.forward(abs(robot.left_motor.speed)) when d == 1, else robot.left_motor.backward(abs(robot.left_motor.speed))
mobotROBOTICS.left_motor.set_direction
Section titled “mobotROBOTICS.left_motor.set_direction”Write robot.left_motor.forward or robot.left_motor.backward.
the snake_case twin of setDirection: the same rule, forward when d == 1
mobotROBOTICS.left_motor.get_speed()
Section titled “mobotROBOTICS.left_motor.get_speed()”Write robot.left_motor.speed.
get_speed() was 0-100 whatever the direction; .speed is signed, -100 to 100 (negative = backward): abs(robot.left_motor.speed) is the old value
mobotROBOTICS.left_motor.get_direction()
Section titled “mobotROBOTICS.left_motor.get_direction()”Write robot.left_motor.speed.
get_direction() == 1 (forward on the Smart Car) -> robot.left_motor.speed > 0; == 0 -> robot.left_motor.speed < 0. At speed 0 the direction is no longer readable
mobotROBOTICS.right_motor.setDirectionAndSpeed
Section titled “mobotROBOTICS.right_motor.setDirectionAndSpeed”Write robot.right_motor.forward or robot.right_motor.backward.
setDirectionAndSpeed(d, s) -> robot.right_motor.forward(s) when d == 1 (forward on the Smart Car), else robot.right_motor.backward(s). A d that is not a literal: robot.right_motor.drive(s if d == 1 else -s)
mobotROBOTICS.right_motor.setDirectionAndSpeed(1, 60) # 2.xrobot.right_motor.forward(60) # 3.0
mobotROBOTICS.right_motor.setDirectionAndSpeed(0, 60) # 2.xrobot.right_motor.backward(60) # 3.0mobotROBOTICS.right_motor.set_direction_and_speed
Section titled “mobotROBOTICS.right_motor.set_direction_and_speed”Write robot.right_motor.forward or robot.right_motor.backward.
the snake_case twin of setDirectionAndSpeed on the 2.x Smart Car shim: the same rule, forward when d == 1
mobotROBOTICS.right_motor.setDirection
Section titled “mobotROBOTICS.right_motor.setDirection”Write robot.right_motor.forward or robot.right_motor.backward.
setDirection(d) followed by a speed write -> forward(s) / backward(s) with d == 1 meaning forward; setDirection(d) alone (keep the speed, change the way) -> robot.right_motor.forward(abs(robot.right_motor.speed)) when d == 1, else robot.right_motor.backward(abs(robot.right_motor.speed))
mobotROBOTICS.right_motor.set_direction
Section titled “mobotROBOTICS.right_motor.set_direction”Write robot.right_motor.forward or robot.right_motor.backward.
the snake_case twin of setDirection: the same rule, forward when d == 1
mobotROBOTICS.right_motor.get_speed()
Section titled “mobotROBOTICS.right_motor.get_speed()”Write robot.right_motor.speed.
get_speed() was 0-100 whatever the direction; .speed is signed, -100 to 100 (negative = backward): abs(robot.right_motor.speed) is the old value
mobotROBOTICS.right_motor.get_direction()
Section titled “mobotROBOTICS.right_motor.get_direction()”Write robot.right_motor.speed.
get_direction() == 1 (forward on the Smart Car) -> robot.right_motor.speed > 0; == 0 -> robot.right_motor.speed < 0. At speed 0 the direction is no longer readable
mobotROBOTICS.buzzer.play
Section titled “mobotROBOTICS.buzzer.play”Write robot.buzzer.play_song.
the default changes from repeating to once: play(x) -> play_song(x, loop=True); play(x, looping=False) -> play_song(x); play(x, looping=v) -> play_song(x, loop=v)
mobotROBOTICS.buzzer.play(SONGS['demo']) # 2.xrobot.buzzer.play_song(SONGS['demo'], loop=True) # 3.0
mobotROBOTICS.buzzer.play(SONGS['demo'], looping=False) # 2.xrobot.buzzer.play_song(SONGS['demo']) # 3.0mobotROBOTICS.ble.isPressed[name]
Section titled “mobotROBOTICS.ble.isPressed[name]”Write robot.gamepad.is_pressed(name).
a subscript becomes a call with the same string: ble.isPressed['a'] -> gamepad.is_pressed("a"); names a, b, x, y, up, down, left, right
mobotROBOTICS.ble.isPressed['a'] # 2.xrobot.gamepad.is_pressed("a") # 3.0mobotROBOTICS.ble.isPressed
Section titled “mobotROBOTICS.ble.isPressed”Write robot.gamepad.buttons().
the whole dict (not subscripted) -> the call gamepad.buttons(), the same dict
mobotROBOTICS.ble.is_connected
Section titled “mobotROBOTICS.ble.is_connected”Write robot.bluetooth.is_connected().
always a call now: ble.is_connected (a property in 2.x; ble.is_connected() raised TypeError there) -> bluetooth.is_connected()
mobotROBOTICS.ble.map_range
Section titled “mobotROBOTICS.ble.map_range”Write map_range.
add from mobot import map_range at the top of the program; the arguments and the float result are unchanged
mobotROBOTICS.ble.map_range(x, -128, 127, 0, 100) # 2.xmap_range(x, -128, 127, 0, 100) # 3.0mobotROBOTICS.ultrasonic.is_object_detected
Section titled “mobotROBOTICS.ultrasonic.is_object_detected”Write robot.distance_sensor.sees_object.
the keyword threshold_cm= becomes within_cm=; positional calls are unchanged
mobotROBOTICS.color_sensor.compColor
Section titled “mobotROBOTICS.color_sensor.compColor”Write robot.color_sensor.is_color.
the argument order changes: compColor(reading, color, th=t) -> is_color(color, reading, tolerance=t); is_color(color) with no reading measures the sensor itself
mobotROBOTICS.color_sensor.compColor(rgb, (255, 0, 0), th=30) # 2.xrobot.color_sensor.is_color((255, 0, 0), rgb, tolerance=30) # 3.0mobotROBOTICS.compass.turn_to_heading
Section titled “mobotROBOTICS.compass.turn_to_heading”Write robot.compass.turn_to.
turn_to_heading(target_deg, base_speed=28, kp=0.8, tol_deg=5, timeout_s=8, L=None, R=None) -> turn_to(heading, speed=28, tolerance=5, timeout_s=8, left=None, right=None): drop L and R when they were the robot’s own motors (the default now), else pass them as left= / right=; kp is fixed at 0.8; base_speed= -> speed=, tol_deg= -> tolerance=
mobotROBOTICS.compass.turn_to_heading(90, L=mobotROBOTICS.left_motor, R=mobotROBOTICS.right_motor) # 2.xrobot.compass.turn_to(90) # 3.0mobotROBOTICS.buzzer.set_volume
Section titled “mobotROBOTICS.buzzer.set_volume”Write robot.buzzer.set_volume.
the unit changes from the PWM duty (0-65535, loudest 32768, default 2512) to percent (0-100, 100 = duty 32768): set_volume(d) -> set_volume(round(d * 100 / 32768)), capped at 100
mobotROBOTICS.buzzer.set_volume(32768) # 2.xrobot.buzzer.set_volume(100) # 3.0
mobotROBOTICS.buzzer.set_volume(2512) # 2.xrobot.buzzer.set_volume(8) # 3.0Smart Car: names that were removed
Section titled “Smart Car: names that were removed”These names have no alias on 3.0. A program that still uses one stops with an error.
mobotROBOTICS.ble.enable_activation_gate: inert since 2.1 (Bluetooth is always on); the call did nothing. What to write now: nothing: delete the callmobotROBOTICS.ble.is_activation_gate_enabled: inert since 2.1 (Bluetooth is always on); the call did nothing. What to write now: nothing: delete the callmobotROBOTICS.ble.is_activated: inert since 2.1 (Bluetooth is always on); the call did nothing. What to write now: nothing: delete the callmobotROBOTICS.servo: a second name for servo1. What to write now:robot.servo1mobotROBOTICS.compass.pivot: now private (_pivot). What to write now:robot.compass.turn_to(heading)mobotROBOTICS.compass.halt: now private (_halt). What to write now:robot.left_motor.stop(); robot.right_motor.stop()mobotROBOTICS.compass.save_calibration: now private (calibrate()saves). What to write now:robot.compass.calibrate()mobotROBOTICS.compass.load_calibration: now private (the compass loads it at start-up).mobotROBOTICS.battery_sensor.read_raw: now private (_read_raw). What to write now:robot.battery.voltage()mobotROBOTICS.battery_sensor.read_pin_voltage: now private (_read_pin_voltage). What to write now:robot.battery.voltage()
Smart Car: new in 3.0
Section titled “Smart Car: new in 3.0”robot.left_motor.drive(speed) / robot.right_motor.drive(speed): -100 to 100, negative = backwardrobot.gamepad: a read-only view of the app’s Game Pad: x, y,is_pressed(name),buttons()robot.name / robot.set_name(name) / robot.mode: on the root (wereble.mobot_name,ble.changeName,ble.control_mode)from mobot import map_range, sleep_ms: the shared helpers (src/helpers.py,src/mobot/__init__.py)robot.led1.toggle() / robot.led2.toggle(): the Mini had it; now the Smart Car toorobot.buzzer.volume: read only, percent (0-100); the default duty 2512 reads 8
Smart Car: names in the firmware source (programs do not use these)
Modules and classes that were renamed.
startup→smart_carBLE→ble_servicemobot_runner→mode_runnercapped_drive→speed_limits: internal: only the built-in modes use itfrom startup import mobotROBOTICS→from smart_car import robot: only firmware code and tests import it; a program uses the globalrobotstartup.mobotROBOTICS→smart_car.SmartCarmotors.Motors→motors.Motormotors.DRV8833_Motor→motors.DRV8833Motormotors.Servos→motors.Servoservo.Servo→servo.ServoDriverindicators.LED→indicators.Ledindicators.BuzzerPlayer→indicators.Buzzerindicators.Music→indicators.SongPlayersensors.IRs→sensors.LineSensorsensors.UltrasonicSensor→sensors.DistanceSensorsensors.Joysticks→sensors.Joysticksensors.BatterySensor→sensors.BatteryBLE.GamepadState→ble_service.Gamepad: Gamepad is a new read-only view (robot.gamepad); GamepadState stays as the internal state holdermobot_runner.sleep_ms→mode_runner.sleep_ms: a program writesfrom mobot import sleep_ms;mode_manager.sleep_mskeeps its name
Removed from the firmware source.
BLE.ActivationGate: inert since 2.1.BLEController(activation_pin=...): the inert gate’s button pin; the Smart Car no longer configures GPIO 13 with a pull-up at boot.motors.DRV8833_Motor: the 2.x alias of DRV8833Motor (no aliases). What to write now:motors.DRV8833Motor
Internal names. The simulator and the firmware tests use these. A program does not.
BLE.NVS→ble_service.SettingsFile: the settings file (/mobot.json,/mobot_mini.json); keys unchangedBLEController._nvs→BLEController._settingsBLEController.isPressed→BLEController.buttonsBLEController.changeName()→BLEController.set_name()BLEController.is_connected→BLEController.is_connected(): a method now (was a property)BLEController.map_range→helpers.map_rangeModeHooks.R / ModeLink.R→ModeHooks.runner / ModeLink.runner: the mode runner enginecapped_drive.CappedDrive(ble, left, right, forward, tag, config_sides_swapped)→speed_limits.SpeedLimitedDrive(ble, left, right, tag, config_sides_swapped): the forward argument is gone: each motor’sforward()knows its kitmode_manager.capped_drive(tag)→mode_manager.speed_limited_drive(tag)mode_manager.FORWARD→(removed): the motors carry itindicators.Music.playingNotes / playingDurations→indicators.SongPlayer.playing_notes / playing_durationsindicators.BuzzerPlayer.current_song (attribute)→indicators.Buzzer._current_song (+ property current_song)mobotROBOTICS.init / cleanup / _stop_outputs / _restore_shared / _reset_after_program (staticmethods on the class)→robot._init / _cleanup / _stop_outputs / _restore_shared / _reset_after_program (methods of the instance): the simulator’s shims call thesemobotROBOTICS._built→robot._built: an instance attribute nowindicators.buzzer_init_freq() / buzzer_pin_number()→indicators._buzzer_init_freq() / _buzzer_pin_number()BLE.IRLineSensorData→ble_service.LineSensorDataBLE.UltrasonicData→ble_service.DistanceDatasensors.ColorSensor._setTh()→sensors.ColorSensor._set_threshold()mobotROBOTICS._battery_telemetry_loop / start_battery_telemetry (staticmethods)→robot._battery_telemetry_loop / start_battery_telemetry (methods)
On firmware 2.x, a program for the Mini used mobotMINI. On 3.0 it is robot.
Mini: names that changed
Section titled “Mini: names that changed”mobotMINI→robot: an instance of class SmartCarMini (smart_car_mini.py), bound in__main__by_boot.py. EverymobotMINI.prefix becomesrobot.; the entries below are the members whose own name changes toomobotMINI.ble→robot.bluetooth: the BLEController; every otherble.*member not listed here keeps its name under bluetoothmobotMINI.init()→robot._init(): internal since 3.0.0: the mode runner and the simulator call it, a program does notmobotMINI.cleanup()→robot._cleanup(): internal since 3.0.0: the mode runner and the simulator call itmobotMINI.led1.setState→robot.led1.set:True/Falseor 1/0, as beforemobotMINI.led1.setLedBrightness→robot.led1.set_brightness: the argument was already a percent, 0-100mobotMINI.led2.setState→robot.led2.set:True/Falseor 1/0, as beforemobotMINI.led2.setLedBrightness→robot.led2.set_brightness: the argument was already a percent, 0-100mobotMINI.buzzer.get_current_song()→robot.buzzer.current_songmobotMINI.ble.x→robot.gamepad.x: -128 (left) to 127 (right)mobotMINI.ble.y→robot.gamepad.y: -128 (down) to 127 (up)mobotMINI.ble.changeName→robot.set_namemobotMINI.ble.mobot_name→robot.namemobotMINI.ble.control_mode→robot.mode: 255 = ProgrammablemobotMINI.rgb→robot.rgb_led: the same name as the Smart Home’s; colours 0-255 as beforemobotMINI.rgb.get_brightness()→robot.rgb_led.brightnessmobotMINI.rgb.start_flash→robot.rgb_led.blink: (r, g, b), calltick()in the loop, as beforemobotMINI.rgb.start_rainbow()→robot.rgb_led.rainbow()mobotMINI.rgb.flash(r, g, b, duration_ms=50)→robot.rgb_led.flash(r, g, b, duration_ms=50): the blocking one-shot flash, as before: every LED shows the colour (0-255 each, at the current brightness) for duration_ms, then gets back the colour it had; a runningblink()orrainbow()goes onmobotMINI.ultrasonic→robot.distance_sensor: a DistanceSensor now (it was the raw HCSR04): a failed reading is -1 instead of an exceptionmobotMINI.initUltrasonic()→robot.enable_distance_sensor()mobotMINI.initIRs()→robot.enable_line_sensor()
Mini: names that change how you call them
Section titled “Mini: names that change how you call them”For these, the arguments change too. Each one comes with its rule, and an example when the map has one.
mobotMINI.left_motor.set_direction_and_speed
Section titled “mobotMINI.left_motor.set_direction_and_speed”Write robot.left_motor.forward or robot.left_motor.backward.
set_direction_and_speed(d, s) -> robot.left_motor.forward(s) when d == 0 (forward on the Mini), else robot.left_motor.backward(s). A d that is not a literal: robot.left_motor.drive(s if d == 0 else -s)
mobotMINI.left_motor.set_direction_and_speed(0, 60) # 2.xrobot.left_motor.forward(60) # 3.0
mobotMINI.left_motor.set_direction_and_speed(1, 60) # 2.xrobot.left_motor.backward(60) # 3.0mobotMINI.left_motor.set_direction
Section titled “mobotMINI.left_motor.set_direction”Write robot.left_motor.forward or robot.left_motor.backward.
set_direction(d) followed by a speed write -> forward(s) / backward(s) with d == 0 meaning forward; set_direction(d) alone (keep the speed, change the way) -> robot.left_motor.forward(abs(robot.left_motor.speed)) when d == 0, else robot.left_motor.backward(abs(robot.left_motor.speed))
mobotMINI.left_motor.get_speed()
Section titled “mobotMINI.left_motor.get_speed()”Write robot.left_motor.speed.
get_speed() was 0-100 whatever the direction; .speed is signed, -100 to 100 (negative = backward): abs(robot.left_motor.speed) is the old value
mobotMINI.left_motor.get_direction()
Section titled “mobotMINI.left_motor.get_direction()”Write robot.left_motor.speed.
get_direction() == 0 (forward on the Mini) -> robot.left_motor.speed > 0; == 1 -> robot.left_motor.speed < 0. At speed 0 the direction is no longer readable
mobotMINI.right_motor.set_direction_and_speed
Section titled “mobotMINI.right_motor.set_direction_and_speed”Write robot.right_motor.forward or robot.right_motor.backward.
set_direction_and_speed(d, s) -> robot.right_motor.forward(s) when d == 0 (forward on the Mini), else robot.right_motor.backward(s). A d that is not a literal: robot.right_motor.drive(s if d == 0 else -s)
mobotMINI.right_motor.set_direction_and_speed(0, 60) # 2.xrobot.right_motor.forward(60) # 3.0
mobotMINI.right_motor.set_direction_and_speed(1, 60) # 2.xrobot.right_motor.backward(60) # 3.0mobotMINI.right_motor.set_direction
Section titled “mobotMINI.right_motor.set_direction”Write robot.right_motor.forward or robot.right_motor.backward.
set_direction(d) followed by a speed write -> forward(s) / backward(s) with d == 0 meaning forward; set_direction(d) alone (keep the speed, change the way) -> robot.right_motor.forward(abs(robot.right_motor.speed)) when d == 0, else robot.right_motor.backward(abs(robot.right_motor.speed))
mobotMINI.right_motor.get_speed()
Section titled “mobotMINI.right_motor.get_speed()”Write robot.right_motor.speed.
get_speed() was 0-100 whatever the direction; .speed is signed, -100 to 100 (negative = backward): abs(robot.right_motor.speed) is the old value
mobotMINI.right_motor.get_direction()
Section titled “mobotMINI.right_motor.get_direction()”Write robot.right_motor.speed.
get_direction() == 0 (forward on the Mini) -> robot.right_motor.speed > 0; == 1 -> robot.right_motor.speed < 0. At speed 0 the direction is no longer readable
mobotMINI.buzzer.play
Section titled “mobotMINI.buzzer.play”Write robot.buzzer.play_song.
the default changes from repeating to once: play(x) -> play_song(x, loop=True); play(x, looping=False) -> play_song(x); play(x, looping=v) -> play_song(x, loop=v)
mobotMINI.buzzer.play(SONGS['demo']) # 2.xrobot.buzzer.play_song(SONGS['demo'], loop=True) # 3.0
mobotMINI.buzzer.play(SONGS['demo'], looping=False) # 2.xrobot.buzzer.play_song(SONGS['demo']) # 3.0mobotMINI.ble.isPressed[name]
Section titled “mobotMINI.ble.isPressed[name]”Write robot.gamepad.is_pressed(name).
a subscript becomes a call with the same string: ble.isPressed['a'] -> gamepad.is_pressed("a"); names a, b, x, y, up, down, left, right
mobotMINI.ble.isPressed['a'] # 2.xrobot.gamepad.is_pressed("a") # 3.0mobotMINI.ble.isPressed
Section titled “mobotMINI.ble.isPressed”Write robot.gamepad.buttons().
the whole dict (not subscripted) -> the call gamepad.buttons(), the same dict
mobotMINI.ble.is_connected
Section titled “mobotMINI.ble.is_connected”Write robot.bluetooth.is_connected().
always a call now: ble.is_connected (a property in 2.x; ble.is_connected() raised TypeError there) -> bluetooth.is_connected()
mobotMINI.ble.map_range
Section titled “mobotMINI.ble.map_range”Write map_range.
add from mobot import map_range at the top of the program; the arguments and the float result are unchanged
mobotMINI.ble.map_range(x, -128, 127, 0, 100) # 2.xmap_range(x, -128, 127, 0, 100) # 3.0mobotMINI.rgb.get_color()
Section titled “mobotMINI.rgb.get_color()”Write robot.rgb_led.color.
get_color(index) for a chained LED other than 0 has no 3.0 form (the kit has one LED)
mobotMINI.left_ir.value()
Section titled “mobotMINI.left_ir.value()”Write robot.line_sensor.read(0).
eye 0 is the left one
mobotMINI.right_ir.value()
Section titled “mobotMINI.right_ir.value()”Write robot.line_sensor.read(1).
eye 1 is the right one
mobotMINI.left_ir
Section titled “mobotMINI.left_ir”Write robot.line_sensor.
[left_ir.value(), right_ir.value()] -> line_sensor.read()
mobotMINI.right_ir
Section titled “mobotMINI.right_ir”Write robot.line_sensor.
see left_ir
mobotMINI.buzzer.set_volume
Section titled “mobotMINI.buzzer.set_volume”Write robot.buzzer.set_volume.
the unit changes from the PWM duty (0-65535, loudest 32768, default 2512) to percent (0-100, 100 = duty 32768): set_volume(d) -> set_volume(round(d * 100 / 32768)), capped at 100
mobotMINI.buzzer.set_volume(32768) # 2.xrobot.buzzer.set_volume(100) # 3.0
mobotMINI.buzzer.set_volume(2512) # 2.xrobot.buzzer.set_volume(8) # 3.0Mini: names that were removed
Section titled “Mini: names that were removed”These names have no alias on 3.0. A program that still uses one stops with an error.
mobotMINI.ble.enable_activation_gate: inert since 2.1 (Bluetooth is always on); the call did nothing. What to write now: nothing: delete the callmobotMINI.ble.is_activation_gate_enabled: inert since 2.1 (Bluetooth is always on); the call did nothing. What to write now: nothing: delete the callmobotMINI.ble.is_activated: inert since 2.1 (Bluetooth is always on); the call did nothing. What to write now: nothing: delete the callmobotMINI.left_motor.FORWARD / REVERSE: raw direction numbers (D4: no direction numbers). What to write now:forward() / backward()
Mini: new in 3.0
Section titled “Mini: new in 3.0”robot.left_motor.drive(speed) / robot.right_motor.drive(speed): -100 to 100, negative = backwardrobot.gamepad: a read-only view of the app’s Game Pad: x, y,is_pressed(name),buttons()robot.name / robot.set_name(name) / robot.mode: on the root (wereble.mobot_name,ble.changeName,ble.control_mode)from mobot import map_range, sleep_ms: the shared helpers (src/helpers.py,src/mobot/__init__.py)robot.line_sensor: a LineSensor over the Mini’s two IR eyes (GPIO 26 left, 27 right):read(),read(i),matches()robot.distance_sensor.sees_object(within_cm=10): as on the Smart Carrobot.buzzer.volume: read only, percent (0-100); the default duty 2512 reads 8
Mini: names in the firmware source (programs do not use these)
Modules and classes that were renamed.
startup→smart_car_miniBLE→ble_servicemobot_runner→mode_runnercapped_drive→speed_limits: internal: only the built-in modes use itfrom startup import mobotMINI→from smart_car_mini import robot: only firmware code and tests import it; a program uses the globalrobotstartup.mobotMINI→smart_car_mini.SmartCarMinimotors.DRV8833_Motor→motors.DRV8833Motorindicators.LED→indicators.Ledindicators.BuzzerPlayer→indicators.Buzzerindicators.Music→indicators.SongPlayerrgb_led.RGB_LED→rgb_led.RGBLedBLE.GamepadState→ble_service.Gamepad: Gamepad is a new read-only view (robot.gamepad); GamepadState stays as the internal state holdermobot_runner.sleep_ms→mode_runner.sleep_ms: a program writesfrom mobot import sleep_ms;mode_manager.sleep_mskeeps its name
Removed from the firmware source.
BLE.ActivationGate: inert since 2.1.BLEController(activation_pin=...): the inert gate’s button pin; the Smart Car no longer configures GPIO 13 with a pull-up at boot.
Internal names. The simulator and the firmware tests use these. A program does not.
BLE.NVS→ble_service.SettingsFile: the settings file (/mobot.json,/mobot_mini.json); keys unchangedBLEController._nvs→BLEController._settingsBLEController.isPressed→BLEController.buttonsBLEController.changeName()→BLEController.set_name()BLEController.is_connected→BLEController.is_connected(): a method now (was a property)BLEController.map_range→helpers.map_rangeModeHooks.R / ModeLink.R→ModeHooks.runner / ModeLink.runner: the mode runner enginecapped_drive.CappedDrive(ble, left, right, forward, tag, config_sides_swapped)→speed_limits.SpeedLimitedDrive(ble, left, right, tag, config_sides_swapped): the forward argument is gone: each motor’sforward()knows its kitmode_manager.capped_drive(tag)→mode_manager.speed_limited_drive(tag)mode_manager.FORWARD→(removed): the motors carry itindicators.Music.playingNotes / playingDurations→indicators.SongPlayer.playing_notes / playing_durationsindicators.BuzzerPlayer.current_song (attribute)→indicators.Buzzer._current_song (+ property current_song)mobotMINI.init / cleanup / _stop_outputs / _restore_shared / _reset_after_program (staticmethods on the class)→robot._init / _cleanup / _stop_outputs / _restore_shared / _reset_after_program (methods of the instance): the simulator’s shims call thesemobotMINI._built→robot._built: an instance attribute now
Smart Home
Section titled “Smart Home”On firmware 2.x, a program for the Smart Home used mobotIOT. On 3.0 it is home.
Smart Home: names that changed
Section titled “Smart Home: names that changed”mobotIOT→home: an instance of class SmartHome (smart_home.py), bound in__main__by_boot.py. EverymobotIOT.prefix becomeshome.; the entries below are the members whose own name changes toomobotIOT.dht11→home.temperature_sensormobotIOT.pir→home.motion_sensormobotIOT.mq135→home.gas_sensormobotIOT.ldr→home.light_sensormobotIOT.pot→home.knobmobotIOT.oled→home.displaymobotIOT.seg→home.number_displaymobotIOT.server→home.dashboardmobotIOT.mq135.read()→home.gas_sensor.level(): raw 0-4095, as beforemobotIOT.ldr.read()→home.light_sensor.level(): raw 0-4095, as beforemobotIOT.pot.read()→home.knob.position(): raw 0-4095, as beforemobotIOT.battery.read()→home.battery.voltage(): volts, two decimalsmobotIOT.rfid.read()→home.rfid.read_card()mobotIOT.led1.write_percent→home.led1.set_brightness: percent, 0-100mobotIOT.led2.write_percent→home.led2.set_brightness: percent, 0-100mobotIOT.seg.number→home.number_display.show_numbermobotIOT.seg.show_number→home.number_display.show_number: (n,dots=None): dots is a list of threeTrue/FalsemobotIOT.seg.set_segments_for_digit→home.number_display.set_digitmobotIOT.init_seg()→home.enable_number_display()mobotIOT.buzzer.play_sound→home.buzzer.play_tone: (frequency Hz, duration ms)mobotIOT.buzzer.play_sequence→home.buzzer.play_notesmobotIOT.buzzer.is_busy()→home.buzzer.is_playing()mobotIOT.servo.get_angle()→home.servo.anglemobotIOT.servo.min()→home.servo.move_to_min()mobotIOT.servo.max()→home.servo.move_to_max()mobotIOT.fan.get_speed()→home.fan.speedmobotIOT.oled.display_text→home.display.show_textmobotIOT.oled.clear_screen()→home.display.clear()mobotIOT.oled.display_frame→home.display.show_framemobotIOT.wifi.connected()→home.wifi.is_connected()mobotIOT.server.start_web_server→home.dashboard.startmobotIOT.server.stop_web_server→home.dashboard.stopmobotIOT.server.register_toggle→home.dashboard.add_switch: returns the control’s number, as beforemobotIOT.server.register_slider→home.dashboard.add_slider: returns the control’s numbermobotIOT.server.register_rgb→home.dashboard.add_color: returns the control’s numbermobotIOT.server.register_text→home.dashboard.add_text: returns the control’s numbermobotIOT.server.get_toggle→home.dashboard.switch: takes the numberadd_switch()returned, as beforemobotIOT.server.get_slider→home.dashboard.slider: takes the numberadd_slider()returnedmobotIOT.server.get_rgb→home.dashboard.color: takes the numberadd_color()returnedmobotIOT.server.get_text→home.dashboard.text: takes the numberadd_text()returnedmobotIOT.server.get_server_ip→home.dashboard.ipmobotIOT.server.is_server_running→home.dashboard.is_running
Smart Home: names that change how you call them
Section titled “Smart Home: names that change how you call them”For these, the arguments change too. Each one comes with its rule, and an example when the map has one.
mobotIOT.dht11.read
Section titled “mobotIOT.dht11.read”Write home.temperature_sensor.temperature or home.temperature_sensor.humidity.
read(0) -> temperature(), read(1) -> humidity(); a mode that is not a literal: (temperature() if m == 0 else humidity())
mobotIOT.dht11.read(0) # 2.xhome.temperature_sensor.temperature() # 3.0
mobotIOT.dht11.read(1) # 2.xhome.temperature_sensor.humidity() # 3.0mobotIOT.rgb_led.write
Section titled “mobotIOT.rgb_led.write”Write home.rgb_led.set_color.
percent becomes 0-255: write(r, g, b) -> set_color(round(r * 255 / 100), round(g * 255 / 100), round(b * 255 / 100)); a literal 100 is 255, 50 is 128
mobotIOT.rgb_led.write(100, 50, 0) # 2.xhome.rgb_led.set_color(255, 128, 0) # 3.0from utils import map
Section titled “from utils import map”Write from mobot import map_range.
map(x, a, b, c, d) -> int(map_range(x, a, b, c, d)): utils.map floored an integer division, map_range returns a float; the int() keeps the old value whenever it is not negative
Smart Home: names that were removed
Section titled “Smart Home: names that were removed”These names have no alias on 3.0. A program that still uses one stops with an error.
mobotIOT.rgb_led.write: hidden as_write(), still in percent, for the firmware’s own callers. What to write now:home.rgb_led.set_color(r, g, b), 0-255mobotIOT.seg.show: a TM1637 driver method that was reachable through seg;home.number_displayoffersshow_number()andset_digit(). What to write now:home.number_display.show_number(n)mobotIOT.seg.float: a TM1637 driver method that was reachable through seg;home.number_displayoffersshow_number()andset_digit(). What to write now:home.number_display.show_number(n)mobotIOT.seg.raw: a TM1637 driver method that was reachable through seg;home.number_displayoffersshow_number()andset_digit(). What to write now:home.number_display.set_digit(index, segments)
Smart Home: new in 3.0
Section titled “Smart Home: new in 3.0”home.rgb_led.set_color(r, g, b): 0-255home.number_display.show_number(n, dots=None): dots: a list of threeTrue/False, now on the TM1637home.number_display.show_text(text): up to 3 characters, right-aligned like show_number,""blanks it: 0-9,'-', space and the letters A b C d E F H L P in either case ('B'draws b,'a'draws A; b and d always look small); any other character, or more than 3, raises ValueError naming what works, and the display keeps what it showedfrom mobot import map_range, sleep_ms: the shared helpers (sleep_ms istime.sleep_mson the Smart Home)
Smart Home: names in the firmware source (programs do not use these)
Modules and classes that were renamed.
iot_startup→smart_homeserver→dashboardTM1637→tm1637utils→helpers:helpers.pyis shared by all four boards (src/ root); a program imports from mobot instead:from mobot import map_rangeiot_startup.mobotIOT→smart_home.SmartHomesensors.DHT11→sensors.TemperatureSensorsensors.PIRSensor→sensors.MotionSensorsensors.MQ135→sensors.GasSensorsensors.LDR→sensors.LightSensorsensors.Potentiometer→sensors.Knobsensors.RFID→sensors.RFIDReaderdisplays.OLEDWrapper→displays.Displaydisplays.SimpleLed→displays.LedTM1637.TM1637_CA→tm1637.TM1637CommonAnodeactuators.ServoWrapper→actuators.Servoservo.Servo→servo.ServoDriverserver.ConfigurableServer→dashboard.Dashboarddisplays.SevenSegment3Digit→displays.NumberDisplay: NumberDisplay drives the house’s TM1637 (TM1637CommonAnode); the GPIO-multiplexing SevenSegment3Digit, which the kit never built, is gone
Removed from the firmware source.
utils.hello: a test leftover.displays.SevenSegment3Digit(segment_pins, digit_pins): a GPIO-multiplexed 3-digit driver the house never built; NumberDisplay drives the TM1637. What to write now:home.number_display
Internal names. The simulator and the firmware tests use these. A program does not.
sensors._ArbitratedADC.read()→sensors._ArbitratedADC._read()sounds.Buzzer.is_playing (attribute)→sounds.Buzzer._playing: freed the name for the methodis_playing()displays.RGBLed.write()→displays.RGBLed._write(): percent; Improv, the boot colours and/api/act/rgbuse itthe TM1637 driver behind seg→home.number_display._driver: the monitors engine usesraw(),float(),number()through itserver.server (the instance)→dashboard.server
Names that did not change, on purpose
Section titled “Names that did not change, on purpose”- the Bluetooth GATT contract (UUIDs, frames, event types)
- the Smart Home HTTP routes and their JSON, and the Improv protocol
- the settings files and their keys (
/mobot.json,/mobot_mini.json,compass_cal.json,mobot_mini_sequence.bin) - the mode ids, the serial markers (MOBOT-MODE…),
boot.py/main.py/_boot.py - mode_manager (module and
resume()),BLEController.set_control_mode(), ColorSensor, Compass, Fan, Button, the chip drivers home.dashboard.update_*and set_ssid_password,home.wifi.ip/house_id/networks/forget/hostname