Skip to content

Commit c55b46f

Browse files
trailcode@gmail.comtrailcode@gmail.com
authored andcommitted
Acceleration ramp up working.
1 parent 939aa0f commit c55b46f

File tree

2 files changed

+70
-17
lines changed

2 files changed

+70
-17
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
.piolibdeps
33
.clang_complete
44
.gcc-flags.json
5-
.travis.yml
5+
.travis.yml
6+
src/MultiStepperControler.ino.cpp

src/MultiStepperControler.ino

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ int latchPin = 4; //Pin connected to ST_CP of 74HC595
1111
int myClockPin = 3; //Pin connected to SH_CP of 74HC595
1212
int myDataPin = 2; //Pin connected to DS of 74HC595
1313

14+
unsigned int index = 0;
15+
unsigned int counter = 0;
16+
17+
uint8_t draw_state = 0;
18+
19+
char buffer[256];
20+
bool ready = false;
21+
22+
int cnt = 0;
23+
1424
void stepperRotate(float rotation, float rpm);
1525

1626
enum
@@ -21,7 +31,8 @@ enum
2131

2232
enum ACCEL_STATE
2333
{
24-
RAMP_UP = 0,
34+
INITAL=0,
35+
RAMP_UP,
2536
CONSTANT,
2637
RAMP_DOWN,
2738
};
@@ -33,14 +44,18 @@ enum
3344
};
3445
//char modes[] = {MODE_CONSTANT,MODE_CONSTANT,MODE_CONSTANT,MODE_CONSTANT,MODE_CONSTANT,MODE_CONSTANT,MODE_CONSTANT,MODE_CONSTANT};
3546
char modes[] = {MODE_SET_POSITION,MODE_SET_POSITION,MODE_SET_POSITION,MODE_SET_POSITION,MODE_SET_POSITION,MODE_SET_POSITION,MODE_SET_POSITION,MODE_SET_POSITION};
36-
char accelState[] = {RAMP_UP,RAMP_UP,RAMP_UP,RAMP_UP,RAMP_UP,RAMP_UP,RAMP_UP,RAMP_UP};
47+
char accelState[] = {INITAL,INITAL,INITAL,INITAL,INITAL,INITAL,INITAL,INITAL};
3748
char directions[] = {DIRECTION_FORWARD,DIRECTION_FORWARD,DIRECTION_FORWARD,DIRECTION_FORWARD,DIRECTION_FORWARD,DIRECTION_FORWARD,DIRECTION_FORWARD,DIRECTION_FORWARD};
3849
long positions[] = {0,0,0,0,0,0,0,0};
3950
long destPositions[] = {0,0,0,0,0,0,0,0};
4051
bool changing[] = {0,0,0,0,0,0,0,0};
41-
bool enabledState[] = {1,1,0,0,0,0,0,0};
52+
bool enabledState[] = {1,0,0,0,0,0,0,0};
4253
unsigned int times[] = {0,0,0,0,0,0,0,0};
4354
unsigned long speeds[] = {1000, 600, 600, 600, 600, 600, 600, 600};
55+
56+
long initalRampSpeed = 10000;
57+
58+
long rampSpeeds[] = {initalRampSpeed,initalRampSpeed,initalRampSpeed,initalRampSpeed,initalRampSpeed,initalRampSpeed,initalRampSpeed,initalRampSpeed};
4459
bool states[] = {1,1,1,1,1,1,1,1};
4560
bool stepModes[8][3] = {{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}};
4661
unsigned long startSpeeds[] = {2000, 2000, 2000, 2000, 2000, 2000, 2000, 2000};
@@ -121,16 +136,6 @@ void receiveEvent(int bytes)
121136

122137
void timerIsr() { stepperRotate() ;}
123138

124-
unsigned int index = 0;
125-
unsigned int counter = 0;
126-
127-
uint8_t draw_state = 0;
128-
129-
char buffer[256];
130-
bool ready = false;
131-
132-
int cnt = 0;
133-
134139
void p(char * buf, char *fmt, ... )
135140
{
136141
va_list args;
@@ -353,11 +358,57 @@ void stepperRotate()
353358
unsigned int diff = counter - times[i];
354359
if(!enabledState[i]) { continue ;}
355360
//if(diff > speeds[i] || states[i])
361+
362+
if(positions[i] == destPositions[i])
363+
{
364+
accelState[i] = INITAL;
365+
366+
rampSpeeds[i] = initalRampSpeed;
367+
368+
continue;
369+
} // Breaks constant rotation
370+
371+
switch(accelState[i])
372+
{
373+
case INITAL:
374+
375+
accelState[i] = RAMP_UP;
376+
377+
goto doContinue;
378+
379+
380+
case RAMP_UP:
381+
382+
rampSpeeds[i] -= 10;
383+
384+
if(rampSpeeds[i] < 0)
385+
{
386+
accelState[i] = CONSTANT;
387+
388+
goto doContinue;
389+
}
390+
391+
if(diff <= rampSpeeds[i])
392+
{
393+
continue;
394+
}
395+
396+
break;
397+
398+
case CONSTANT:
399+
break;
400+
401+
case RAMP_DOWN:
402+
break;
403+
}
404+
405+
doContinue:
406+
356407
if(diff <= speeds[i]) { continue ;}
357408

358409
stepperPosChanged[i] = true;
359410
times[i] = counter;
360-
switch(modes[i])
411+
switch(modes[i]) // Try to move this code above, or combine it
361412
{
362413
case MODE_CONSTANT:
363414
states[i] = !states[i];
@@ -370,8 +421,9 @@ void stepperRotate()
370421
{
371422
if(positions[i] == destPositions[i])
372423
{
373-
states[i] = 0;
374-
break;
424+
states[i] = 0; // Does it get here?
425+
426+
break;
375427
}
376428
if(positions[i] - destPositions[i] > 0)
377429
{

0 commit comments

Comments
 (0)