Before you use Laptop-Toio, you will need to download:
- Processing
- Also make sure to add the
oscP5
library from theSketch > Import Library... > Manage Libraries...
button.
- Also make sure to add the
- Rust
All of the Low-Level Bluetooth Toio is handled within Rust, while the Higher-Level Simulations is done within Processing.
Our Rust code allows us to connect to toios by using their 'name' (An internal 3-digit alphanumeric id built into the firmware), or their AxLab ID (Written on the bottom of the toio). We can connect using the following command
First, clone this repository, and use terminal to navigate to rust_osc folder. From there, run:
cargo run -- -a 48,46
NOTE: Do not uses spaces between the IDs.
Using the -a
flag allows us to connect using the AxLab ID. When needed, we can also use -n
to connect directly to their internal name, or even combine the two. For example: cargo run -- -n P1B
or cargo run -- -a 46 -n P1B
There are special flags for specific cases.
- Running Laptop-Toio with the command
cargo run -- -s
will allow you to connect to all nearby toios, in case you don't want to deal with the hassle of looking over which toios you have. NOTE: Only use this flag when there is no one else using toios nearby. - Running Laptop-Toio with the command
cargo run -- -o -a 48,46
will attempt to connect to the toios in the specific order you passed them in. In this case, that would be 48 and then 46
The full toio API allows us to send commands and request information from the toio. Most of these API requests have been implemented within Laptop-toio on the Rust and Processing side to allow us to control toios. All of these functions are available on the Cube
tab of the processing code. All of the toios are stored an array called cubes
. This means that you can access each toio with cubes[i]
, where i
is the order thetoios connected in.
There are 5 tabs in the Laptop-Toio Processing Code:
- The
toio processing
tab includes three core functions:settings
: The function allows you to configure your programsetup
: This function is called once at the beginning of your programdraw
: This function is called continously every tick This tab is analogous to thesetup
andloop
structure in arduino
- The
cube
tab includes all of the information on theCube
struct which stores most of the values and methods used to communicate with toios - The
events
tab allows you to handle different events from the keyboard, mouse or the toios. - The
motorVelocityTarget
tab includes the code for thevelocityTarget
function, which is an advanced function used to travel smoothly over time - The
osc
tab handles the communication with the rust code, and sends commands to the toios.
For the most part, you will purely be writing your code in the toio processing
and events
tabs, and cube
can be refered for you to quickly understand different commands.
Processing allows you to write code in two ways:
- The
draw()
function is called continously on a loop. If you want your code to run on a regular interval, this is the best place to put it. - The
events
tab is comprised of many functions that are called on certain events.- Keyboard and Mouse events call the
keyPressed
,mousePressed
andmouseReleased
functions. If you want an extended look at the GUI events that are registered by Processing, you can look at the Keyboard and Mouse sections here. - toio events automatically call the
buttonDown
,buttonUp
,collision
anddoubleTap
functions. These functions will pass the toio IDs as a function parameter, allowing you to use them in your code.
- Keyboard and Mouse events call the
We are send comannds to control to control:
- The Motors: NOTE: the maximum speed of a motor on a toio is 115. That commands that can control the toio are:
cubes[i].motor
: can be called with eitherleftSpeed, rightSpeed
orleftSpeed, rightSpeed, duration
, allowing you to control the speed of each motor individually for a set duration. Further documentation can be found here and here.cubes[i].target
: can be called withx, y, theta
,mode, x, y, theta
orcontrol, timeout, mode, maxspeed, speedchange, x, y, theta
, allowing you to target a specific location. Further documentation can be found here.cubes[i].accelerate
: can be called withspeed, acc, rotateVelocity, rotateDir, dir, priority, duration
, allowing you to control acceleration of the motors. Further documentation can be found here.cubes[i].multiTarget
: can be called withmode, targets
orcontrol, timeout, mode, maxspeed, speedchange, targets
where targets are a 2D array for each target marked as{x, y}
or{x, y, theta}
. Unless specified,theta = 0
. Further documentation can be found here.- Advanced:
cubes[i].velocityTarget
is a function developed by AxLab to allow toiois to follow a continously moving target. WhenvelocityTarget
is called withx, y
values every loop, the motion between the targets will be automatically smoothed out. WARNING: This behavior will only occur if the function is called every loop. The velocity is caculated by storing values within thetargetx, targety
andtargetTime
variables within theCube
class.
- The LED Indicator:
cubes[i].led
can be used to set the LED to a certain color withduration, red, green, blue
or to produce an LED sequence withrepetitions, lights
wherelights
are a 2D array with each light in the sequence arranged as{duration, red, green, blue}
. Further documentation can be found here.
- The Speaker:
cubes[i].sound
can be called withsoundeffect, volume
to play sound effects. Further documentation can be found here.cubes[i].midi
can be used to play a certain note withduration, noteID, volume
or to produce an note sequence withrepetitions, notes
wherenote
are a 2D array with each note in the sequence arranged as{duration, noteID, volume}
or{duration, noteID}
. Unless specified,volume = 255
. Further documentation can be found here.
We automatically recieve updates about:
- Position: The values of
cubes[i].x
,cubes[i].y
, andcubes[i].theta
will automatically update to the location and angle of each toio. - Battery: The value of
cubes[i].battery
will automatically update to the battery level of each toio. - Button: The value of
cubes[i].buttonDown
will automatically change on button press of each toio. Changes in this state will also trigger thebuttonDown
andbuttonUp
functions.
We are able to request information from: