Here’s the thing on the Arduino side:
The values are received via wifi, so the actual timing of them is non-consistent. Am I right in thinking that a queue/buffer is a good strategy to eliminate the inconsistent timings, and “trickle” the value to the motors at the right intervals? How would I implement this on the arduino? here’s the current code
// #define ARDUINOOSC_DEBUGLOG_ENABLE
#include <ArduinoOSCWiFi.h>
#include <AccelStepper.h>
#include <cppQueue.h>
#define IMPLEMENTATION FIFO
//# define VERBOSE
// WiFi stuff
const char* ssid = “BT-CKAF99”;
const char* pwd = “UiGPYi6LXiRtQd”;
const IPAddress ip(192, 168, 1, 201);
const IPAddress gateway(192, 168, 1, 1);
const IPAddress subnet(255, 255, 255, 0);
// for ArduinoOSC
const char* host = “192.168.1.186”;
const int recv_port = 9999;
// Define some steppers and the pins the will use
AccelStepper stepper1(AccelStepper::FULL4WIRE, 3, 4, 5, 6);
//AccelStepper stepper2(AccelStepper::FULL4WIRE, 9, 10, 11, 12);
cppQueue q(sizeof(int), 256, IMPLEMENTATION); // Instantiate queue
void setup() {
Serial.begin(115200);
delay(2000);
stepper1.setMaxSpeed(10000.0);
stepper1.setAcceleration(10000.0);
// WiFi stuff (no timeout setting for WiFi)
#if defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_RP2040)
#ifdef ESP_PLATFORM
WiFi.disconnect(true, true); // disable wifi, erase ap info
#else
WiFi.disconnect(true); // disable wifi
#endif
delay(1000);
WiFi.mode(WIFI_STA);
#endif
#ifdef ARDUINO_UNOR4_WIFI
WiFi.config(ip);
#else
WiFi.config(ip, gateway, subnet);
#endif
while (WiFi.status() != WL_CONNECTED) {
#ifdef ARDUINO_UNOR4_WIFI
static int count = 0;
if (count++ > 20) {
Serial.println(“WiFi connection timeout, retry”);
WiFi.begin(ssid, pwd);
count = 0;
}
#endif
}
Serial.print("WiFi connected, IP = ");
Serial.println(WiFi.localIP());
// publish osc messages (default publish rate = 30 [Hz])
// OscWiFi.publish(host, publish_port, "/publish/value", i, f, s)
// OscWiFi.publish(host, publish_port, "/publish/func", &millis, µs)
// ->setIntervalMsec(500.f);
// subscribe osc messages
// OscWiFi.subscribe(bind_port, "/bind/values", i, f, s);
OscWiFi.subscribe(recv_port, "/motor1", [](const OscMessage& m)
int value = m.arg<int>(0);
Serial.print(m.remoteIP());
Serial.print(m.remotePort());
Serial.print(m.address());
Serial.print(stepper1_lastValue);
}
void loop() {
//OscWiFi.update(); // should be called to receive + send osc
OscWiFi.parse(); // to receive osc
// OscWiFi.post(); // to publish osc
if (!stepper1.isRunning() && !q.isEmpty())
if (q.pop(&nextPosition))
stepper1.moveTo(nextPosition);
}