Hello,
I am using Arduino mega as microcontroller in my project. There are 5 stepper motor which needs to be rotated at different speed according to selected conditions. Each stepper motor has 12 number of speeds.
Please suggest how to write conditions in this programme as there is more then 200k combination.
You haven't given us much to go on.
Maths?
Lookup tables?
Welcome to the forum
Taking one stepper as an example, what controls the speed ?
How about using a 2 dimensional array with 12 rows (1 per speed) with the speed parameters in the columns ? Given the speed number (0 to 11) you can pick out the speed values and apply them to a stepper
Are the speed parameters the same for all of the steppers ?
A incremental rotary encoder is used to control speed.
Can you share any sample programme of 2 dimension array for arduino having 5×12 size.
Please post examples of how you set the speed of a single stepper to speeds 1 to 12
Are there 5 rotary encoders or just one ?
Are you sure a Mega is fast enough to handle a single encoder at max RPM, much less 5 of them? What is the pulse rate (pulses/second) for each motor when running at max RPM?
any sample programme
char table[5][12]={0};
for (int i=0; i<5; i++) {
for (int j=0; j<12; j++) {
table[i][j]=i*j;
}
}
There is only 1 encoder for all 5 motors. following code were used to control single motor. Here value of spacing is sent through android app via bluetooth and speedout is given by encoder.
void spac() {
if (spacing == 'A') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 3.13);
stepper.runSpeed();
}
else if (spacing == 'B') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 1.56);
stepper.runSpeed();
}
else if (spacing == 'C') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 1.04);
stepper.runSpeed();
}
else if (spacing == 'D') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 0.78);
stepper.runSpeed();
}
else if (spacing == 'E') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 0.625);
stepper.runSpeed();
}
else if (spacing == 'F') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 0.52);
stepper.runSpeed();
}
else if (spacing == 'G') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 0.446);
stepper.runSpeed();
}
else if (spacing == 'H') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 0.39);
stepper.runSpeed();
}
else if (spacing == 'I') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 0.35);
stepper.runSpeed();
}
else if (spacing == 'J') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 0.31);
stepper.runSpeed();
}
else if (spacing == 'K') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 0.28);
stepper.runSpeed();
}
else if (spacing == 'L') {
stepper.setCurrentPosition(0);
stepper.setSpeed(speedOut * 0.26);
stepper.runSpeed();
}
}
Encoder is of 600 PPR and the maximum speed of rotation in this case is 40-50 RPM.
Hello swapnilfmp
Take some time read and study the ussage about structs, arrays and structured array.
These mapping of conditions can be done by an object and a methode to handle the data.
Have a nice day and enjoy coding in C++.
consider
obviously the struct can contain more than just 1 component
struct Param {
float spd;
};
Param params [] = {
{ 3.13 }, // A
{ 1.56 },
{ 1.04 },
{ 0.78 },
{ 0.625 }, // E
{ 0.52 },
{ 0.446 },
{ 0.39 },
{ 0.35 }, // I
{ 0.31 },
{ 0.28 },
{ 0.26 }, // L
};
const int Nparams = sizeof(params) / sizeof(Param);
// -----------------------------------------------------------------------------
void
loop (void)
{
if (Serial.available ()) {
int i = Serial.read () - 'A';
if (0 <= i && i < Nparams)
Serial.println (params [i].spd);
}
}
void
setup (void)
{
Serial.begin (9600);
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.