Before you use Laptop-Toio, you will need to download:
- Processing
- Also make sure to add the
oscP5library 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 -- -swill 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,46will attempt to connect to the toios in the specific order you passed them in. In this case, that would be 48 and then 46
See the following: README_unregistered.md. NOTE: Not intended for students taking classes taught by Professor Ken Nakagaki.
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 processingtab 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 thesetupandloopstructure in arduino
- The
cubetab includes all of the information on theCubestruct which stores most of the values and methods used to communicate with toios - The
eventstab allows you to handle different events from the keyboard, mouse or the toios. - The
motorVelocityTargettab includes the code for thevelocityTargetfunction, which is an advanced function used to travel smoothly over time - The
osctab 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
eventstab is comprised of many functions that are called on certain events.- Keyboard and Mouse events call the
keyPressed,mousePressedandmouseReleasedfunctions. 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,collisionanddoubleTapfunctions. 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, rightSpeedorleftSpeed, 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, thetaorcontrol, 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, targetsorcontrol, timeout, mode, maxspeed, speedchange, targetswhere 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].velocityTargetis a function developed by AxLab to allow toiois to follow a continously moving target. WhenvelocityTargetis called withx, yvalues 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, targetyandtargetTimevariables within theCubeclass.
- The LED Indicator:
cubes[i].ledcan be used to set the LED to a certain color withduration, red, green, blueor to produce an LED sequence withrepetitions, lightswherelightsare 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].soundcan be called withsoundeffect, volumeto play sound effects. Further documentation can be found here.cubes[i].midican be used to play a certain note withduration, noteID, volumeor to produce an note sequence withrepetitions, noteswherenoteare 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].thetawill automatically update to the location and angle of each toio. - Battery: The value of
cubes[i].batterywill automatically update to the battery level of each toio. - Button: The value of
cubes[i].buttonDownwill automatically change on button press of each toio. Changes in this state will also trigger thebuttonDownandbuttonUpfunctions.
We are able to request information from:
