void Gauge::updateGaugePosition(unsigned int new_value)
{
//do nothing when gauge position has not changed.
if (new_value == old_value)
return;
//gaugePosToSteps() converts the gauge position to stepper motor steps.
stepper.moveTo(gaugePosToSteps(new_value));
old_value = new_value;
}@ Gregor... The data I eventually receive has already been compared to the previous
@ Gregor... The data I receive has already been compared to the last piece of data so only data that has changed is sent to the Arduino board. That data goes into a global variable and then it is remapped as follows: "targetPos = map(value,0,65535,0,945); with 0 to 945 being the available steps for that specific motor.
So the only line I need in the void loop() function is "stepper.moveTo (targetPos);" and that will allow the motor to move in almost perfect sync and keep up with the simulator gauge??
--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think your main bottleneck will be the SPI communication, you may not be able to take advantage of the 200MHz cpu.
Hi,
With "bottleneck" i meant it will be the slowest part of the code, but not necessarily so slow that it becomes a problem. I am just wondering if it pays off to have a powerful CPU to accelerate some rather lightweight functions (assuming you use runSpeedToPosition()) when the time it takes to receive a complete SPI message is the same for a 200MHz cpu and a 16MHz cpu (that most arduinos use).
AccelStepper has a function setCurrentPosition(), is this what you are looking for? Or do you need a function that moves your steppers to their respective home positions? The latter you will have to implement yourself.
--
digitalWrite(9, HIGH);
delayMicroseconds(100);
digitalWrite(9, LOW);
delayMicroseconds(100);
i am asking that because i want to control the steeper by using a joy stick that the movement of joystick control the direction and speed of motor.if you know any better way to do this please clear it out for me.
#define MAXSPEED 100 //the maximum speed of your stepper (both directions)
uint16_t joystick_value;
int speed;
void loop()
{
joystick_value = analogRead(A0);
int speed = map(joystick_value, 0, 1024, -MAXSPEED, MAXSPEED ); //map joystick input to -MAXSPEED to +MAXSPEED range
stepper.setSpeed(speed);
stepper.runSpeed();
} void loop() {
stepper.moveTo(600); //move to almost full range of motion
stepper.moveT0(0);//return to zero
stepper.run():
}
#include <AccelStepper.h>
AccelStepper stepper (1, 8, 9);//driver, step, direction
AccelStepper stepper1 (1, 10, 11);//driver, step, direction
void setup() {
stepper.setMaxSpeed(2000.0);
stepper.setAcceleration(2000.0);
stepper.runToNewPosition(-630); //backwards sweep to find hard stop
stepper.setCurrentPosition(0);//establishes the zero position
stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(2000.0);
stepper1.runToNewPosition(-630); //backwards sweep to find hard stop
stepper1.setCurrentPosition(0);//establishes the zero position
//set target once
stepper1.moveTo(630);
stepper.moveTo(630);
}
void loop() {
stepper1.run();
stepper.run();
}thanks a lot for your reply gregor i really appreciate it
i tried to use this code like you said:
#include <AccelStepper.h>
#define X_pin A0
#define MAXSPEED 300 //the maximum speed of your stepper (both directions)
AccelStepper stepper(1, 9, 8);
uint16_t X_pinval;
int speed;
void setup() {
// put your setup code here, to run once:
}
void loop()
{
X_pinval = analogRead(A0);
int speed = map(X_pinval, 0, 1023, -MAXSPEED, MAXSPEED ); //map joystick input to -MAXSPEED to +MAXSPEED range
stepper.setSpeed(speed);
stepper.runSpeed();
} // Arduino pin numbers
//#define X_pin A0 // analog pin connected to X output
//#define Y_pin A1 // analog pin connected to Y output
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = A0; // joystick X axis
const int Y_pin = A1; // joystick Y axis
//int X_Pin = A1;
//int Y_Pin = A0;
void setup() {
pinMode(SW_pin, INPUT);
//digitalWrite(SW_pin, HIGH);
//pinMode(X_pin, INPUT);
//pinMode(Y_pin, INPUT);
//pinMode(SW_pin, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
Serial.print("Switch: ");
Serial.print(digitalRead(SW_pin));
Serial.print("\n");
Serial.print("X-axis: ");
Serial.print(analogRead(X_pin));
Serial.print("\n");
Serial.print("Y-axis: ");
Serial.println(analogRead(Y_pin));
Serial.print("\n\n");
delay(1000);
} Switch: 1
X-axis: 316
Y-axis: 614
Switch: 1
X-axis: 833
Y-axis: 565
Switch: 0
X-axis: 725
Y-axis: 214
Switch: 1
X-axis: 426
Y-axis: 140
Switch: 0
X-axis: 16
Y-axis: 849
Switch: 0
X-axis: 525
Y-axis: 203
Switch: 1
X-axis: 462
Y-axis: 631Hello John,
There are a few problems with the code you sent:
1. You are using setSpeed with run(). SetSpeed is only for use in constant
speed environments. Looks like you want to use accelerated steppers (viz
setting the accel with setAcceleration().
2. You are setting 2 new target positions every time through the loop and not
giving it a chance to move. moveTo does not actually implement the move, it
only sets a new target position.
To test a single stepper you prob want (untested):
void setup() {
stepper.setMaxSpeed(200.0);
stepper.setAcceleration(2000.0);
stepper.runToNewPosition(-615); //backwards sweep to find hard stop
stepper.setCurrentPosition(0); //establishes the zero position
}
void loop() {
stepper.run
--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
#include <AccelStepper.h>
#define NUM_STEPPERS 20
AccelStepper *steppers[NUM_STEPPERS];
void setup(){ Serial.begin(9600); Serial.println("begin"); for (int i = 0; i < NUM_STEPPERS; i++) { steppers[i] = new AccelStepper(AccelStepper::DRIVER, 2*i + 3, 2*i+ 1 + 3);
steppers[i]->setMaxSpeed(200.0); steppers[i]->setSpeed(100.0); }}
void loop(){ unsigned long start_time = millis(); unsigned long stop_time; uint16_t counter;
do { counter++;
for (int i = 0; i < NUM_STEPPERS; i++) { steppers[i]->runSpeed(); } } while (counter != 0);
stop_time = millis();
Serial.print("time needed: "); Serial.print(stop_time - start_time); Serial.println("ms");}begin
time needed: 14474ms
time needed: 14475ms
time needed: 14475ms
time needed: 14475ms
time needed: 14475ms
time needed: 14475ms
time needed: 14475ms
time needed: 14475ms