Popravki senzor kode, sprejemnika in monitor skripte

main
Jurij Podgoršek 2024-09-26 15:49:08 +02:00
parent e9df3c13ae
commit a78110dc80
5 changed files with 609 additions and 211 deletions

View File

@ -3,5 +3,6 @@
source .venv/bin/activate source .venv/bin/activate
port=${1:-/dev/ttyACM0} port=${1:-/dev/ttyACM0}
rate=${2:-230400}
pio device monitor -b 115200 -p "$port" pio device monitor -b "$rate" -p "$port"

View File

@ -39,12 +39,10 @@
// id, address // id, address
Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28); Adafruit_BNO055 bno = Adafruit_BNO055(55, 0x28);
/**************************************************************************/ /************************************************************************
/* * Displays some basic information on this sensor from the unified *
Displays some basic information on this sensor from the unified * sensor API sensor_t type (see Adafruit_Sensor for more information) *
sensor API sensor_t type (see Adafruit_Sensor for more information) ***********************************************************************/
*/
/**************************************************************************/
void displaySensorDetails(void) void displaySensorDetails(void)
{ {
sensor_t sensor; sensor_t sensor;
@ -61,13 +59,10 @@ void displaySensorDetails(void)
delay(500); delay(500);
} }
/**************************************************************************/ /****************************************************
/* * Display some basic info about the sensor status *
Display some basic info about the sensor status ***************************************************/
*/ void displaySensorStatus(void) {
/**************************************************************************/
void displaySensorStatus(void)
{
/* Get the system status values (mostly for debugging purposes) */ /* Get the system status values (mostly for debugging purposes) */
uint8_t system_status, self_test_results, system_error; uint8_t system_status, self_test_results, system_error;
system_status = self_test_results = system_error = 0; system_status = self_test_results = system_error = 0;
@ -85,13 +80,10 @@ void displaySensorStatus(void)
delay(500); delay(500);
} }
/**************************************************************************/ /*************************************
/* * Display sensor calibration status *
Display sensor calibration status *************************************/
*/ void displayCalStatus(void) {
/**************************************************************************/
void displayCalStatus(void)
{
/* Get the four calibration values (0..3) */ /* Get the four calibration values (0..3) */
/* Any sensor data reporting 0 should be ignored, */ /* Any sensor data reporting 0 should be ignored, */
/* 3 means 'fully calibrated" */ /* 3 means 'fully calibrated" */
@ -101,8 +93,7 @@ void displayCalStatus(void)
/* The data should be ignored until the system calibration is > 0 */ /* The data should be ignored until the system calibration is > 0 */
Serial.print("\t"); Serial.print("\t");
if (!system) if (!system) {
{
Serial.print("! "); Serial.print("! ");
} }
@ -155,62 +146,35 @@ void displaySensorOffsets(const adafruit_bno055_offsets_t &calibData)
int eeprom_size; int eeprom_size;
void setup(void) void setup(void) {
{
Serial.begin(115200); Serial.begin(115200);
delay(8000); delay(8000);
Serial.println("Orientation Sensor Test"); Serial.println(""); Serial.println("Orientation Sensor Test"); Serial.println("");
/* Initialise the sensor */ /* Initialise the sensor */
if (!bno.begin()) if (!bno.begin()) {
{
/* There was a problem detecting the BNO055 ... check your connections */ /* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while (1); while (1);
} }
// EEPROM init // EEPROM init
eeprom_size = sizeof(long) + sizeof(adafruit_bno055_offsets_t); eeprom_size = sizeof(adafruit_bno055_offsets_t);
EEPROM.begin(eeprom_size); EEPROM.begin(eeprom_size);
Serial.print("EEPROM init (len "); Serial.print("EEPROM init (len ");
Serial.print(EEPROM.length()); Serial.print(EEPROM.length());
Serial.println(")\n"); Serial.println(")\n");
int eeAddress = 0;
long bnoID;
bool foundCalib = false;
EEPROM.get(eeAddress, bnoID);
adafruit_bno055_offsets_t calibrationData; adafruit_bno055_offsets_t calibrationData;
sensor_t sensor; sensor_t sensor;
/*
* Look for the sensor's unique ID at the beginning oF EEPROM.
* This isn't foolproof, but it's better than nothing.
*/
bno.getSensor(&sensor); bno.getSensor(&sensor);
if (bnoID != sensor.sensor_id) EEPROM.get(0, calibrationData);
{
Serial.println("\nNo Calibration Data for this sensor exists in EEPROM");
delay(500);
}
else
{
Serial.println("\nFound Calibration for this sensor in EEPROM.");
eeAddress += sizeof(long);
EEPROM.get(eeAddress, calibrationData);
Serial.println("\n\nCalibration data in EEPROM");
displaySensorOffsets(calibrationData); displaySensorOffsets(calibrationData);
Serial.println("\n\nRestoring Calibration data to the BNO055...");
bno.setSensorOffsets(calibrationData);
Serial.println("\n\nCalibration data loaded into BNO055");
foundCalib = true;
}
delay(1000); delay(1000);
/* Display some basic information on this sensor */ /* Display some basic information on this sensor */
@ -224,20 +188,9 @@ void setup(void)
sensors_event_t event; sensors_event_t event;
bno.getEvent(&event); bno.getEvent(&event);
/* always recal the mag as It goes out of calibration very often */
if (foundCalib){
Serial.println("Move sensor slightly to calibrate magnetometers");
while (!bno.isFullyCalibrated())
{
bno.getEvent(&event);
delay(BNO055_SAMPLERATE_DELAY_MS);
}
}
else
{
Serial.println("Please Calibrate Sensor: "); Serial.println("Please Calibrate Sensor: ");
while (!bno.isFullyCalibrated()) while (!bno.isFullyCalibrated()) {
{
bno.getEvent(&event); bno.getEvent(&event);
Serial.print("X: "); Serial.print("X: ");
@ -256,7 +209,6 @@ void setup(void)
/* Wait the specified delay before requesting new data */ /* Wait the specified delay before requesting new data */
delay(BNO055_SAMPLERATE_DELAY_MS); delay(BNO055_SAMPLERATE_DELAY_MS);
} }
}
Serial.println("\nFully calibrated!"); Serial.println("\nFully calibrated!");
Serial.println("--------------------------------"); Serial.println("--------------------------------");
@ -267,14 +219,7 @@ void setup(void)
Serial.println("\n\nStoring calibration data to EEPROM..."); Serial.println("\n\nStoring calibration data to EEPROM...");
eeAddress = 0; EEPROM.put(0, newCalib);
bno.getSensor(&sensor);
bnoID = sensor.sensor_id;
EEPROM.put(eeAddress, bnoID);
eeAddress += sizeof(long);
EEPROM.put(eeAddress, newCalib);
EEPROM.commit(); EEPROM.commit();
Serial.println("Data stored to EEPROM."); Serial.println("Data stored to EEPROM.");

View File

@ -4,7 +4,7 @@
#include <EEPROM.h> #include <EEPROM.h>
// ID senzorja mora bit unikaten! (se poslje poleg parametrov) // ID senzorja mora bit unikaten! (se poslje poleg parametrov)
#define SENSOR_ID 6 #define SENSOR_ID 7
// Stanje baterije // Stanje baterije
#define BATTERY_PIN 2 #define BATTERY_PIN 2
@ -17,7 +17,7 @@
#define LED_PIN 17 #define LED_PIN 17
// debagiranje! // debagiranje!
//#define DEBUG #define DEBUG
// I²C pins // I²C pins
#define SDA_PIN 8 #define SDA_PIN 8
@ -34,8 +34,15 @@
#include <esp_now.h> #include <esp_now.h>
#include <WiFi.h> #include <WiFi.h>
// MAC naslov laptopa (linux sprejemnik)
//uint8_t sprejemnikMac[] = { 0x9c, 0xb6, 0xd0, 0xc4, 0xe8, 0xb9 };
// MAC naslov sprejemnika // MAC naslov sprejemnika
uint8_t sprejemnikMac[] = { 0x08, 0x3A, 0xF2, 0x50, 0xEF, 0x6C }; uint8_t sprejemnikMac[] = { 0x08, 0x3A, 0xF2, 0x50, 0xEF, 0x6C };
// MAC naslov sprejemnika2: 08:3A:F2:50:EF:6D
//uint8_t sprejemnikMac[] = {0x08, 0x3A, 0xF2, 0x50, 0xEF, 0x6D};
// wifi kanal
#define KANAL 1
// Comp // Comp
sensor_msg odcitek; sensor_msg odcitek;
@ -48,12 +55,11 @@ sensor_t ensor;
imu::Quaternion quat; imu::Quaternion quat;
imu::Vector<3> linearAccel; imu::Vector<3> linearAccel;
int cas = 0; unsigned long cas_bat = 0;
unsigned long cas_uspeh = 0;
// EEPROM za kalibracijo // EEPROM za kalibracijo
int eeprom_size; int eeprom_size;
/* Set the delay between fresh samples (calibration) */
#define BNO055_SAMPLERATE_DELAY_MS (100)
void error_blink() { void error_blink() {
while(1) { while(1) {
@ -65,6 +71,9 @@ void error_blink() {
} }
void setup() { void setup() {
// Nizja CPU frekvenca - je dovolj (za stevilo wifi paketov - ~100 na sekundo)!
//setCpuFrequencyMhz(160);
// Basic(debug) serial init // Basic(debug) serial init
Serial.begin(115200); // set this as high as you can reliably run on your platform Serial.begin(115200); // set this as high as you can reliably run on your platform
Serial.println("Starting up..."); Serial.println("Starting up...");
@ -76,26 +85,34 @@ void setup() {
// Init - 3 one second blinks // Init - 3 one second blinks
pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT);
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
#ifdef DEBUG
Serial.println(i + 1); Serial.println(i + 1);
#endif
digitalWrite(LED_PIN, LOW); digitalWrite(LED_PIN, LOW);
delay(500); delay(500);
digitalWrite(LED_PIN, HIGH); digitalWrite(LED_PIN, HIGH);
delay(500); delay(500);
} }
digitalWrite(LED_PIN, LOW);
// WIFI init // WIFI init
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) { if (esp_now_init() != ESP_OK) {
#ifdef DEBUG
Serial.println("Error initializing ESP-NOW"); Serial.println("Error initializing ESP-NOW");
#endif
error_blink(); error_blink();
} }
memcpy(peerInfo.peer_addr, sprejemnikMac, 6); memcpy(peerInfo.peer_addr, sprejemnikMac, 6);
peerInfo.channel = 0; peerInfo.channel = KANAL;
peerInfo.encrypt = false; peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK){ if (esp_now_add_peer(&peerInfo) != ESP_OK){
#ifdef DEBUG
Serial.println("WIFI registracija ni uspela"); Serial.println("WIFI registracija ni uspela");
#endif
error_blink(); error_blink();
} }
@ -103,23 +120,20 @@ void setup() {
if (!bno.begin(OPERATION_MODE_NDOF)) { if (!bno.begin(OPERATION_MODE_NDOF)) {
/* There was a problem detecting the BNO055 ... check your connections */ /* There was a problem detecting the BNO055 ... check your connections */
#ifdef DEBUG
Serial.println("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!"); Serial.println("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
#endif
error_blink(); error_blink();
} }
// EEPROM init // EEPROM init
eeprom_size = sizeof(long) + sizeof(adafruit_bno055_offsets_t); eeprom_size = sizeof(long) + sizeof(adafruit_bno055_offsets_t);
EEPROM.begin(eeprom_size); EEPROM.begin(eeprom_size);
#ifdef DEBUG
Serial.print("EEPROM init (len "); Serial.print("EEPROM init (len ");
Serial.print(EEPROM.length()); Serial.print(EEPROM.length());
Serial.println(")\n"); Serial.println(")\n");
#endif
// Fetch calibration
int eeAddress = 0;
long bnoID;
bool foundCalib = false;
EEPROM.get(eeAddress, bnoID);
adafruit_bno055_offsets_t calibrationData; adafruit_bno055_offsets_t calibrationData;
sensor_t sensor; sensor_t sensor;
@ -129,25 +143,23 @@ void setup() {
* This isn't foolproof, but it's better than nothing. * This isn't foolproof, but it's better than nothing.
*/ */
bno.getSensor(&sensor); bno.getSensor(&sensor);
if (bnoID != sensor.sensor_id) { EEPROM.get(0, calibrationData);
Serial.println("\nNo Calibration Data for this sensor exists in EEPROM");
delay(500);
} else {
Serial.println("\nFound Calibration for this sensor in EEPROM.");
eeAddress += sizeof(long);
EEPROM.get(eeAddress, calibrationData);
#ifdef DEBUG
Serial.println("\n\nRestoring Calibration data to the BNO055..."); Serial.println("\n\nRestoring Calibration data to the BNO055...");
#endif
bno.setSensorOffsets(calibrationData); bno.setSensorOffsets(calibrationData);
#ifdef DEBUG
Serial.println("\n\nCalibration data loaded into BNO055"); Serial.println("\n\nCalibration data loaded into BNO055");
} #endif
delay(1000); delay(1000);
/* Use external crystal for better accuracy? */ /* Use external crystal for better accuracy? */
/* Crystal must be configured AFTER loading calibration data into BNO055. */ /* Crystal must be configured AFTER loading calibration data into BNO055. */
bno.setExtCrystalUse(true); bno.setExtCrystalUse(true);
//bno.setExtCrystalUse(false);
delay(1000); delay(1000);
@ -155,16 +167,22 @@ void setup() {
bno.getEvent(&event); bno.getEvent(&event);
/* always recal the mag as It goes out of calibration very often */ /* always recal the mag as It goes out of calibration very often */
if (foundCalib){ /*
Serial.println("Move sensor slightly to calibrate magnetometers");
while (!bno.isFullyCalibrated()) { while (!bno.isFullyCalibrated()) {
bno.getEvent(&event); bno.getEvent(&event);
delay(BNO055_SAMPLERATE_DELAY_MS); delay(100);
} #ifdef DEBUG
Serial.println("Calibrating...");
#endif
} }
delay(1000); delay(1000);
#ifdef DEBUG
Serial.println("Calibrated!");
#endif
*/
/* Change mode to sensor fusion */ /* Change mode to sensor fusion */
bno.setMode(OPERATION_MODE_NDOF); bno.setMode(OPERATION_MODE_NDOF);
@ -177,12 +195,11 @@ void setup() {
odcitek.id = SENSOR_ID; odcitek.id = SENSOR_ID;
// Initial time // Initial time
cas = millis(); cas_bat = millis();
} }
// Read battery (from example T7 sketch) // Read battery (from example T7 sketch)
uint32_t readADC_Cal(int ADC_Raw) uint32_t readADC_Cal(int ADC_Raw) {
{
esp_adc_cal_characteristics_t adc_chars; esp_adc_cal_characteristics_t adc_chars;
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, 1100, &adc_chars); esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_DB_11, ADC_WIDTH_BIT_12, 1100, &adc_chars);
@ -190,9 +207,27 @@ uint32_t readADC_Cal(int ADC_Raw)
} }
void loop() { void loop() {
/* Get a new sensor event */ // Get linear acceleration (3 * 2bytes)
//sensors_event_t event; linearAccel = bno.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
//bno.getEvent(&event); if (abs(linearAccel.x()) > abs(odcitek.aX)) {
odcitek.aX = linearAccel.x();
}
if (abs(linearAccel.y()) > abs(odcitek.aY)) {
odcitek.aY = linearAccel.y();
}
if (abs(linearAccel.z()) > abs(odcitek.aZ)) {
odcitek.aZ = linearAccel.z();
}
// Najvec 1 na sekundo
if ((millis() - cas_uspeh) < 9) {
delay(1);
#ifdef DEBUG
Serial.println("preskocim..");
#endif
return;
}
// Get quat (fusion mode); 4 * 2bytes // Get quat (fusion mode); 4 * 2bytes
quat = bno.getQuat(); quat = bno.getQuat();
@ -213,21 +248,6 @@ void loop() {
Serial.println(""); Serial.println("");
#endif #endif
// Each second, read the battery
// @TODO use something more precise, like https://github.com/rlogiacco/BatterySense ?
if (millis() - cas > 1000) {
cas = millis();
odcitek.bat = (float) (readADC_Cal(analogRead(BATTERY_PIN)) * 2) / 1000;
}
// Get linear acceleration (3 * 2bytes)
linearAccel = bno.getVector(Adafruit_BNO055::VECTOR_LINEARACCEL);
odcitek.aX = linearAccel.x();
odcitek.aY = linearAccel.y();
odcitek.aZ = linearAccel.z();
#ifdef DEBUG #ifdef DEBUG
Serial.print(F("Linear acceleration: ")); Serial.print(F("Linear acceleration: "));
Serial.print((float)odcitek.aX); Serial.print((float)odcitek.aX);
@ -239,14 +259,28 @@ void loop() {
#endif #endif
// Each second, read the battery
// @TODO use something more precise, like https://github.com/rlogiacco/BatterySense ?
if (millis() - cas_bat > 1000) {
cas_bat = millis();
odcitek.bat = (float) (readADC_Cal(analogRead(BATTERY_PIN)) * 2) / 1000;
}
esp_err_t result = esp_now_send(sprejemnikMac, (uint8_t *) &odcitek, sizeof(odcitek)); esp_err_t result = esp_now_send(sprejemnikMac, (uint8_t *) &odcitek, sizeof(odcitek));
#ifdef DEBUG
if (result == ESP_OK) { if (result == ESP_OK) {
#ifdef DEBUG
Serial.println("Uspesno poslano"); Serial.println("Uspesno poslano");
#endif
cas_uspeh = millis();
odcitek.aX = 0;
odcitek.aY = 0;
odcitek.aZ = 0;
} else { } else {
Serial.println("Napaka pri posiljanju"); #ifdef DEBUG
} Serial.print("Napaka pri posiljanju (");
Serial.print(esp_err_to_name(result));
Serial.println(")");
#endif #endif
} }
}

View File

@ -21,6 +21,9 @@ SLIPEncodedUSBSerial SLIPSerial(Serial);
// MAC naslov sprejemnika: 08:3A:F2:50:EF:6C // MAC naslov sprejemnika: 08:3A:F2:50:EF:6C
uint8_t newMACAddress[] = {0x08, 0x3A, 0xF2, 0x50, 0xEF, 0x6C}; uint8_t newMACAddress[] = {0x08, 0x3A, 0xF2, 0x50, 0xEF, 0x6C};
// MAC naslov laptopa (linux sprejemnik)
//uint8_t newMACAddress[] = { 0x9c, 0xb6, 0xd0, 0xc4, 0xe8, 0xb9 };
// Maksimalno stevilo // Maksimalno stevilo
#define ST_SPREJEMNIKOV 10 #define ST_SPREJEMNIKOV 10
@ -65,7 +68,7 @@ void prejemPodatkov(const uint8_t * mac_addr, const uint8_t * noviPodatki, int l
void setup() { void setup() {
// Nizja CPU frekvenca // Nizja CPU frekvenca
//setCpuFrequencyMhz(80); setCpuFrequencyMhz(160);
//SLIPSerial.begin(115200); //SLIPSerial.begin(115200);
SLIPSerial.begin(230400); SLIPSerial.begin(230400);

View File

@ -0,0 +1,415 @@
/************************
* MIDI / OSC MAPIRANJE *
***********************/
NetAddr.langPort;
/***********************************
* OSC MAPPING: Povezava na simona *
**********************************/
(
~simonIP = "10.42.1.2";
~oscS = NetAddr.new(~simonIP, 57120);
OSCFunc.trace(true); // debug osc
OSCFunc.trace(false); // debug osc
~senzorji.keys.do({ |id|
~senzorji[id].postln;
OSCdef.new((\accOSC ++ id).asSymbol, { |msg, time, addr, recvPort|
~oscS.sendMsg("/senzor/" ++ id ++ "/accX", msg[1].linlin(-50, 50, 0, 1));
~oscS.sendMsg("/senzor/" ++ id ++ "/accY", msg[2].linlin(-50, 50, 0, 1));
~oscS.sendMsg("/senzor/" ++ id ++ "/accZ", msg[3].linlin(-50, 50, 0, 1));
~oscS.sendMsg("/senzor/" ++ id ++ "/accSum", msg[4].linlin(-50, 50, 0, 1));
}, "/acc/" ++ id);
OSCdef.new((\eulerOSC ++ id).asSymbol, { |msg, time, addr, recvPort|
var pitch, roll, yaw;
// vrtenje sinusoidiziramo, da ni preskokov
pitch = msg[1].sin.linlin(-pi, pi, 0, 1);
roll = msg[2].sin.linlin(-pi, pi, 0, 1);
yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
//[pitch, roll, yaw].postln;
~oscS.sendMsg("/senzor/" ++ id ++ "/pitch", pitch);
~oscS.sendMsg("/senzor/" ++ id ++ "/roll", roll);
~oscS.sendMsg("/senzor/" ++ id ++ "/yaw", yaw);
//["simon", pitch, roll, yaw].postln;
}, "/euler/" ++ id);
});
)
/************************************
* MIDI MAPPING: Povezava na boruta *
***********************************/
// Midi mapping funkcija
(
~midiVals = Dictionary.new;
~sendMidi = { | chan=0, cc=0, val=0 |
var key = chan.asString ++ "_" ++ cc, v = val;
v = val.floor.clip(0, 127);
if ((~midiVals[key] == nil) || (~midiVals[key] != val)) {
~midiVals[key] = val;
~midi.control(chan, cc, val);
["midi " ++ ~map, chan, cc, v].postln;
};
};
)
// MIDI MAP I
(
"MIDI MAP I !!!".postln;
~map = "I";
~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
var pitch, roll, yaw, freq, gain;
// vrtenje sinusoidiziramo, da ni preskokov
pitch = msg[1].sin.linlin(-pi, pi, 0, 1);
roll = msg[2].sin.linlin(-pi, pi, 0, 1);
yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
// quick 16 (1) = frekvenca, quick 17 (2) = gain
switch (id,
4, {
freq = roll;
// Quick slots 1-3
~sendMidi.value(0, 16, freq * 127);
},
1, {
gain = yaw;
if (gain <= 0.5, {
gain = 0.5 - gain;
}, {
gain = gain - 0.5;
});
~sendMidi.value(0, 17, 64 + (gain * 127));
}
);
}, "/euler/" ++ id);
OSCdef.new((\accMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
// Pospeski: gremo od 0 ali iz sredine?
var accX, accY, accZ, accSum;
accX = msg[1].linlin(-50, 50, 0, 1);
accY = msg[2].linlin(-50, 50, 0, 1);
accZ = msg[3].linlin(-50, 50, 0, 1);
accSum = msg[4].linlin(-50, 50, 0, 1);
/*
switch (id,
3, {
~sendMidi.value(0, 19, (accX * 127).floor);
~sendMidi.value(0, 20, (accY * 127).floor);
~sendMidi.value(0, 21, (accZ * 127).floor);
}
);
*/
}, "/acc/" ++ id);
});
)
// MIDI MAP II
(
~map = "II";
"MIDI MAP II !!!".postln;
~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
var pitch, roll, yaw;
// vrtenje sinusoidiziramo, da ni preskokov
pitch = msg[1].sin.linlin(-pi, pi, 0, 1);
roll = msg[2].sin.linlin(-pi, pi, 0, 1);
yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
// MORPHING EFEKT
switch (id,
4, {
// Quick slots 1-3
~sendMidi.value(0, 16, (-20 + (yaw * 150)).floor);
},
3, {
~sendMidi.value(0, 17, (-20 + (roll * 150).floor));
}
);
}, "/euler/" ++ id);
OSCdef.new((\accMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
// Pospeski: gremo od 0 ali iz sredine?
var accX, accY, accZ, accSum;
accX = msg[1].linlin(-50, 50, 0, 1);
accY = msg[2].linlin(-50, 50, 0, 1);
accZ = msg[3].linlin(-50, 50, 0, 1);
accSum = msg[4].linlin(-50, 50, 0, 1);
/*
switch (id,
3, {
~sendMidi.value(0, 19, (accX * 127).floor);
~sendMidi.value(0, 20, (accY * 127).floor);
~sendMidi.value(0, 21, (accZ * 127).floor);
}
);
*/
}, "/acc/" ++ id);
});
)
// MIDI MAP III
(
"MIDI MAP III !!!".postln;
~map = "III";
~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
var pitch, roll, yaw;
// vrtenje sinusoidiziramo, da ni preskokov
pitch = msg[1].sin.linlin(-pi, pi, 0, 1);
roll = msg[2].sin.linlin(-pi, pi, 0, 1);
yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
switch (id,
3, {
// Quick slots 1-3
~sendMidi.value(0, 16, (pitch * 127));
},
4, {
~sendMidi.value(0, 17, (pitch * 127));
}
);
}, "/euler/" ++ id);
OSCdef.new((\accMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
// Pospeski: gremo od 0 ali iz sredine?
var accX, accY, accZ, accSum;
accX = msg[1].linlin(-50, 50, 0, 1);
accY = msg[2].linlin(-50, 50, 0, 1);
accZ = msg[3].linlin(-50, 50, 0, 1);
accSum = msg[4].linlin(-50, 50, 0, 1);
accSum = accSum - 0.5;
switch (id,
4, {
~sendMidi.value(0, 18, (accSum * 256).floor);
}
);
}, "/acc/" ++ id);
});
)
// MIDI MAP IV (II)
(
~map = "IV";
"MIDI MAP IV (II) !!!".postln;
~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
var pitch, roll, yaw;
// vrtenje sinusoidiziramo, da ni preskokov
pitch = msg[1].sin.linlin(-pi, pi, 0, 1);
roll = msg[2].sin.linlin(-pi, pi, 0, 1);
yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
// MORPHING EFEKT
switch (id,
4, {
// Quick slots 1-3
~sendMidi.value(0, 16, (-15 + (yaw * 150)).floor);
},
3, {
~sendMidi.value(0, 17, (-15 + (roll * 150).floor));
}
);
}, "/euler/" ++ id);
OSCdef.new((\accMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
// Pospeski: gremo od 0 ali iz sredine?
var accX, accY, accZ, accSum;
accX = msg[1].linlin(-50, 50, 0, 1);
accY = msg[2].linlin(-50, 50, 0, 1);
accZ = msg[3].linlin(-50, 50, 0, 1);
accSum = msg[4].linlin(-50, 50, 0, 1);
/*
switch (id,
3, {
~sendMidi.value(0, 19, (accX * 127).floor);
}
);
*/
}, "/acc/" ++ id);
});
)
(
"MIDI MAP V (III) !!!".postln;
~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
var pitch, roll, yaw;
// vrtenje sinusoidiziramo, da ni preskokov
pitch = msg[1].sin.linlin(-pi, pi, 0, 1);
roll = msg[2].sin.linlin(-pi, pi, 0, 1);
yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
// MORPHING EFEKT
switch (id,
4, {
// Quick slots 1-3
~sendMidi.value(0, 16, (-15 + (yaw * 150)).floor);
},
3, {
~sendMidi.value(0, 17, (-15 + (roll * 150).floor));
}
);
}, "/euler/" ++ id);
OSCdef.new((\accMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
// Pospeski: gremo od 0 ali iz sredine?
var accX, accY, accZ, accSum;
accX = msg[1].linlin(-50, 50, 0, 1);
accY = msg[2].linlin(-50, 50, 0, 1);
accZ = msg[3].linlin(-50, 50, 0, 1);
accSum = msg[4].linlin(-50, 50, 0, 1);
/*
switch (id,
3, {
~sendMidi.value(0, 19, (accX * 127).floor);
~sendMidi.value(0, 20, (accY * 127).floor);
~sendMidi.value(0, 21, (accZ * 127).floor);
}
);
*/
}, "/acc/" ++ id);
});
)
(
"MIDI MAP VI (III) !!!".postln;
~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
var pitch, roll, yaw;
// vrtenje sinusoidiziramo, da ni preskokov
pitch = msg[1].sin.linlin(-pi, pi, 0, 1);
roll = msg[2].sin.linlin(-pi, pi, 0, 1);
yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
switch (id,
3, {
// Quick slots 1-3
~sendMidi.value(0, 16, (pitch * 127).floor);
~sendMidi.value(0, 17, (yaw * 127).floor);
}
);
}, "/euler/" ++ id);
OSCdef.new((\accMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
// Pospeski: gremo od 0 ali iz sredine?
var accX, accY, accZ, accSum;
accX = msg[1].linlin(-50, 50, 0, 1);
accY = msg[2].linlin(-50, 50, 0, 1);
accZ = msg[3].linlin(-50, 50, 0, 1);
accSum = msg[4].linlin(-50, 50, 0, 1);
accSum = accSum - 0.5;
switch (id,
4, {
//~sendMidi.value(0, 18, (accSum * 200).floor);
}
);
}, "/acc/" ++ id);
});
)
(
"MIDI MAP VII (2)".postln;
~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
var pitch, roll, yaw;
// vrtenje sinusoidiziramo, da ni preskokov
pitch = msg[1].sin.linlin(-pi, pi, 0, 1);
roll = msg[2].sin.linlin(-pi, pi, 0, 1);
yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
// BITCRUSH EFEKT
/*
switch (id,
4, {
// Quick slots 1-3
~sendMidi.value(0, 16, (-15 + (yaw * 150)).floor);
},
3, {
~sendMidi.value(0, 17, (-15 + (roll * 150).floor));
}
);
*/
}, "/euler/" ++ id);
OSCdef.new((\accMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
// Pospeski: gremo od 0 ali iz sredine?
var accX, accY, accZ, accSum;
accX = msg[1].abs.linlin(-50, 50, 0, 1);
accY = msg[2].abs.linlin(0, 50, 0, 1);
accZ = msg[3].abs.linlin(0, 50, 0, 1);
accSum = msg[4].linlin(0, 50, 0, 1);
switch (id,
3, {
~sendMidi.value(0, 16, (accX * 127));
~sendMidi.value(0, 17, (accY * 127));
}
);
}, "/acc/" ++ id);
});
)
// VDMX mapping setup za simona - dedicated controls
(
~senzorji.keys.do({|id|
~oscS.sendMsg("/senzor/" ++ id ++ "/pitch", 0.5);
~oscS.sendMsg("/senzor/" ++ id ++ "/roll", 0.5);
~oscS.sendMsg("/senzor/" ++ id ++ "/yaw", 0.5);
~oscS.sendMsg("/senzor/" ++ id ++ "/accX", 0.5);
~oscS.sendMsg("/senzor/" ++ id ++ "/accY", 0.5);
~oscS.sendMsg("/senzor/" ++ id ++ "/accZ", 0.5);
~oscS.sendMsg("/senzor/" ++ id ++ "/accSum", 0.5);
});
)