Hi all,
Newbie/wannabee arduino tinkerer here. Im working on an analog vario gauge for a glider. Im using a x27.168 stepper from adafruit, that (for now), I connected straight to an arduino uno. Im using the SwitecX25 library.
The signal comes from an openvario glider computer, and is basically a number with 2 decimals precision, that represents climb/sink rate in meter per second, and Im only interested in values between -5.00 and +5.00.
I got it working, but I would like to smooth the motion. Have a look:
It looks better on video than it does to my eye, but especially with small movements, I think its still too jerky, and Im at a loss on how to improve it.
I tried adjusting the range, so I would more steps per meter/s, but it makes no real difference (by sheer luck, 945 steps of this motor is pretty close to the number of values between -5.00 and +5.00).
Here is my code:
#include "SwitecX25.h"
//setup stepper
#define STEPS (315*3) // standard X25.168 range 315 degrees at 1/3 degree steps
SwitecX25 motor1(STEPS,2,3,5,13);
int target=0;
int ind1;
int ind2;
int ind3;
int ind4;
int ind5;
String received;
String msgtype;
String variot;
float vario;
void setup() {
Serial.begin(9600);
vario=-0.1;
// run the motor against the stops
motor1.zero();
motor1.setPosition(STEPS/2);
motor1.updateBlocking();
}
void loop()
{
static char buffer[80];
if (readline(Serial.read(), buffer, 80) > 0) {
received=buffer;
if (received.substring(0,4) == "$POV"){
// Serial.print("got vario:> ");
ind1 = received.indexOf(','); //finds location of first ,
ind2 = received.indexOf(',', ind1+1 ); //Position of P or E or V
msgtype = received.substring(ind1+1, ind2); //P or E or V
// Serial.println(msgtype);
if (msgtype == "E") { // vario message
ind3 = received.indexOf(',', ind2+1 ); //value
variot= received.substring(ind2+1, received.length()); //IAS
ind4= variot.indexOf('*'); //position of checksum data at end
variot= variot.substring(0,ind4); //strip checksumdata
vario=variot.toFloat();
// Serial.println(vario);
}
}
}
target=-70*vario+STEPS/2;
motor1.setPosition(target);
motor1.update();
}
int readline(int readch, char *buffer, int len)
{
static int pos = 0;
int rpos;
if (readch > 0) {
switch (readch) {
case '\n': // Ignore new-lines
break;
case '\r': // Return on CR
rpos = pos;
pos = 0; // Reset position index ready for next time
return rpos;
default:
if (pos < len-1) {
buffer[pos++] = readch;
buffer[pos] = 0;
}
}
}
// No end of line has been found, so return -1.
return -1;
}
Is there something in can do in code to make this smoother? Would a stepper controller with microstepping help?
Also, Im a little surprised how noisy this stepper is. Its probably acceptable in a glider, but certainly not a car, which is where these are typically used. Is this normal?
I appreciate any and all help I can get with this.