Skip to content

TotemRobot

Object representing remote Totem robot connection over BLE

Functions list

Result Function Description
String getName() Get robot name
String getAddress() Get robot MAC address
int getModel() Get robot model (type) hash
int getColor() Get robot appearance color
int getNumber() Get robot module number
bool isConnected() Check if connection is active
bool connect() Connect to robot
none disconnect() Disconnect from robot
none attach(TotemModule) Attach module to connection
none detach(TotemModule) Detach module from connection

Example

void setup() {
  Serial.begin(115200);
  // Initialize Totem BLE interface
  Totem.BLE.begin();
  // Start searching for Totem robot and block further
  // code execution until any robot is connected
  TotemRobot robot = Totem.BLE.findRobot();
  // Robot (module) connected. Print name:
  Serial.print("Connected robot: ");
  Serial.println(robot.getName());
}

Description

String getName()

Description: Get robot Bluetooth name.
Same as configured in cfg/robot/name command.
Result: String containing robot Bluetooth name.

TotemRobot robot = Totem.BLE.findRobot(); // Find and connect a robot
Serial.print("Connected to: ");
Serial.println(robot.getName());

String getAddress()

Description: Get robot Bluetooth MAC (example: "00:11:22:33:44:55"). Each robot has unique address.
Result: String containing robot Bluetooth address.

TotemRobot robot = Totem.BLE.findRobot(); // Find and connect a robot
Serial.print("Connected robot MAC address: ");
Serial.println(robot.getAddress());

int getModel()

Description: Get robot Totem model hash.
Each one can have assigned hashed module string to tell apart what Totem product is used with particular controller. This hash can be generated with TotemModule::hashModel("MiniTrooper").
Can be configured with cfg/robot/model command.
Result: Totem robot model number.

void setup() {
  TotemRobot robot = Totem.BLE.findRobot(); // Find and connect a robot
  Serial.print("Connected robot model number: ");
  Serial.println(robot.getModel());
  if (robot.getModel() == TotemModule::hashModel("MiniTrooper")) {
    // Check if robot is MiniTrooper
  }
}

int getColor()

Description: Get robot appearance color. Each robot can have different color to tell them apart easier. Also this color can be used for on board RGB LEDs.
Result: 16bit High color encoding.

void setup() {
  TotemRobot robot = Totem.BLE.findRobot(); // Find and connect a robot
  Serial.print("Connected robot color code: 0x");
  Serial.println(robot.getColor(), HEX);
}

int getNumber()

Description: Get robot controller board module number.
To identify if connecting to X4 or X3.
Result: module number.

void setup() {
  TotemRobot robot = Totem.BLE.findRobot(); // Find and connect a robot
  Serial.print("Connected to module: ");
  Serial.println(robot.getNumber());
}

bool isConnected()

Description: Check if robot is connected over BLE.
Result: true if robot is connected, false otherwise.

void function() {
  TotemRobot robot = Totem.BLE.getConnectedLast(); // Get last connected robot
  if (robot.isConnected())
    Serial.println("Robot is connected");
  else
    Serial.println("Robot is not connected");
}

bool connect()

Description: Connect to Totem robot over BLE.
Result: true if connected, false on failure.

void onFoundRobot(TotemRobot robot) { // findRobot event listing each discovered device
  if (robot.connect()) // Establish connection to selected robot
    Serial.println("Totem robot connected");
  else
    Serial.println("Connection failed");
}

disconnect()

Description: Manually disconnect from robot connected over BLE.

void function() {
  TotemRobot robot = Totem.BLE.getConnectedLast(); // Get last connected robot
  robot.disconnect(); // Robot will be disconnected
}

attach(TotemModule)

Description: Attach selected TotemModule to active BLE connection.
All initialized modules are automatically attached to active connection. This is required if connecting to more than one robot at the same time and to use separate TotemModule objects in multiple connections.

TotemModule module(03);
void function() {
  TotemRobot robot = Totem.BLE.getConnectedLast(); // Get last connected robot
  robot.attach(module); // Assign module X3 object to selected robot connection.
                        // "module" now will only control X3 modules that are available in provided "robot" connection.
}

detach(TotemModule)

Description: Detach selected TotemModule from active BLE connection.

TotemModule module(03);
void function() {
  TotemRobot robot = Totem.BLE.getConnectedLast(); // Get last connected robot
  robot.detach(module); // Detach module X3 object from selected robot connection. 
                        // "module"' will no longer respond to commands
}