Close

Yet a few more findings and how the "advanced coding" mode works (part 1)

A project log for Custom control app for Mind Designer Robot

This project is about reverse-engineering the BLE communications protocol and getting a custom app working

adriajunyent-ferreadria.junyent-ferre 12/29/2019 at 14:050 Comments

I captured a further log, this time I tried to define a loop in the advanced coding mode and I also captured the log from drawing something using the freehand mode.

The bad news are that the freehand mode uses exactly the same sequence definition as the basic coding mode, which means that it isn't possible to request turning angles that aren't integer degrees of turn and it isn't possible to request displacements that aren't integer number of centimetres.

The good news are that loops are indeed defined as loops and they aren't unrolled by the app. The beginning of the loop is marked by a command that defines how many times the loop will be played and the end of the loop is marked by another special command. For example, the following sequence of commands draws an equilateral triangle:

1100 # start the definition of a sequence of movements

0700 0003 # start the definition of a loop to be repeated three times

0001 0005 # move forward by 5 cm

0004 0120 # turn to the right by 120 degrees

0701 # end the definition of the loop

1101 # end the definition of the sequence and start the motion

Testing all this from nRF Connect would be quite tedious, therefore I started using a few other tools on my laptop.

The first one I tried was the gatttool in interactive mode, that allows you to manually write to the characteristics of the BLE service and do more or less the same I was doing using nRF Connect. The use of the tool is pretty straightforward and there are plenty of usage examples online (for example).  The tool can be used in non-interactive mode to send commands from the terminal. The issue with this method, though is that a single execution of gatttool will open a BLE connection, write to the characteristic and close the connection. This causes the Mind Designer Robot to stop doing whatever it has been asked to do. Consequently, I recommend using gatttool just for debugging things manually.

The other thing I tried was the bluepy library in Python. This library is pretty straightforward to use, it has functions to list the services offered by any BLE device and it can also read and write to any characteristic. I started writing a very  basic script to test if the process would work:

#!/usr/bin/env python

from bluepy import btle
import time
 
dev = btle.Peripheral("18:7A:93:16:82:1B")
time.sleep(0.5)

dev.writeCharacteristic(0x003d,"1000")
time.sleep(0.2)

dev.writeCharacteristic(0x003d,"1100")
time.sleep(0.1)
dev.writeCharacteristic(0x003d,"0001 0005")
time.sleep(0.1)
dev.writeCharacteristic(0x003d,"0003 0090")
time.sleep(0.1)
dev.writeCharacteristic(0x003d,"1101")

time.sleep(50)
dev.disconnect() 

This code defines a simple sequence where the robot moves forward by 5 cm and then turns to the right by 90 degrees. Sleep intervals of 100 ms are introduced every time a command is sent to the robot. I haven't tested if these delays are required but I see no reason to speed up the process of sending the commands to the robot and this is more or less what I saw the Android app doing.

That's it for this update. I've posted a slightly more intricate script that draws a five pointed star using a sequence with a loop. The python script can be found in the downloads section of the project page.

I want to carry out a few further tests to see if the definition of multiple loops within a sequence makes any difference but I'm not sure what the next steps will be.

Once again, stay tuned for more updates!

Discussions