Loading...

Ways to control the T-Bot

  • Android - T-Bot Controller - with automatic reconnection (requires the latest T-Bot.ino)
  • Python - This is the recommended option. The T-Bot Joystick bridge allows you to use a PS3, PS4 or generic wireless controller to control the T-Bot. This works on Linux, Windows and Mac and has been developed on the Raspberry Pi 4.
  • Python - Using the T-Bot Controller for PC included in the downloaded software (Linux, Windows, Mac). This controller allowes you to use your keyboard arrow keys to control the T-Bot. You can also record macros and remotly receive data for plotting.
  • Writing your own Apps

The T-Bot Controller for Android

The simplest way to control your T-Bot is the use the T-Bot Controller.

TBot Android Controller

Connect your android device to you T-Bot

Close Joystick bluetooth Commander and pair your Android device with your T-Bot

Connecting

Open the T-Bot Controller, switch on your T-Bot and press connect. Select your T-Bot from the list. Once connected, the controller will monitor the connection and automatically reconnect if the connection is lost.

T-Bot Controller Screen Shots


Adjusting the Trim
Initially, the most important thing you will have to change on your T-Bot is the trim. Once you're connected to the T-Bot, hold it in the upright position and press the autotrim button (blue icon on the bottom left of the screen). You will see the third value in blue change as the T-Bot auto adjusts its trim. You might have to do this two or three times. You can refine the value using the - and + trim buttons. Once you're happy, you can hard code the trim value into the TBot.ino file. Look for the following lines and set gtrim to the value showing in the Trim datafield (3.0 in the example above). You can now upload the T-Bot.ino code to the T-Bot to make the change persistent.

////////////////////  Speed and Stability tunings   /////////////////////////

float gtrim = -1.25;   // Compensated for drift in forward or reverse direction.

float rtrim = -0.0; // Compensated for rotational drift.



Controlling the T-Bot using Python

Note when you have paired the T-Bot with your computer, the connection will drop. This is normal because the computer doesn't know what to do with it yet.

USB or Wireless to Bluetooth Bridge

The Joystick Bridge allows you to use your computer to convert the USB signal from a PS3 or PS4 controller, or the wireless signal form a generic wireless controller to a Bluetooth signal compatible with the T-Bot. If you prefer to use your PS controller wirelessly, you can follow these instructions for PS3 or these for PS4 to setup the Bluetooth connection (Raspberry Pi).

Wireless to Bluetooth Bridge

Software Dependencies

For Raspberry Pi users. Pair your T-Bot by clicking on the Bluetooth icon and selecting Add Device. Enter 1234 when your T-Bot is found. Type the following in a terminal:

hcitool scan
      Scanning ...
	  98:D3:32:21:3D:77	MazeRunner
	  98:D3:51:FD:81:AC	T-Bot
      

Find the following line in joystick.py and enter your T-Bot's mac address:

else:
        bd_addr = '98:D3:51:FD:81:AC'
        

Now run in the command line using:

python joystick.py
        

Windows or mac users can use the PySerial version: joystick_WinMac.py. There are more instructions for setting up connections in the next section (Python T-Bot Controller).

Note, different controllers may have different button configurations so you might have to update the code to make it compatible with the T-Bot. Even if the configuration different, you will still be able to see which buttons are pressed on the display window.

Python T-Bot Controller

There are three versions of the Python controller bundled with your T-Bot software. The Pybluez and Socket versions are for Linux and the PySerial version is for windows and Mac.

PyBluez Version

You can allow the software to search for your T-Bot or if you know the mac address, you can hard code it in to the software to speed up the connection process.

search = False
bd_addr = '98:D3:32:11:4C:CF' # put the bluetooth address of your T-Bot here.

Then launch a command terminal type the following to launch the Joystick:

python Controller.py



Socket Version

The socket version does not have the search function so you need to know the mac address. This can be stored as a python dictionary in the MAC_Adresses file. Multiple address can be stored if you have more than one T-Bot

{'George': '98:d3:32:11:4c:cf'}

Launch with:

python3 Controller.py

TBot Controller

pySerial Version (Windows 10)

Switch on your T-Bot. Open 'Bluetooth and other device'. Click on 'Add Bluetooth or other devices'. When the dialogue window opens, click on Bluetooth. Your T-Bot should show up as Unknown Device which will change to HC-05 or the name you chose. The PIN is 1234 if you haven't changed it. Now open Control Panel > Hardware and Sound > Devices and Printers. You should now see your T-Bot under Unspecified. Right click and select properties. Click on the Hardware tab. You will see two device functions in the list. The second one will have the port number eg. COM6. Take note of this and edit Controller.py

port = 'COM9'
sock = serial.Serial(port, baudrate)
      

Now launch Controller.py. Spyder is good for this. You might have to run it as administrater.

pySerial Version (Mac)

Install Pygame and pySerial

    sudo easy_install pip
    sudo pip install pygame
    sudo pip install pyserial
      

Open System Preferences > Bluetooth. Pair your T-Bot. Open a terminal and type:

ls /dev/*NameOfYourTbot*
      

The result should look like this:

cu.NameOfYourTbot-DevB	tty.NameOfYourTbot-DevB
      

Now update Controller.py with the port name including the path.

port = '/dev/tty.NameOfYourTbot-DevB'
        sock = serial.Serial(port, baudrate)
      

The key menu will be displayed in the terminal window and will look like this:

-----------------------------------------------------------------
Controls:
Click and drag joystick to drive the T-Bot
Use up, down, left, right arrow keys to drive the T-Bot
Press w or s to change the speed factor for arrow controls.
Click on plot or press c to clear plots
Press q or Esc to quit or Ctrl c in this window

-----------------------------------------------------------------
        

Have fun and feel free to change the code according to your needs.