README update, some arduino/pio updates, basic WIP GUI

main
Jurij Podgoršek 2024-09-03 15:04:59 +02:00
parent fcbd4058e8
commit f303161ef2
9 changed files with 210 additions and 12 deletions

View File

@ -0,0 +1,104 @@
AHRSensor {
var <id,
<>calibrationQuat,
<>quat,
<>euler,
<>accel,
<battery,
<gEx,
<gEy,
<gEz;
*new { |id|
^super.newCopyArgs(id).init;
}
quat2euler { |quat|
var w = quat.a, x = quat.b, y = quat.c, z = quat.d,
x2 = x + x, y2 = y + y, z2 = z + z,
xx = x * x2, xy = x * y2, xz = x * z2,
yy = y * y2, yz = y * z2, zz = z * z2,
wx = w * x2, wy = w * y2, wz = w * z2,
matrix = [
1 - ( yy + zz ), xy + wz, xz - wy, 0,
xy - wz, 1 - ( xx + zz ), yz + wx, 0,
xz + wy, yz - wx, 1 - ( xx + yy ), 0,
0, 0, 0, 1
];
var m11 = matrix[0], m12 = matrix[4], m13 = matrix[8];
var m21 = matrix[1], m22 = matrix[5], m23 = matrix[9];
var m31 = matrix[2], m32 = matrix[6], m33 = matrix[10];
var euler = [0, 0, 0];
euler[1] = asin(m13.clip(- 1, 1));
if ((m13.abs < 0.9999999), {
euler[0] = atan2(m23.neg, m33);
euler[2] = atan2(m12.neg, m11);
}, {
euler[0] = atan2(m32, m22);
euler[2] = 0;
});
euler.postln;
euler;
}
init {
quat = Quaternion;
calibrationQuat = Quaternion;
euler = [0, 0, 0];
accel = [0, 0, 0];
battery = 0;
this.guiInit;
}
guiInit {
// Barve
var cRed, cGreen, cBlue, cPurple, cI;
// Intenziteta
cI = 0.8;
cRed = Color.new(cI, 0, 0);
cGreen = Color.new(0, cI, 0);
cBlue = Color.new(0, 0, cI);
cPurple = Color.new(cI, 0, cI);
gEx = StaticText().string_(0).stringColor_(cRed);
gEy = StaticText().string_(0).stringColor_(cGreen);
gEz = StaticText().string_(0).stringColor_(cBlue);
}
getGui {
^VLayout(
StaticText().string_("Sensor " ++ id),
HLayout(
StaticText().string_("euler: "),
[StaticText().string_("x: "), align: \left],
[gEx, align: \left],
StaticText().string_("y: "),
gEy,
StaticText().string_("z: "),
gEz,
)
);
}
updateEuler { |newQuat|
var quatDiff = newQuat / quat;
euler += quat2euler(quatDiff);
}
refreshGui {
gEx.string_(euler[0]);
gEy.string_(euler[1]);
gEz.string_(euler[2]);
}
}

View File

@ -6,6 +6,16 @@ Ryuzo Fukohara dancing and triggering / modulating sounds and projections by Sim
We plan to plant 5-6 sensors on Ryuzota, the IMU signals will be converted
into midi for Borut in Simon.
** Code
*** Arduino sensor
[[file:src/ada.cpp][Arduino source (adafruit on ESP32S2)]]
*** Arduino receiver
[[file:src/sprejemnik.cpp][Arduino source (ESP32S3 receiver)]]
*** Supercollider receiver code
[[file:utopia.scd][Utopia receiver]]
*** SLIPDecoder source
[[file:~/.local/share/SuperCollider/downloaded-quarks/SLIPDecoder/SLIPDecoder.sc][SLIPDecoder source]]
** Microcontrollers
*** LilyGo ESP32-S3
https://www.lilygo.cc/products/t7-s3

View File

@ -1,5 +1,12 @@
#!/usr/bin/env sh
guix shell --container --network --emulate-fhs --share=$HOME/.platformio python-platformio coreutils bash nss-certs less gcc-toolchain glibc vim sudo
# Zakaj noce zbildat 32 bit verzije platformio??
guix shell --container --network --share=$HOME/.platformio python-platformio coreutils bash nss-certs zopfli python-zopfli --system=i686-linux --emulate-fhs -e '(list (@@ (gnu packages commencement) gcc) "lib")'
#guix shell --container --network --share=$HOME/.platformio coreutils bash nss-certs zopfli python-zopfli --system=i686-linux --emulate-fhs -e '(list (@@ (gnu packages commencement) gcc) "lib")'
#guix shell --container --network --emulate-fhs --share=$HOME/.platformio python-platformio coreutils bash nss-certs less vim sudo patchelf
#guix shell --container --network -s i686-linux --emulate-fhs --share=$HOME/.platformio python-virtualenv coreutils bash nss-certs less gcc-toolchain glibc python
#guix shell --container --network -s i686-linux --emulate-fhs --share=$HOME/.platformio python-virtualenv coreutils bash nss-certs less gcc-toolchain python

View File

@ -21,5 +21,4 @@
},
"frameworks": "arduino",
"platforms": "*"
]
}

View File

@ -27,7 +27,7 @@ board = lilygo-t7-s3
upload_protocol = esptool
upload_speed = 921600
monitor_speed = 115200
build_flags = -D ARDUINO_USB_CDC_ON_BOOT=1 -D CORE_DEBUG_LEVEL=1
build_flags = -D ARDUINO_USB_CDC_ON_BOOT=1
build_src_filter =
+<sprejemnik.cpp>

View File

@ -46,7 +46,7 @@ void setup() {
Wire.begin(SDApin, SCLpin);
// Fast mode
Wire.setClock(1000000);
Wire.setClock(400000);
bno = Adafruit_BNO055(55, 0x28, &Wire);
/* Initialise the sensor */

View File

@ -1,6 +1,8 @@
#include <Arduino.h>
#include <Wire.h>
#define __x86_64__
// ID kegla mora bit unikaten za vsakega! (se poslje poleg parametrov)
#define SENSOR_ID 1

View File

@ -11,7 +11,6 @@
//#define DEBUG
// Ponavadi imamo navaden serial
#include "SLIPEncodedSerial.h"
SLIPEncodedUSBSerial SLIPSerial(Serial);
@ -20,11 +19,11 @@ SLIPEncodedUSBSerial SLIPSerial(Serial);
uint8_t newMACAddress[] = {0x08, 0x3A, 0xF2, 0x50, 0xEF, 0x6C};
// Maksimalno stevilo
#define ST_KEGLOV 10
#define ST_SPREJEMNIKOV 10
int odcitekId;
sensor_msg odcitki[ST_KEGLOV];
bool poslji[ST_KEGLOV];
sensor_msg odcitki[ST_SPREJEMNIKOV];
bool poslji[ST_SPREJEMNIKOV];
void prejemPodatkov(const uint8_t * mac_addr, const uint8_t * noviPodatki, int len) {
@ -62,12 +61,14 @@ void prejemPodatkov(const uint8_t * mac_addr, const uint8_t * noviPodatki, int l
}
void setup() {
// Nizja CPU frekvenca
setCpuFrequencyMhz(80);
SLIPSerial.begin(115200);
//Serial.begin(115200);
// Ne posiljaj preden se podatki napolnijo
for (int i = 0; i < ST_KEGLOV; i++) {
poslji[0] = false;
for (int i = 0; i < ST_SPREJEMNIKOV; i++) {
poslji[i] = false;
}
for (int i = 0; i < 5; i++) {
@ -101,8 +102,9 @@ void loop() {
OSCBundle bundle;
char glava[32];
for (int i = 0; i < ST_KEGLOV; i++) {
for (int i = 0; i < ST_SPREJEMNIKOV; i++) {
if (poslji[i]) {
// Accel in quaternion v bundlu skupaj z ostalim sta velika 396 bytov!
sprintf(glava, "/ww/%d/accel", i);
/*
Serial.print("Posiljam ");

74
utopia.scd 100644
View File

@ -0,0 +1,74 @@
// Dependencies:
// - SLIPDecoder (https://git.kompot.si/g1smo/SLIPDecoder)
// - MathLib (https://depts.washington.edu/dxscdoc/Help/Browse.html#Libraries%3EMathLib)
(
// Initialize the the receiver via SLIP decoder
~receiverPath = "/dev/ttyACM0";
~baudRate = 115200;
~decoder = SLIPDecoder.new(~receiverPath, ~baudRate);
OSCFunc.trace(false); // debug osc
~decoder.trace(true); // debug slip decoder
/*******
* GUI *
******/
~senzorji = [];
~numSensors = 3;
~numSensors.do({ |n|
~senzorji.add(AHRSensor.new(n + 1));
});
~w = Window.new("Utopia || C²", Rect(300, 300, 640, ~numSensors * 20),true);
~elementi = ~senzorji.collect({|s| s.getGui;});
~ttyInput = TextField().string_("/dev/ttyACM0");
~w.layout_(
VLayout(
HLayout(
StaticText().string_("Serial path: "),
~ttyInput,
Button().string_("Start").action_({ | butt |
if ((~decoder.running.not), {
// If not running, start decoder
~decoder.deviceName = "";
~decoder = SLIPDecoder.new(~receiverPath, ~baudRate);
~decoder.start;
butt.string_("Stop")
}, {
// Else stop the decoder
~decoder.stop;
butt.string_("Start")
});
})
),
// Elementi senzorjev
VLayout(*~elementi)
)
);
~w.front;
q = OSCFunc({ |msg, time, addr, recvPort|
var q;
q = Quaternion.new(msg[4], msg[1], msg[2], msg[3]);
q.postln;
//~senzorji[0].updateEuler(q);
//~senzorji[0].euler.postln;
//~elementi[0].refreshGui;
}, "/ww/1/quaternion");
// Start the decoder!
//~decoder.start;
)
~decoder.trace;
~decoder.stop;
~decoder.start;
~decoder.rate;