diff --git a/AHRSensor/AHRSensor.sc b/AHRSensor/AHRSensor.sc new file mode 100644 index 0000000..04e4361 --- /dev/null +++ b/AHRSensor/AHRSensor.sc @@ -0,0 +1,104 @@ +AHRSensor { + var calibrationQuat, + <>quat, + <>euler, + <>accel, + + diff --git a/src/ada.cpp b/src/ada.cpp index 8fd8592..9c97074 100644 --- a/src/ada.cpp +++ b/src/ada.cpp @@ -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 */ diff --git a/src/main.cpp b/src/main.cpp index e2d4455..f3daef1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include #include +#define __x86_64__ + // ID kegla mora bit unikaten za vsakega! (se poslje poleg parametrov) #define SENSOR_ID 1 diff --git a/src/sprejemnik.cpp b/src/sprejemnik.cpp index c625cb4..91c54ec 100644 --- a/src/sprejemnik.cpp +++ b/src/sprejemnik.cpp @@ -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 "); diff --git a/utopia.scd b/utopia.scd new file mode 100644 index 0000000..0fad816 --- /dev/null +++ b/utopia.scd @@ -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; \ No newline at end of file