Used to create calibration data for Barista

Dependencies:   ColorDetectorV2 mbed

Capsule Calibrator

The default mbed Device Server (NSP or mDS) configuration is used by an instance of the web app (Barista) here: http://barista-test.cloudapp.net:4005.

In main.cpp, find the following lines:

/************************
* Modify parameters below
************************/
#define COLOR_SENSOR_SCL I2C_SCL
#define COLOR_SENSOR_SDA I2C_SDA
 
#define NUM_RUNS_PER_CAPSULE 20
#define NUM_CAPSULES 5
 
const char* capsules[] = {
    "decaffeinato_intenso",
    "vivalto_lungo",
    "roma",
    "livanto",
    "arpeggio"
};
 
/************************
* Stop editing here
************************/

Edit COLOR_SENSOR_SCL and COLOR_SENSOR_SDA to the appropriate I2C pins on your mbed platform.

Edit NUM_RUNS_PER_CAPSULE to change the number of repetitions needed per capsule. In general, this should be left at the default to ensure consistent detection.

Edit NUM_CAPSULES to match the number of different types of capsules you wish to detect.

Edit capsules[] to change the types of capsules that you wish to calibrate.

Calibration Process

Compile the project and program your mbed.

Open up a serial terminal (like PuTTY). Configure the serial connection for your mbed's serial port and set the baud rate to 115200.

Also, configure your terminal to log all of the output to a file.

Open the connection and reset your mbed.

You will now be prompted to push your first capsule through the sensor. Choose the correct capsule based on the last name printed to the console. When you have completed all of the repetitions for a particular capsule, it will print out the name of the next capsule. Proceed to push this capsule through the sensor to continue the calibration process. Repeat this until no more capsule names are printed to the terminal.

Close your terminal.

Preparing the Calibration File

Open the log file that your terminal created. Some terminal programs (including PuTTY) print extra information at the top of the file. Remove this now. The first line should read:

module.exports = {

Save and rename the file to all-data.js.

Uploading the Calibration File

Now that the calibration file has been prepared, you need to upload it to your instance of Barista. Copy and replace /classification/all-data.js in your Barista installation. When this is done, restart Barista for the changes to take effect.

Committer:
bridadan
Date:
Thu Jul 16 18:37:29 2015 +0000
Revision:
3:e9b7dd919530
Parent:
2:0916f1a0f6a2
Updating ColorDetectorV2 (defaulting to 3.3v devices)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bridadan 0:94990f7d44d2 1 #include "mbed.h"
bridadan 0:94990f7d44d2 2 #include "GroveColourSensor.h"
bridadan 0:94990f7d44d2 3 #include "ColorDetector.h"
bridadan 0:94990f7d44d2 4
bridadan 0:94990f7d44d2 5 /************************
bridadan 0:94990f7d44d2 6 * Modify parameters below
bridadan 0:94990f7d44d2 7 ************************/
bridadan 0:94990f7d44d2 8 #define COLOR_SENSOR_SCL I2C_SCL
bridadan 0:94990f7d44d2 9 #define COLOR_SENSOR_SDA I2C_SDA
bridadan 0:94990f7d44d2 10 #define COLOR_SENSOR_PR A0
bridadan 0:94990f7d44d2 11
bridadan 0:94990f7d44d2 12 #define NUM_RUNS_PER_CAPSULE 20
bridadan 0:94990f7d44d2 13 #define NUM_CAPSULES 5
bridadan 0:94990f7d44d2 14
bridadan 0:94990f7d44d2 15 const char* capsules[] = {
bridadan 0:94990f7d44d2 16 "decaffeinato_intenso",
bridadan 0:94990f7d44d2 17 "vivalto_lungo",
bridadan 0:94990f7d44d2 18 "roma",
bridadan 0:94990f7d44d2 19 "livanto",
bridadan 0:94990f7d44d2 20 "arpeggio"
bridadan 0:94990f7d44d2 21 };
bridadan 0:94990f7d44d2 22
bridadan 0:94990f7d44d2 23 /************************
bridadan 0:94990f7d44d2 24 * Stop editing here
bridadan 0:94990f7d44d2 25 ************************/
bridadan 0:94990f7d44d2 26
bridadan 0:94990f7d44d2 27 Serial pc(USBTX, USBRX);
bridadan 0:94990f7d44d2 28
bridadan 0:94990f7d44d2 29 int main()
bridadan 0:94990f7d44d2 30 {
bridadan 0:94990f7d44d2 31 // Gotta speed up the terminal, otherwise takes forever to print samples
bridadan 0:94990f7d44d2 32 pc.baud(115200);
bridadan 0:94990f7d44d2 33
bridadan 0:94990f7d44d2 34 DigitalOut scl_dummy(I2C_SCL);
bridadan 0:94990f7d44d2 35
bridadan 0:94990f7d44d2 36 // Ensure I2C bus is released by toggling clock (fixes reset errors)
bridadan 0:94990f7d44d2 37 for (int i = 0; i < 100; i++) {
bridadan 0:94990f7d44d2 38 scl_dummy = !scl_dummy;
bridadan 0:94990f7d44d2 39 wait_us(2);
bridadan 0:94990f7d44d2 40 }
bridadan 0:94990f7d44d2 41
bridadan 0:94990f7d44d2 42 I2C i2c(COLOR_SENSOR_SDA, COLOR_SENSOR_SCL);
bridadan 0:94990f7d44d2 43
bridadan 0:94990f7d44d2 44 GroveColourSensor colorSensor(&i2c);
bridadan 0:94990f7d44d2 45
bridadan 0:94990f7d44d2 46 colorSensor.powerUp();
bridadan 2:0916f1a0f6a2 47 colorSensor.setGain(3);
bridadan 0:94990f7d44d2 48 colorSensor.setBlockRead();
bridadan 0:94990f7d44d2 49
bridadan 0:94990f7d44d2 50 ColorDetector detector(&colorSensor, COLOR_SENSOR_PR);
bridadan 0:94990f7d44d2 51
bridadan 0:94990f7d44d2 52 int runCount, sampleCount;
bridadan 0:94990f7d44d2 53 RGBC *buf = detector.getBuffer();
bridadan 0:94990f7d44d2 54
bridadan 0:94990f7d44d2 55 pc.printf("module.exports = {\r\n");
bridadan 0:94990f7d44d2 56
bridadan 0:94990f7d44d2 57 for (int i = 0; i < NUM_CAPSULES; i++) {
bridadan 0:94990f7d44d2 58 pc.printf("\t\"%s\": [\r\n", capsules[i]);
bridadan 0:94990f7d44d2 59
bridadan 0:94990f7d44d2 60 runCount = 0;
bridadan 0:94990f7d44d2 61
bridadan 0:94990f7d44d2 62 while (runCount < NUM_RUNS_PER_CAPSULE) {
bridadan 0:94990f7d44d2 63 sampleCount = detector.sample();
bridadan 0:94990f7d44d2 64 wait(0.001);
bridadan 0:94990f7d44d2 65 if (sampleCount > 0) {
bridadan 0:94990f7d44d2 66 pc.printf("\t\t[\r\n");
bridadan 0:94990f7d44d2 67
bridadan 0:94990f7d44d2 68 for (int j = 0; j < sampleCount; j++) {
bridadan 0:94990f7d44d2 69 pc.printf("\t\t\t[%u, %u, %u]", buf[j].ch.red, buf[j].ch.green, buf[j].ch.blue);
bridadan 0:94990f7d44d2 70
bridadan 0:94990f7d44d2 71 if (j < sampleCount - 1) {
bridadan 0:94990f7d44d2 72 pc.printf(",");
bridadan 0:94990f7d44d2 73 }
bridadan 0:94990f7d44d2 74
bridadan 0:94990f7d44d2 75 pc.printf("\r\n");
bridadan 0:94990f7d44d2 76 }
bridadan 0:94990f7d44d2 77
bridadan 0:94990f7d44d2 78 pc.printf("\t\t]");
bridadan 0:94990f7d44d2 79
bridadan 0:94990f7d44d2 80 if (runCount < NUM_RUNS_PER_CAPSULE - 1) {
bridadan 0:94990f7d44d2 81 pc.printf(",");
bridadan 0:94990f7d44d2 82 }
bridadan 0:94990f7d44d2 83
bridadan 0:94990f7d44d2 84 pc.printf(" // %d, %d samples taken\r\n", runCount, sampleCount);
bridadan 0:94990f7d44d2 85 runCount++;
bridadan 0:94990f7d44d2 86 }
bridadan 0:94990f7d44d2 87 }
bridadan 0:94990f7d44d2 88
bridadan 0:94990f7d44d2 89 pc.printf("\t]");
bridadan 0:94990f7d44d2 90
bridadan 0:94990f7d44d2 91 if (i < NUM_CAPSULES - 1) {
bridadan 0:94990f7d44d2 92 pc.printf(",");
bridadan 0:94990f7d44d2 93 }
bridadan 0:94990f7d44d2 94
bridadan 0:94990f7d44d2 95 pc.printf(" // %s\r\n", capsules[i]);
bridadan 0:94990f7d44d2 96 }
bridadan 0:94990f7d44d2 97
bridadan 0:94990f7d44d2 98 pc.printf("};");
bridadan 0:94990f7d44d2 99
bridadan 0:94990f7d44d2 100 return 0;
bridadan 0:94990f7d44d2 101 }