Skip to content

TotemRobot

Object representing remote Totem robot connection over BLE. Received from Totem.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());
}

API

Functions

getName()

Get robot Bluetooth name. Same as configured in cfg/robot/name command.
Returns: String containing robot Bluetooth name.
TotemRobot robot = Totem.BLE.findRobot(); // Find and connect a robot
Serial.print("Connected to: ");
Serial.println(robot.getName());

getAddress()

Get robot Bluetooth MAC (e.g. "00:11:22:33:44:55"). Each robot has unique address.
Returns: 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());

getModel()

Get robot Totem model hash.
Each one can have assigned hashed 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.
Returns: Totem robot model hash [0:0xFFFF].
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
  }
}

getColor()

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 lights.
Returns: 24bit color code [0x000000:0xFFFFFF].
void setup() {
  TotemRobot robot = Totem.BLE.findRobot(); // Find and connect a robot
  Serial.print("Connected robot color code: 0x");
  Serial.println(robot.getColor(), HEX);
}

getNumber()

Get robot controller board module number.
To identify if connecting to X4 or X3.
Returns: module number [0:255].
void setup() {
  TotemRobot robot = Totem.BLE.findRobot(); // Find and connect a robot
  Serial.print("Connected to module: ");
  Serial.println(robot.getNumber());
}

isConnected()

Check if robot is connected over BLE.
Returns: is robot connected [true:false].
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");
}

connect()

Connect to Totem robot over BLE.
Returns: connection is successful [true:false].
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()

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)

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 Mini Control Board X3 that are available in provided "robot" connection.
}

detach(TotemModule)

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
}