Misc

Black/White Processing

Black/White (bw) processing is a firmware function i.e. it operates on the ScratchLink Hardware itself rather than calculated in the browser by Scratch or JavaScipt.

Purpose: To rapidly detect changes between Black/White under the colour sensors to enable rapid halting of the robot and improve response time reactions to lines while moving quickly and thus avoiding “driving through” black lines such as line following or Sumo. Dramatically improves robot reaction time to black lines.

How it works: The values for the “Black” or “White” surface under the colour sensor can be “captured” and used to quickly send a data packet to the browser (over wifi/BT) and additionally the robot can automatically be stopped during when over “Black” while it waits for the data to go up to the browser and instructions to come back (this can take up to 100ms depending on how it is configured).

How to use BW Processing

1. “Scan” either your typical “Black” or “White” surface by the placing eBot’s colour sensors over your surface then call:

bw scan black;  OR  bw scan white;  OR don't call and use default

2. Turn on bw processing and optionally turn on auto stop.

bw [on|off] [on|off];

Examples explained:

bw on on;  // turns on bw processing and autostop on black
bw on off; // turns on bw processing but autostop is off
bw on; // same as "bw on off;"
bw off on; // NOT allowed

3. Utilise returned bw data packets which are put at the front of eBot’s packet que so they get to the browser and your Scratch or JS program as quickly as possible.

Once bw processing is turned on then data packets are automatically generated upon any “state change” of the colour sensors. Returned data packet when bw processing is on:

{BW:[LHS Black?, RHS Black?, Just done autostop?]};
///where data values are 1 for "yes" or 0 for "no" eg.///
{BW:[0,0,0]}; // LHS sees white, RHS sees white, not just done stop
{BW:[1,0,1]}; //LHS sees black, RHS sees white, just done autostop

HTML Commands

There are two commands you can send over the html link to scratchlink

If there is no data you will get an empty packet back ie {} 

/readjson
ie 
http://127.0.0.1:42429/readjson
which will return the latest data from the attached device ie 

{ts:15000,Ultra:[227,200],Analog:[655,0],WiiCC:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]} 

and /readjsonall

which will return all the data packets since the previous readjsonall or readjson.
ie http://127.0.0.1:42429/readjsonall

ts:87600,Ultra:[227,200],Analog:[661,0],WiiCC:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]} {ts:87700,Ultra:[226,200],Analog:[656,0],WiiCC:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]} {ts:87800,Ultra:[227,200],Analog:[639,0],WiiCC:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]} {ts:87900,Ultra:[226,200],Analog:[653,0],WiiCC:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]} 

Note the Wii are now NunC0 and NunC1 or WiiCC0 and WiiCC1eg NunC1:[0,0,0,0,239,81,64]

The i2c color sensor is: RGB0:[50,37,19,209,9,5],RGB1:[513,411,139,967,103,5]

The compass is {cmp:244} being whole numbers from 0 to 360.

Note that matrix get packets will come back between normal data packets in their own packets.

matrix show 0x1000000000000000200000000000000030000000000000004000000000000005;

then 


matrix save; // which will save it as the deault image 0.

Then 

matrix get; // ie get the default one, you could use a number after it

will return 

{mtx:[0,0×1000000000000000200000000000000030000000000000004000000000000005]}

If you are streaming it will come back between two of the stream packets..

For the nunchuck – 

NunC:[0,0,0,0,195,163,91]

where the values are – [joyx, joyy, cbutton, zbutton, gyrox, gyroy, gyroz]

For the classic controller –

WiiCC:[100,78,-100,12,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0]

where the values are –
[left joys x,y,
right joys x,y,
Diamond- Y,A,X,B,
Trigger – LHS top, RHS top, lsh bottom, rhs bottom,
Pad – left,right,up,down,
control – select,home,start]

Joysticks are all scaled -100 to 100.
You must power cycle if swapping between the two controllers (we can change that later if required).

RGB0:[red,green,blue,white,AmbientLight,color_detected]

The light sensor in scratch is taken from “ambientLight”

with color_detected being 0 to 6 meaning:

COLOR_NONE =0;
COLOR_WHITE = 1;
COLOR_RED = 2;
COLOR_GREEN = 3;
COLOR_BLUE = 4;
COLOR_BLACK = 5;
COLOR_SILVER = 6; 

Returned Data

For the nunchuck – 

NunC:[0,0,0,0,195,163,91]

where the values are – [joyx, joyy, cbutton, zbutton, gyrox, gyroy, gyroz]

For the classic controller –

WiiCC:[100,78,-100,12,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0]

where the values are –
[left joys x,y,
right joys x,y,
Diamond- Y,A,X,B,
Trigger – LHS top, RHS top, lsh bottom, rhs bottom,
Pad – left,right,up,down,
control – select,home,start]

Joysticks are all scaled -100 to 100.
You must power cycle if swapping between the two controllers (we can change that later if required).