Skip to content

Vehicle Capabilities

decltype(auto) edited this page Mar 20, 2022 · 18 revisions

This page contains information and notes on each attachment implemented currently on the virtual car.

Attachments

SMCE Implements most sensors exposed in the Smartcar shield library, and tries to emulate them, though do note that these are likely to not match the real world.

Motor

Amount: 2
Pins: 12,14,13 - 25,26,27
Class: BrushedMotor
Notes:

  • Use smartcarlib::pins::v2::leftMotorPins and smartcarlib::pins::v2::rightMotorPins in the ctor to get the right pins.
  • BrushedMotor::setSpeed take a percentage from 0 to 100, in the emulator this percentage translates to a target speed.

Infrared distance sensor

Amount: 4
Pins: 0 - 1 - 2 - 3
Classes: GP2D120, GP2Y0A02, GP2Y0A21
Notes:

  • Maximum distance of .4 meters, no minimum distance.
  • All classes share the same implementation, so any may work.
  • Infrareds have relatively small range, press F3 to toggle a debug view to see where they point to.

Ultrasonic distance sensor

Amount: 1
Pins: 6,7
Class: SR04
Notes:

  • Maximum distance of 4 meters, minimum distance of 2 cm.
  • While it has a large range, a bit of noise is introduced artificially to better emulate how utlra-sonics work.
  • Unlike the infrared sensors, the ultrasonic sensor has a cone shape.
  • At the time of writing the ultrasonic distance sensor does not take the hit angle into account, so the sensor may hit the ground at times.

Odometer

Amount: 2
Pins: 35,34 - 36,39
Class: DirectionalOdometer (and DirectionlessOdometer)
Notes:

  • Use smartcarlib::pins::v2::leftOdometerPins and smartcarlib::pins::v2::rightOdometerPins in the ctor to get the right pins.
  • While originally intended to be interrupt based, that's not the case in our re-implementation; don't expect the passed function in the ctor to be executed.
  • Unlike the real world, these odometers track absolute distance traveled, not wheel spin.
  • Due to a current implementation detail, the maximum distance tracked is 2^16 cm. So don't depend on the odometers counting up infinitely.

Gyroscope

Amount: 1
Pins: not applicable
Class: GY50
Notes:

  • The virtual gyroscope simple reports back the absolute local horizontal rotation, while reliable virtually, in the real world it's not; so don't use it to determine absolute direction.
  • Offset is currently ignored and will always be 0.

Camera

Amount: 1
pins: not applicable
Class: OV767X
Notes:

  • You have to include OV767X.h to get access to it.
  • There is a global Camera object which you can use; manually creating one is not needed.
  • See here for the API and here on how to use it in practice.
  • Max resolution is 640x480@30fps, you can see the active resolution and fps in the attachment GUI.

Unsupported attachments

  • VL53L0X
  • SRF08
  • ServoMotor

Networking

While conventional networking capabilities are not supported (Think WiFi and Bluetooth) due to complexity, SMCE provides a custom MQTT implementation using the arduino-mqtt interface with the only caveat being that you cannot actually use the WiFi class, as it's merely a shim. Here is an example sketch on how to use it:

#include <MQTT.h>
#include <WiFi.h>

WiFiClient net;
MQTTClient mqtt;

void setup() {
    Serial.begin(9600);
    mqtt.begin("aerostun.dev", 1883, net);
    // Will connect to localhost port 1883 be default
    if (mqtt.connect("arduino", "public", "public")) {
        mqtt.subscribe("/", 2);
        mqtt.onMessage(+[](String& topic, String& message) {
            // handle the message
            Serial.println("Topic: " + topic + " Message: " + message);
        });
    }
}

void loop() {
    if (mqtt.connected())
        mqtt.loop();
}

SDCard (>=v1.3)

The SD Arduino library can be used to get filesystem access.
By default there are no SD cards available, to configure one add the following to your board_config.json:

{
    "sd_cards": [{ "cspin":  0, "root_dir":  "sdcard" }]
}

root_dir is the directory SMCE-gd will use to emulate the root directory of the sdcard,
in the example above the folder sdcard is relative to the sketch file's base folder.
You can also specify an absolute path but that will break portability.