uStepper S
uStepperS.cpp
Go to the documentation of this file.
1 /********************************************************************************************
2 * File: uStepperS.cpp *
3 * Version: 2.0.0 *
4 * Date: March 30th, 2020 *
5 * Author: Thomas Hørring Olsen *
6 * *
7 *********************************************************************************************
8 * (C) 2020 *
9 * *
10 * uStepper ApS *
11 * www.ustepper.com *
12 * administration@ustepper.com *
13 * *
14 * The code contained in this file is released under the following open source license: *
15 * *
16 * Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International *
17 * *
18 * The code in this file is provided without warranty of any kind - use at own risk! *
19 * neither uStepper ApS nor the author, can be held responsible for any damage *
20 * caused by the use of the code contained in this file ! *
21 * *
22 ********************************************************************************************/
32 #include <uStepperS.h>
34 
36 {
37  pointer = this;
38 
39  this->microSteps = 256;
40  this->init();
41 
42  this->setMaxAcceleration(2000.0);
43  this->setMaxDeceleration(2000.0);
44  this->setMaxVelocity(100.0);
45 }
46 
47 uStepperS::uStepperS(float acceleration, float velocity)
48 {
49  pointer = this;
50  this->microSteps = 256;
51  this->init();
52 
53  this->setMaxAcceleration(acceleration);
54  this->setMaxVelocity(velocity);
55 }
56 
57 
58 void uStepperS::init( void ){
59 
60 
61  this->pidDisabled = 1;
62  /* Set CS, MOSI, SCK and DRV_ENN as Output */
63  DDRC = (1<<SCK1)|(1<<MOSI_ENC);
64  DDRD = (1<<DRV_ENN)|(1<<SD_MODE)|(1<<CS_ENCODER);
65  DDRE = (1<<MOSI1)|(1<<CS_DRIVER);
66 
67  PORTD |= (1 << DRV_ENN); // Set DRV_ENN HIGH, while configuring
68  PORTD &= ~(1 << SD_MODE); // Set SD_MODE LOW
69 
70  /*
71  * ---- Global SPI1 configuration ----
72  * SPE = 1: SPI enabled
73  * MSTR = 1: Master
74  * SPR0 = 0 & SPR1 = 0: fOSC/4 = 4Mhz
75  */
76  SPCR1 = (1<<SPE1)|(1<<MSTR1);
77 
78  driver.init( this );
79  encoder.init( this );
80  PORTD &= ~(1 << DRV_ENN); // Set DRV_ENN LOW
81 }
82 
83 bool uStepperS::getMotorState(uint8_t statusType)
84 {
85  this->driver.readMotorStatus();
86  if(this->driver.status & statusType)
87  {
88  return 0;
89  }
90  return 1;
91 }
92 
93 void uStepperS::checkOrientation(float distance)
94 {
95  float startAngle;
96  uint8_t inverted = 0;
97  uint8_t noninverted = 0;
98  this->driver.setShaftDirection(0);
99 
100  startAngle = this->encoder.getAngleMoved();
101  this->moveAngle(distance);
102 
103  while(this->getMotorState());
104 
105  startAngle -= distance/2.0;
106  if(this->encoder.getAngleMoved() < startAngle)
107  {
108  inverted++;
109  }
110  else
111  {
112  noninverted++;
113  }
114 
115  startAngle = this->encoder.getAngleMoved();
116  this->moveAngle(-distance);
117 
118  while(this->getMotorState());
119 
120  startAngle += distance/2.0;
121  if(this->encoder.getAngleMoved() > startAngle)
122  {
123  inverted++;
124  }
125  else
126  {
127  noninverted++;
128  }
129 
130  startAngle = this->encoder.getAngleMoved();
131  this->moveAngle(distance);
132 
133  while(this->getMotorState());
134 
135  startAngle -= distance/2.0;
136  if(this->encoder.getAngleMoved() < startAngle)
137  {
138  inverted++;
139  }
140  else
141  {
142  noninverted++;
143  }
144 
145  this->moveAngle(-distance);
146 
147  while(this->getMotorState());
148 
149  if(inverted > noninverted)
150  {
151  this->driver.setShaftDirection(1);
152  }
153 }
154 
155 void uStepperS::setup( uint8_t mode,
156  uint16_t stepsPerRevolution,
157  float pTerm,
158  float iTerm,
159  float dTerm,
160  uint16_t dropinStepSize,
161  bool setHome,
162  uint8_t invert,
163  uint8_t runCurrent,
164  uint8_t holdCurrent)
165 {
166  dropinCliSettings_t tempSettings;
167  this->pidDisabled = 1;
168  // Should setup mode etc. later
169  this->mode = mode;
170  this->fullSteps = stepsPerRevolution;
171  this->dropinStepSize = 256/dropinStepSize;
172  this->angleToStep = (float)this->fullSteps * (float)this->microSteps / 360.0;
173  this->rpmToVelocity = (float)(279620.267 * fullSteps * microSteps)/(CLOCKFREQ);
174  this->stepsPerSecondToRPM = 60.0/(this->microSteps*this->fullSteps);
175  this->RPMToStepsPerSecond = (this->microSteps*this->fullSteps)/60.0;
176  this->init();
177 
178  this->driver.setDeceleration( (uint32_t)( this->maxDeceleration ) );
179  this->driver.setAcceleration( (uint32_t)(this->maxAcceleration ) );
180 
181  this->setCurrent(0.0);
182  this->setHoldCurrent(0.0);
183 
184  this->setCurrent(40.0);
185  this->setHoldCurrent(0.0);
186 
187  this->encoder.Beta=5;
188  if(this->mode)
189  {
190  if(this->mode == DROPIN)
191  {
192  //Set Enable, Step and Dir signal pins from 3dPrinter controller as inputs
193  this->encoder.Beta = 2;
194  pinMode(2,INPUT);
195  pinMode(3,INPUT);
196  pinMode(4,INPUT);
197  //Enable internal pull-up resistors on the above pins
198  digitalWrite(2,HIGH);
199  digitalWrite(3,HIGH);
200  digitalWrite(4,HIGH);
201  delay(10000);
202  attachInterrupt(0, interrupt0, FALLING);
203  attachInterrupt(1, interrupt1, CHANGE);
204  this->driver.setDeceleration( 0xFFFE );
205  this->driver.setAcceleration( 0xFFFE );
206  Serial.begin(9600);
207 
208  tempSettings.P.f = pTerm;
209  tempSettings.I.f = iTerm;
210  tempSettings.D.f = dTerm;
211  tempSettings.invert = invert;
212  tempSettings.runCurrent = runCurrent;
213  tempSettings.holdCurrent = holdCurrent;
214  tempSettings.checksum = this->dropinSettingsCalcChecksum(&tempSettings);
215 
216  if(tempSettings.checksum != EEPROM.read(sizeof(dropinCliSettings_t)))
217  {
218  this->dropinSettings = tempSettings;
219  this->saveDropinSettings();
220  EEPROM.put(sizeof(dropinCliSettings_t),this->dropinSettings.checksum);
221  this->loadDropinSettings();
222  }
223  else
224  {
225  if(!this->loadDropinSettings())
226  {
227  this->dropinSettings = tempSettings;
228  this->saveDropinSettings();
229  EEPROM.put(sizeof(dropinCliSettings_t),this->dropinSettings.checksum);
230  this->loadDropinSettings();
231  }
232  }
233 
234 
235  this->dropinPrintHelp();
236  }
237  else
238  {
239  this->encoder.Beta = 4;
240  }
241  }
242 
243  if(setHome == true){
244  encoder.setHome();
245  }
246 
247  this->pidDisabled = 0;
248 
249  DDRB |= (1 << 4);
250 }
251 
252 void uStepperS::moveSteps( int32_t steps )
253 {
254  this->driver.setDeceleration( (uint16_t)( this->maxDeceleration ) );
255  this->driver.setAcceleration( (uint16_t)(this->maxAcceleration ) );
256  this->driver.setVelocity( (uint32_t)( this->maxVelocity ) );
257 
258  // Get current position
259  int32_t current = this->driver.getPosition();
260 
261  // Set new position
262  this->driver.setPosition( current + steps);
263 }
264 
265 
266 
267 void uStepperS::moveAngle( float angle )
268 {
269  int32_t steps;
270 
271  if(angle < 0.0)
272  {
273  steps = (int32_t)((angle * angleToStep) - 0.5);
274  this->moveSteps( steps );
275  }
276  else
277  {
278  steps = (int32_t)((angle * angleToStep) + 0.5);
279  this->moveSteps( steps );
280  }
281 }
282 
283 
284 void uStepperS::moveToAngle( float angle )
285 {
286  float diff;
287  int32_t steps;
288 
289  diff = angle - this->angleMoved();
290  steps = (int32_t)( (abs(diff) * angleToStep) + 0.5);
291 
292  if(diff < 0.0)
293  {
294  this->moveSteps( -steps );
295  }
296  else
297  {
298  this->moveSteps( steps );
299  }
300 }
301 
302 void uStepperS::enableStallguard( int8_t threshold, bool stopOnStall )
303 {
304  this->clearStall();
305  this->stallThreshold = threshold;
306  this->stallStop = stopOnStall;
307 
308  pointer->driver.enableStallguard( threshold, stopOnStall);
309 
310  this->stallEnabled = true;
311 }
312 
313 void uStepperS::disableStallguard( void )
314 {
315  pointer->driver.disableStallguard();
316 
317  this->stallEnabled = false;
318 }
319 
320 void uStepperS::clearStall( void )
321 {
322  pointer->driver.clearStall();
323 }
324 
325 bool uStepperS::isStalled( void )
326 {
327  return this->isStalled( this->stallThreshold );
328 }
329 
330 bool uStepperS::isStalled( int8_t threshold )
331 {
332  // If the threshold is different from what is configured..
333  if( threshold != this->stallThreshold || this->stallEnabled == false ){
334  // Reconfigure stallguard
335  this->enableStallguard( threshold, this->stallStop );
336  }
337 
338  int32_t stats = pointer->driver.readRegister(RAMP_STAT);
339 
340  // Only interested in 'status_sg', with bit position 13 (last bit in RAMP_STAT).
341  return ( stats >> 13 );
342 }
343 
344 void uStepperS::setBrakeMode( uint8_t mode, float brakeCurrent )
345 {
346  int32_t registerContent = this->driver.readRegister(PWMCONF);
347  registerContent &= ~(3UL << 20);
348  if(mode == FREEWHEELBRAKE)
349  {
350  this->setHoldCurrent(0.0);
351  this->driver.writeRegister( PWMCONF, PWM_AUTOSCALE(1) | PWM_GRAD(1) | PWM_AMPL(128) | PWM_FREQ(0) | FREEWHEEL(1) );
352  }
353  else if(mode == COOLBRAKE)
354  {
355  this->setHoldCurrent(0.0);
356  this->driver.writeRegister( PWMCONF, PWM_AUTOSCALE(1) | PWM_GRAD(1) | PWM_AMPL(128) | PWM_FREQ(0) | FREEWHEEL(2) );
357  }
358  else
359  {
360  this->setHoldCurrent(brakeCurrent);
361  this->driver.writeRegister( PWMCONF, PWM_AUTOSCALE(1) | PWM_GRAD(1) | PWM_AMPL(128) | PWM_FREQ(0) | FREEWHEEL(0) );
362  }
363 }
364 
365 void uStepperS::setRPM( float rpm)
366 {
367  int32_t velocityDir = rpmToVelocity * rpm;
368 
369  if(velocityDir > 0){
370  driver.setDirection(1);
371  }else{
372  driver.setDirection(0);
373  }
374 
375  // The velocity cannot be signed
376  uint32_t velocity = abs(velocityDir);
377 
378  driver.setVelocity( (uint32_t)velocity );
379 }
380 
381 
382 void uStepperS::setSPIMode( uint8_t mode ){
383 
384  switch(mode){
385  case 2:
386  SPCR1 |= (1<<CPOL1); // Set CPOL HIGH = 1
387  SPCR1 &= ~(1<<CPHA1); // Set CPHA LOW = 0
388  break;
389 
390  case 3:
391  SPCR1 |= (1<<CPOL1); // Set CPOL HIGH = 1
392  SPCR1 |= (1<<CPHA1); // Set CPHA HIGH = 1
393  break;
394  }
395 }
396 
397 uint8_t uStepperS::SPI(uint8_t data){
398 
399  SPDR1 = data;
400 
401  // Wait for transmission complete
402  while(!( SPSR1 & (1 << SPIF1) ));
403 
404  return SPDR1;
405 
406 }
407 
408 void uStepperS::setMaxVelocity( float velocity )
409 {
410  velocity *= (float)this->microSteps;
411  velocity = abs(velocity)*VELOCITYCONVERSION;
412 
413  this->maxVelocity = velocity;
414 
415  // Steps per second, has to be converted to microsteps
416  this->driver.setVelocity( (uint32_t)( this->maxVelocity ) );
417 }
418 
419 void uStepperS::setMaxAcceleration( float acceleration )
420 {
421  acceleration *= (float)this->microSteps;
422  acceleration = abs(acceleration) * ACCELERATIONCONVERSION;
423 
424  this->maxAcceleration = acceleration;
425 
426 
427  // Steps per second, has to be converted to microsteps
428  this->driver.setAcceleration( (uint32_t)(this->maxAcceleration ) );
429 }
430 
431 void uStepperS::setMaxDeceleration( float deceleration )
432 {
433  deceleration *= (float)this->microSteps;
434  deceleration = abs(deceleration) * ACCELERATIONCONVERSION;
435 
436  this->maxDeceleration = deceleration;
437 
438  // Steps per second, has to be converted to microsteps
439  this->driver.setDeceleration( (uint32_t)(this->maxDeceleration ) );
440 }
441 
442 void uStepperS::setCurrent( double current )
443 {
444  if( current <= 100.0 && current >= 0.0){
445  // The current needs to be in the range of 0-31
446  this->driver.current = ceil(0.31 * current);
447  }else{
448  // If value is out of range, set default
449  this->driver.current = 16;
450  }
451 
453 }
454 
455 void uStepperS::setHoldCurrent( double current )
456 {
457  // The current needs to be in the range of 0-31
458  if( current <= 100.0 && current >= 0.0){
459  // The current needs to be in the range of 0-31
460  this->driver.holdCurrent = ceil(0.31 * current);
461  }else{
462  // If value is out of range, set default
463  this->driver.holdCurrent = 16;
464  }
465 
467 }
468 
469 void uStepperS::runContinous( bool direction )
470 {
471  this->driver.setDeceleration( (uint32_t)( this->maxDeceleration ) );
472  this->driver.setAcceleration( (uint32_t)(this->maxAcceleration ) );
473  this->driver.setVelocity( (uint32_t)( this->maxVelocity ) );
474 
475  // Make sure we use velocity mode
477 
478  // Set the direction
479  this->driver.setDirection( direction );
480 }
481 
482 float uStepperS::angleMoved ( void )
483 {
484  return this->encoder.getAngleMoved();
485 }
486 
487 void uStepperS::stop( bool mode){
488 
489  if(mode == HARD)
490  {
491  this->driver.setDeceleration( 0xFFFE );
492  this->driver.setAcceleration( 0xFFFE );
493  this->setRPM(0);
494  while(this->driver.readRegister(VACTUAL) != 0);
495  this->driver.setDeceleration( (uint32_t)( this->maxDeceleration ) );
496  this->driver.setAcceleration( (uint32_t)(this->maxAcceleration ) );
497  }
498  else
499  {
500  this->setRPM(0);
501  }
502 }
503 
504 void uStepperS::filterSpeedPos(posFilter_t *filter, int32_t steps)
505 {
506  if(this->mode != DROPIN)
507  {
508  filter->posEst += filter->velEst * ENCODERINTPERIOD * 0.5f;
509  }
510  else
511  {
512  filter->posEst += filter->velEst * ENCODERINTPERIOD;
513  }
514 
515 
516  filter->posError = (float)steps - filter->posEst;
517  if(this->mode != DROPIN)
518  {
519  filter->velIntegrator += filter->posError * PULSEFILTERKI * 0.5f;
520  }
521  else
522  {
523  filter->velIntegrator += filter->posError * PULSEFILTERKI;
524  }
525  filter->velEst = (filter->posError * PULSEFILTERKP) + filter->velIntegrator;
526 }
527 
528 void interrupt1(void)
529 {
530  if(PIND & 0x04)
531  {
532  PORTD |= (1 << 4);
533  }
534  else
535  {
536  PORTD &= ~(1 << 4);
537  }
538 }
539 
540 void interrupt0(void)
541 {
542  if(PIND & 0x04)
543  {
544  PORTD |= (1 << 4);
545  }
546  else
547  {
548  PORTD &= ~(1 << 4);
549  }
550  if((PINB & (0x08))) //CCW
551  {
553  {
554  pointer->stepCnt-=pointer->dropinStepSize; //DIR is set to CCW, therefore we subtract 1 step from step count (negative values = number of steps in CCW direction from initial postion)
555  }
556  else
557  {
558  pointer->stepCnt+=pointer->dropinStepSize; //DIR is set to CW, therefore we add 1 step to step count (positive values = number of steps in CW direction from initial postion)
559  }
560 
561  }
562  else //CW
563  {
565  {
566  pointer->stepCnt+=pointer->dropinStepSize; //DIR is set to CW, therefore we add 1 step to step count (positive values = number of steps in CW direction from initial postion)
567  }
568  else
569  {
570  pointer->stepCnt-=pointer->dropinStepSize; //DIR is set to CCW, therefore we subtract 1 step from step count (negative values = number of steps in CCW direction from initial postion)
571  }
572  }
573 }
574 
575 void TIMER1_COMPA_vect(void)
576 {
577 
578  int32_t stepsMoved;
579  int32_t stepCntTemp;
580  float error;
581  float output;
582  sei();
583 
585  stepsMoved = pointer->driver.getPosition();
586  if(pointer->mode == DROPIN)
587  {
588  cli();
589  stepCntTemp = pointer->stepCnt;
590  sei();
591 
593 
594  if(!pointer->pidDisabled)
595  {
596  error = (stepCntTemp - (int32_t)(pointer->encoder.angleMoved * ENCODERDATATOSTEP))/16;
598  pointer->pid(error);
599  }
600  return;
601  }
602  else if(pointer->mode == CLOSEDLOOP)
603  {
604  if(!pointer->pidDisabled)
605  {
608  {
611  }
612 
614  }
615  }
616 }
617 
618 void uStepperS::setControlThreshold(float threshold)
619 {
620  this->controlThreshold = threshold;
621 }
622 void uStepperS::enablePid(void)
623 {
624  cli();
625  this->pidDisabled = 0;
626  sei();
627 }
628 
629 void uStepperS::disablePid(void)
630 {
631  cli();
632  this->pidDisabled = 1;
633  sei();
634 }
635 
637 {
638  this->enablePid();
639 }
640 
642 {
643  this->disablePid();
644 }
645 
646 float uStepperS::moveToEnd(bool dir, float rpm, int8_t threshold)
647 {
648  // Lowest reliable speed for stallguard
649  if (rpm < 20.0)
650  rpm = 20.0;
651 
652  this->isStalled();
653  // Enable stallguard to detect hardware stop (use driver directly, as to not override user stall settings)
654  pointer->driver.enableStallguard( threshold, true );
655 
656  float length = this->encoder.getAngleMoved();
657 
658  if(dir == CW)
659  this->setRPM(abs(rpm));
660  else
661  this->setRPM(-abs(rpm));
662 
663  delay(100);
664 
665  while( !this->isStalled() ){}
666  this->stop();
667  pointer->driver.clearStall();
668 
669  // Return to normal operation
671 
672  length -= this->encoder.getAngleMoved();
673  delay(1000);
674  return abs(length);
675 }
676 
677 float uStepperS::getPidError(void)
678 {
679  return this->currentPidError;
680 }
681 
682 float uStepperS::pid(float error)
683 {
684  float u;
685  float limit = abs(this->currentPidSpeed) + 10000.0;
686  static float integral;
687  static bool integralReset = 0;
688  static float errorOld, differential = 0.0;
689 
690  this->currentPidError = error;
691 
692  u = error*this->pTerm;
693 
694  if(u > 0.0)
695  {
696  if(u > limit)
697  {
698  u = limit;
699  }
700  }
701  else if(u < 0.0)
702  {
703  if(u < -limit)
704  {
705  u = -limit;
706  }
707  }
708 
709  integral += error*this->iTerm;
710 
711  if(integral > 200000.0)
712  {
713  integral = 200000.0;
714  }
715  else if(integral < -200000.0)
716  {
717  integral = -200000.0;
718  }
719 
720  if(error > -10 && error < 10)
721  {
722  if(!integralReset)
723  {
724  integralReset = 1;
725  integral = 0;
726  }
727  }
728  else
729  {
730  integralReset = 0;
731  }
732 
733  u += integral;
734 
735  differential *= 0.9;
736  differential += 0.1*((error - errorOld)*this->dTerm);
737 
738  errorOld = error;
739 
740  u += differential;
741 
742  u *= this->stepsPerSecondToRPM * 16.0;
743  this->setRPM(u);
744  this->driver.setDeceleration( 0xFFFE );
745  this->driver.setAcceleration( 0xFFFE );
746 }
747 
748 void uStepperS::setProportional(float P)
749 {
750  this->pTerm = P;
751 }
752 
753 void uStepperS::setIntegral(float I)
754 {
755  this->iTerm = I * ENCODERINTPERIOD;
756 }
757 
758 void uStepperS::setDifferential(float D)
759 {
760  this->dTerm = D * ENCODERINTFREQ;
761 }
762 
763 void uStepperS::invertDropinDir(bool invert)
764 {
765  this->invertPidDropinDirection = invert;
766 }
767 
768 void uStepperS::parseCommand(String *cmd)
769 {
770  uint8_t i = 0;
771  String value;
772 
773  if(cmd->charAt(2) == ';')
774  {
775  Serial.println("COMMAND NOT ACCEPTED");
776  return;
777  }
778 
779  value.remove(0);
780  /****************** SET P Parameter ***************************
781  * *
782  * *
783  **************************************************************/
784  if(cmd->substring(0,2) == String("P="))
785  {
786  for(i = 2;;i++)
787  {
788  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
789  {
790  value.concat(cmd->charAt(i));
791  }
792  else if(cmd->charAt(i) == '.')
793  {
794  value.concat(cmd->charAt(i));
795  i++;
796  break;
797  }
798  else if(cmd->charAt(i) == ';')
799  {
800  break;
801  }
802  else
803  {
804  Serial.println("COMMAND NOT ACCEPTED");
805  return;
806  }
807  }
808 
809  for(;;i++)
810  {
811  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
812  {
813  value.concat(cmd->charAt(i));
814  }
815  else if(cmd->charAt(i) == ';')
816  {
817  Serial.print("COMMAND ACCEPTED. P = ");
818  Serial.println(value.toFloat(),4);
819  this->dropinSettings.P.f = value.toFloat();
820  this->saveDropinSettings();
821  this->setProportional(value.toFloat());
822  return;
823  }
824  else
825  {
826  Serial.println("COMMAND NOT ACCEPTED");
827  return;
828  }
829  }
830  }
831 
832 /****************** SET I Parameter ***************************
833  * *
834  * *
835  **************************************************************/
836  else if(cmd->substring(0,2) == String("I="))
837  {
838  for(i = 2;;i++)
839  {
840  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
841  {
842  value.concat(cmd->charAt(i));
843  }
844  else if(cmd->charAt(i) == '.')
845  {
846  value.concat(cmd->charAt(i));
847  i++;
848  break;
849  }
850  else if(cmd->charAt(i) == ';')
851  {
852  break;
853  }
854  else
855  {
856  Serial.println("COMMAND NOT ACCEPTED");
857  return;
858  }
859  }
860 
861  for(;;i++)
862  {
863  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
864  {
865  value.concat(cmd->charAt(i));
866  }
867  else if(cmd->charAt(i) == ';')
868  {
869  Serial.print("COMMAND ACCEPTED. I = ");
870  Serial.println(value.toFloat(),4);
871  this->dropinSettings.I.f = value.toFloat();
872  this->saveDropinSettings();
873  this->setIntegral(value.toFloat());
874  return;
875  }
876  else
877  {
878  Serial.println("COMMAND NOT ACCEPTED");
879  return;
880  }
881  }
882  }
883 
884 /****************** SET D Parameter ***************************
885  * *
886  * *
887  **************************************************************/
888  else if(cmd->substring(0,2) == String("D="))
889  {
890  for(i = 2;;i++)
891  {
892  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
893  {
894  value.concat(cmd->charAt(i));
895  }
896  else if(cmd->charAt(i) == '.')
897  {
898  value.concat(cmd->charAt(i));
899  i++;
900  break;
901  }
902  else if(cmd->charAt(i) == ';')
903  {
904  break;
905  }
906  else
907  {
908  Serial.println("COMMAND NOT ACCEPTED");
909  return;
910  }
911  }
912 
913  for(;;i++)
914  {
915  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
916  {
917  value.concat(cmd->charAt(i));
918  }
919  else if(cmd->charAt(i) == ';')
920  {
921  Serial.print("COMMAND ACCEPTED. D = ");
922  Serial.println(value.toFloat(),4);
923  this->dropinSettings.D.f = value.toFloat();
924  this->saveDropinSettings();
925  this->setDifferential(value.toFloat());
926  return;
927  }
928  else
929  {
930  Serial.println("COMMAND NOT ACCEPTED");
931  return;
932  }
933  }
934  }
935 
936 /****************** invert Direction ***************************
937  * *
938  * *
939  **************************************************************/
940  else if(cmd->substring(0,6) == String("invert"))
941  {
942  if(cmd->charAt(6) != ';')
943  {
944  Serial.println("COMMAND NOT ACCEPTED");
945  return;
946  }
947  if(this->invertPidDropinDirection)
948  {
949  Serial.println(F("Direction normal!"));
950  this->dropinSettings.invert = 0;
951  this->saveDropinSettings();
952  this->invertDropinDir(0);
953  return;
954  }
955  else
956  {
957  Serial.println(F("Direction inverted!"));
958  this->dropinSettings.invert = 1;
959  this->saveDropinSettings();
960  this->invertDropinDir(1);
961  return;
962  }
963  }
964 
965  /****************** get Current Pid Error ********************
966  * *
967  * *
968  **************************************************************/
969  else if(cmd->substring(0,5) == String("error"))
970  {
971  if(cmd->charAt(5) != ';')
972  {
973  Serial.println("COMMAND NOT ACCEPTED");
974  return;
975  }
976  Serial.print(F("Current Error: "));
977  Serial.print(this->getPidError());
978  Serial.println(F(" Steps"));
979  }
980 
981  /****************** Get run/hold current settings ************
982  * *
983  * *
984  **************************************************************/
985  else if(cmd->substring(0,7) == String("current"))
986  {
987  if(cmd->charAt(7) != ';')
988  {
989  Serial.println("COMMAND NOT ACCEPTED");
990  return;
991  }
992  Serial.print(F("Run Current: "));
993  Serial.print(ceil(((float)this->driver.current)/0.31));
994  Serial.println(F(" %"));
995  Serial.print(F("Hold Current: "));
996  Serial.print(ceil(((float)this->driver.holdCurrent)/0.31));
997  Serial.println(F(" %"));
998  }
999 
1000  /****************** Get PID Parameters ***********************
1001  * *
1002  * *
1003  **************************************************************/
1004  else if(cmd->substring(0,10) == String("parameters"))
1005  {
1006  if(cmd->charAt(10) != ';')
1007  {
1008  Serial.println("COMMAND NOT ACCEPTED");
1009  return;
1010  }
1011  Serial.print(F("P: "));
1012  Serial.print(this->dropinSettings.P.f,4);
1013  Serial.print(F(", "));
1014  Serial.print(F("I: "));
1015  Serial.print(this->dropinSettings.I.f,4);
1016  Serial.print(F(", "));
1017  Serial.print(F("D: "));
1018  Serial.println(this->dropinSettings.D.f,4);
1019  }
1020 
1021  /****************** Help menu ********************************
1022  * *
1023  * *
1024  **************************************************************/
1025  else if(cmd->substring(0,4) == String("help"))
1026  {
1027  if(cmd->charAt(4) != ';')
1028  {
1029  Serial.println("COMMAND NOT ACCEPTED");
1030  return;
1031  }
1032  this->dropinPrintHelp();
1033  }
1034 
1035 /****************** SET run current ***************************
1036  * *
1037  * *
1038  **************************************************************/
1039  else if(cmd->substring(0,11) == String("runCurrent="))
1040  {
1041  for(i = 11;;i++)
1042  {
1043  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
1044  {
1045  value.concat(cmd->charAt(i));
1046  }
1047  else if(cmd->charAt(i) == '.')
1048  {
1049  value.concat(cmd->charAt(i));
1050  i++;
1051  break;
1052  }
1053  else if(cmd->charAt(i) == ';')
1054  {
1055  break;
1056  }
1057  else
1058  {
1059  Serial.println("COMMAND NOT ACCEPTED");
1060  return;
1061  }
1062  }
1063 
1064  for(;;i++)
1065  {
1066  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
1067  {
1068  value.concat(cmd->charAt(i));
1069  }
1070  else if(cmd->charAt(i) == ';')
1071  {
1072  if(value.toFloat() >= 0.0 && value.toFloat() <= 100.0)
1073  {
1074  i = (uint8_t)value.toFloat();
1075  break;
1076  }
1077  else
1078  {
1079  Serial.println("COMMAND NOT ACCEPTED");
1080  return;
1081  }
1082  }
1083  else
1084  {
1085  Serial.println("COMMAND NOT ACCEPTED");
1086  return;
1087  }
1088  }
1089 
1090  Serial.print("COMMAND ACCEPTED. runCurrent = ");
1091  Serial.print(i);
1092  Serial.println(F(" %"));
1093  this->dropinSettings.runCurrent = i;
1094  this->saveDropinSettings();
1095  this->setCurrent(i);
1096  }
1097 
1098  /****************** SET run current ***************************
1099  * *
1100  * *
1101  **************************************************************/
1102  else if(cmd->substring(0,12) == String("holdCurrent="))
1103  {
1104  for(i = 12;;i++)
1105  {
1106  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
1107  {
1108  value.concat(cmd->charAt(i));
1109  }
1110  else if(cmd->charAt(i) == '.')
1111  {
1112  value.concat(cmd->charAt(i));
1113  i++;
1114  break;
1115  }
1116  else if(cmd->charAt(i) == ';')
1117  {
1118  break;
1119  }
1120  else
1121  {
1122  Serial.println("COMMAND NOT ACCEPTED");
1123  return;
1124  }
1125  }
1126 
1127  for(;;i++)
1128  {
1129  if(cmd->charAt(i) >= '0' && cmd->charAt(i) <= '9')
1130  {
1131  value.concat(cmd->charAt(i));
1132  }
1133  else if(cmd->charAt(i) == ';')
1134  {
1135  if(value.toFloat() >= 0.0 && value.toFloat() <= 100.0)
1136  {
1137  i = (uint8_t)value.toFloat();
1138  break;
1139  }
1140  else
1141  {
1142  Serial.println("COMMAND NOT ACCEPTED");
1143  return;
1144  }
1145  }
1146  else
1147  {
1148  Serial.println("COMMAND NOT ACCEPTED");
1149  return;
1150  }
1151  }
1152 
1153  Serial.print("COMMAND ACCEPTED. holdCurrent = ");
1154  Serial.print(i);
1155  Serial.println(F(" %"));
1156  this->dropinSettings.holdCurrent = i;
1157  this->saveDropinSettings();
1158  this->setHoldCurrent(i);
1159  }
1160 
1161  /****************** DEFAULT (Reject!) ************************
1162  * *
1163  * *
1164  **************************************************************/
1165  else
1166  {
1167  Serial.println("COMMAND NOT ACCEPTED");
1168  return;
1169  }
1170 
1171 }
1173 void uStepperS::dropinCli()
1174 {
1175  static String stringInput;
1176  static uint32_t t = millis();
1177 
1178  while(1)
1179  {
1180  while(!Serial.available())
1181  {
1182  delay(1);
1183  if((millis() - t) >= 500)
1184  {
1185  stringInput.remove(0);
1186  t = millis();
1187  }
1188  }
1189  t = millis();
1190  stringInput += (char)Serial.read();
1191  if(stringInput.lastIndexOf(';') > -1)
1192  {
1193  this->parseCommand(&stringInput);
1194  stringInput.remove(0);
1195  }
1196  }
1197 }
1200 {
1201  Serial.println(F("uStepper S Dropin !"));
1202  Serial.println(F(""));
1203  Serial.println(F("Usage:"));
1204  Serial.println(F("Show this command list: 'help;'"));
1205  Serial.println(F("Get PID Parameters: 'parameters;'"));
1206  Serial.println(F("Set Proportional constant: 'P=10.002;'"));
1207  Serial.println(F("Set Integral constant: 'I=10.002;'"));
1208  Serial.println(F("Set Differential constant: 'D=10.002;'"));
1209  Serial.println(F("Invert Direction: 'invert;'"));
1210  Serial.println(F("Get Current PID Error: 'error;'"));
1211  Serial.println(F("Get Run/Hold Current Settings: 'current;'"));
1212  Serial.println(F("Set Run Current (percent): 'runCurrent=50.0;'"));
1213  Serial.println(F("Set Hold Current (percent): 'holdCurrent=50.0;'"));
1214  Serial.println(F(""));
1215  Serial.println(F(""));
1216 }
1219 {
1220  dropinCliSettings_t tempSettings;
1221 
1222  EEPROM.get(0,tempSettings);
1223 
1224  if(this->dropinSettingsCalcChecksum(&tempSettings) != tempSettings.checksum)
1225  {
1226  return 0;
1227  }
1228 
1229  this->dropinSettings = tempSettings;
1230  this->setProportional(this->dropinSettings.P.f);
1231  this->setIntegral(this->dropinSettings.I.f);
1232  this->setDifferential(this->dropinSettings.D.f);
1233  this->invertDropinDir((bool)this->dropinSettings.invert);
1234  this->setCurrent(this->dropinSettings.runCurrent);
1236  return 1;
1237 }
1240 {
1242 
1243  EEPROM.put(0,this->dropinSettings);
1244 }
1247 {
1248  uint8_t i;
1249  uint8_t checksum = 0xAA;
1250  uint8_t *p = (uint8_t*)settings;
1251 
1252  for(i=0; i < 15; i++)
1253  {
1254  checksum ^= *p++;
1255  }
1256 
1257  return checksum;
1258 }
XTARGET
#define XTARGET
Definition: uStepperDriver.h:65
uStepperS::externalStepInputFilter
volatile posFilter_t externalStepInputFilter
Definition: uStepperS.h:724
uStepperS
Prototype of class for accessing all features of the uStepper S in a single object.
Definition: uStepperS.h:272
uStepperDriver::init
void init(uStepperS *_pointer)
Initiation of the motor driver.
Definition: uStepperDriver.cpp:68
uStepperS::dropinStepSize
uint16_t dropinStepSize
Definition: uStepperS.h:717
dropinCliSettings_t::P
floatBytes_t P
Definition: uStepperS.h:182
uStepperDriver::disableStallguard
void disableStallguard(void)
Definition: uStepperDriver.cpp:381
uStepperS::moveSteps
void moveSteps(int32_t steps)
Make the motor perform a predefined number of steps.
Definition: uStepperS.cpp:251
uStepperS::enableStallguard
void enableStallguard(int8_t threshold=4, bool stopOnStall=false)
Enable TMC5130 StallGuard.
Definition: uStepperS.cpp:301
uStepperS::getMotorState
bool getMotorState(uint8_t statusType=POSITION_REACHED)
Get the current motor driver state.
Definition: uStepperS.cpp:82
uStepperS::stallEnabled
bool stallEnabled
Definition: uStepperS.h:754
uStepperDriver::setAcceleration
void setAcceleration(uint32_t acceleration)
Set motor acceleration.
Definition: uStepperDriver.cpp:117
uStepperDriver::readRegister
int32_t readRegister(uint8_t address)
Reads a register from the motor driver.
Definition: uStepperDriver.cpp:306
uStepperS::setBrakeMode
void setBrakeMode(uint8_t mode, float brakeCurrent=25.0)
Definition: uStepperS.cpp:343
uStepperS.h
uStepperDriver::readMotorStatus
void readMotorStatus(void)
Definition: uStepperDriver.cpp:99
PULSEFILTERKI
#define PULSEFILTERKI
Definition: uStepperS.h:239
uStepperEncoder::Beta
volatile uint8_t Beta
Definition: uStepperEncoder.h:228
uStepperEncoder::angleMoved
volatile int32_t angleMoved
Definition: uStepperEncoder.h:211
posFilter_t::velIntegrator
float velIntegrator
Definition: uStepperS.h:200
uStepperS::dTerm
float dTerm
Definition: uStepperS.h:734
uStepperEncoder::getAngleMoved
float getAngleMoved(bool filtered=true)
Returns the angle moved from reference position in degrees.
Definition: uStepperEncoder.cpp:182
uStepperS::rpmToVelocity
float rpmToVelocity
Definition: uStepperS.h:712
dropinCliSettings_t
Struct to store dropin settings.
Definition: uStepperS.h:180
posFilter_t::velEst
float velEst
Definition: uStepperS.h:201
pointer
uStepperS * pointer
Definition: uStepperS.cpp:32
uStepperDriver::setVelocity
void setVelocity(uint32_t velocity)
Set motor velocity.
Definition: uStepperDriver.cpp:105
uStepperS::setSPIMode
void setSPIMode(uint8_t mode)
Definition: uStepperS.cpp:381
uStepperEncoder::captureAngle
uint16_t captureAngle(void)
Capture the current shaft angle.
Definition: uStepperEncoder.cpp:115
ACCELERATIONCONVERSION
#define ACCELERATIONCONVERSION
Definition: uStepperDriver.h:140
uStepperS::disableStallguard
void disableStallguard(void)
Disables the builtin stallguard offered from TMC5130, and reenables StealthChop.
Definition: uStepperS.cpp:312
CW
#define CW
Definition: uStepperS.h:154
dropinCliSettings_t::D
floatBytes_t D
Definition: uStepperS.h:184
uStepperS::runContinous
void runContinous(bool dir)
Make the motor rotate continuously.
Definition: uStepperS.cpp:468
uStepperS::disablePid
void disablePid(void)
This method disables the PID until calling enablePid.
Definition: uStepperS.cpp:628
SCK1
#define SCK1
Definition: uStepperS.h:222
uStepperS::fullSteps
uint16_t fullSteps
Definition: uStepperS.h:716
uStepperDriver::clearStall
void clearStall(void)
Definition: uStepperDriver.cpp:393
uStepperS::pTerm
float pTerm
Definition: uStepperS.h:730
uStepperS::maxAcceleration
float maxAcceleration
Definition: uStepperS.h:709
uStepperS::isStalled
bool isStalled(void)
This method returns a bool variable indicating wether the motor is stalled or not....
Definition: uStepperS.cpp:324
uStepperS::stepsPerSecondToRPM
float stepsPerSecondToRPM
Definition: uStepperS.h:721
FREEWHEELBRAKE
#define FREEWHEELBRAKE
Definition: uStepperS.h:150
uStepperS::dropinCli
void dropinCli()
This method is used to tune Drop-in parameters. After tuning uStepper S, the parameters are saved in ...
Definition: uStepperS.cpp:1172
uStepperEncoder::encoderFilter
volatile posFilter_t encoderFilter
Definition: uStepperEncoder.h:225
uStepperS::stepCnt
int32_t stepCnt
Definition: uStepperS.h:719
uStepperS::controlThreshold
volatile float controlThreshold
Definition: uStepperS.h:738
uStepperS::stop
void stop(bool mode=HARD)
Stop the motor.
Definition: uStepperS.cpp:486
uStepperS::encoder
uStepperEncoder encoder
Definition: uStepperS.h:285
RAMP_STAT
#define RAMP_STAT
Definition: uStepperDriver.h:69
uStepperDriver::updateCurrent
void updateCurrent(void)
Writes the current setting registers of the motor driver
Definition: uStepperDriver.cpp:153
uStepperDriver::current
uint8_t current
Definition: uStepperDriver.h:318
uStepperS::filterSpeedPos
void filterSpeedPos(posFilter_t *filter, int32_t steps)
Definition: uStepperS.cpp:503
uStepperS::getPidError
float getPidError(void)
This method returns the current PID error.
Definition: uStepperS.cpp:676
dropinCliSettings_t::checksum
uint8_t checksum
Definition: uStepperS.h:188
SD_MODE
#define SD_MODE
Definition: uStepperS.h:213
ENCODERDATATOSTEP
#define ENCODERDATATOSTEP
Definition: uStepperEncoder.h:39
uStepperS::setRPM
void setRPM(float rpm)
Set the velocity in rpm.
Definition: uStepperS.cpp:364
uStepperS::disableClosedLoop
void disableClosedLoop(void)
This method disables the closed loop mode until calling enableClosedLoop.
Definition: uStepperS.cpp:640
uStepperS::microSteps
uint16_t microSteps
Definition: uStepperS.h:715
uStepperS::iTerm
float iTerm
Definition: uStepperS.h:732
uStepperS::pidDisabled
volatile bool pidDisabled
Definition: uStepperS.h:736
uStepperS::parseCommand
void parseCommand(String *cmd)
This method is used for the dropinCli to take in user commands.
Definition: uStepperS.cpp:767
COOLBRAKE
#define COOLBRAKE
Definition: uStepperS.h:151
floatBytes_t::f
float f
Definition: uStepperS.h:168
uStepperS::moveToEnd
float moveToEnd(bool dir, float rpm=40.0, int8_t threshold=4)
Moves the motor to its physical limit, without limit switch.
Definition: uStepperS.cpp:645
uStepperS::setIntegral
void setIntegral(float I)
This method is used to change the PID integral parameter I.
Definition: uStepperS.cpp:752
uStepperS::RPMToStepsPerSecond
float RPMToStepsPerSecond
Definition: uStepperS.h:722
uStepperS::clearStall
void clearStall(void)
Clear the stallguard, reenabling the motor to return to its previous operation.
Definition: uStepperS.cpp:319
dropinCliSettings_t::invert
uint8_t invert
Definition: uStepperS.h:185
PULSEFILTERKP
#define PULSEFILTERKP
Definition: uStepperS.h:238
MOSI_ENC
#define MOSI_ENC
Definition: uStepperS.h:220
PWM_FREQ
#define PWM_FREQ(n)
Definition: uStepperDriver.h:77
uStepperS::init
void init(void)
Internal function to prepare the uStepperS in the constructor.
Definition: uStepperS.cpp:57
uStepperS::loadDropinSettings
bool loadDropinSettings(void)
Definition: uStepperS.cpp:1217
uStepperDriver::setPosition
void setPosition(int32_t position)
Set the motor position.
Definition: uStepperDriver.cpp:158
uStepperS::setDifferential
void setDifferential(float D)
This method is used to change the PID differential parameter D.
Definition: uStepperS.cpp:757
interrupt1
void interrupt1(void)
Used by dropin feature to take in enable signal.
Definition: uStepperS.cpp:527
dropinCliSettings_t::I
floatBytes_t I
Definition: uStepperS.h:183
posFilter_t::posError
float posError
Definition: uStepperS.h:198
uStepperS::setMaxVelocity
void setMaxVelocity(float velocity)
Set the maximum velocity of the stepper motor.
Definition: uStepperS.cpp:407
PWMCONF
#define PWMCONF
Definition: uStepperDriver.h:73
uStepperS::dropinSettingsCalcChecksum
uint8_t dropinSettingsCalcChecksum(dropinCliSettings_t *settings)
Definition: uStepperS.cpp:1245
uStepperS::enableClosedLoop
void enableClosedLoop(void)
This method reenables the closed loop mode after being disabled.
Definition: uStepperS.cpp:635
uStepperS::setup
void setup(uint8_t mode=NORMAL, uint16_t stepsPerRevolution=200, float pTerm=10.0, float iTerm=0.0, float dTerm=0.0, uint16_t dropinStepSize=16, bool setHome=true, uint8_t invert=0, uint8_t runCurrent=50, uint8_t holdCurrent=30)
Initializes the different parts of the uStepper S object.
Definition: uStepperS.cpp:154
uStepperS::interrupt0
friend void interrupt0(void)
Used by dropin feature to take in step pulses.
Definition: uStepperS.cpp:539
dropinCliSettings_t::holdCurrent
uint8_t holdCurrent
Definition: uStepperS.h:186
uStepperS::pid
float pid(float error)
Definition: uStepperS.cpp:681
uStepperEncoder::init
void init(uStepperS *_pointer)
Initiation of the encoder.
Definition: uStepperEncoder.cpp:48
uStepperDriver::enableStallguard
void enableStallguard(int8_t threshold, bool stopOnStall)
Definition: uStepperDriver.cpp:352
uStepperS::mode
volatile uint8_t mode
Definition: uStepperS.h:729
PWM_GRAD
#define PWM_GRAD(n)
Definition: uStepperDriver.h:78
uStepperDriver::getPosition
int32_t getPosition(void)
Returns the current position of the motor driver.
Definition: uStepperDriver.cpp:237
CS_ENCODER
#define CS_ENCODER
Definition: uStepperS.h:217
uStepperS::angleToStep
float angleToStep
Definition: uStepperS.h:713
uStepperS::stallStop
bool stallStop
Definition: uStepperS.h:751
uStepperS::maxVelocity
float maxVelocity
Definition: uStepperS.h:703
dropinCliSettings_t::runCurrent
uint8_t runCurrent
Definition: uStepperS.h:187
PWM_AMPL
#define PWM_AMPL(n)
Definition: uStepperDriver.h:79
XACTUAL
#define XACTUAL
Definition: uStepperDriver.h:52
uStepperS::saveDropinSettings
void saveDropinSettings(void)
Definition: uStepperS.cpp:1238
uStepperDriver::holdCurrent
uint8_t holdCurrent
Definition: uStepperDriver.h:319
ENCODERINTPERIOD
#define ENCODERINTPERIOD
Definition: uStepperS.h:237
uStepperS::setMaxAcceleration
void setMaxAcceleration(float acceleration)
Set the maximum acceleration of the stepper motor.
Definition: uStepperS.cpp:418
CS_DRIVER
#define CS_DRIVER
Definition: uStepperS.h:216
uStepperS::angleMoved
float angleMoved(void)
Get the angle moved from reference position in degrees.
Definition: uStepperS.cpp:481
uStepperS::driver
uStepperDriver driver
Definition: uStepperS.h:282
VELOCITYCONVERSION
#define VELOCITYCONVERSION
Definition: uStepperDriver.h:141
ENCODERINTFREQ
#define ENCODERINTFREQ
Definition: uStepperS.h:236
FREEWHEEL
#define FREEWHEEL(n)
Definition: uStepperDriver.h:75
uStepperS::invertDropinDir
void invertDropinDir(bool invert)
This method is used to invert the drop-in direction pin interpretation.
Definition: uStepperS.cpp:762
uStepperDriver::status
uint8_t status
Definition: uStepperDriver.h:311
uStepperS::stallThreshold
int8_t stallThreshold
Definition: uStepperS.h:748
uStepperS::currentPidSpeed
float currentPidSpeed
Definition: uStepperS.h:726
uStepperS::moveAngle
void moveAngle(float angle)
Makes the motor rotate a specific angle relative to the current position.
Definition: uStepperS.cpp:266
uStepperEncoder::setHome
void setHome(float initialAngle=0)
Define new reference(home) position.
Definition: uStepperEncoder.cpp:80
uStepperS::dropinSettings
dropinCliSettings_t dropinSettings
Definition: uStepperS.h:766
uStepperS::SPI
uint8_t SPI(uint8_t data)
Definition: uStepperS.cpp:396
DROPIN
#define DROPIN
Definition: uStepperS.h:226
posFilter_t
Struct for encoder velocity estimator.
Definition: uStepperS.h:196
uStepperDriver::setDirection
void setDirection(bool direction)
Definition: uStepperDriver.cpp:179
uStepperS::checkOrientation
void checkOrientation(float distance=10)
This method is used to check the orientation of the motor connector.
Definition: uStepperS.cpp:92
VELOCITY_MODE_POS
#define VELOCITY_MODE_POS
Definition: uStepperDriver.h:132
uStepperS::setHoldCurrent
void setHoldCurrent(double current)
Set motor hold current.
Definition: uStepperS.cpp:454
uStepperS::uStepperS
uStepperS()
Constructor of uStepper class.
Definition: uStepperS.cpp:34
uStepperS::moveToAngle
void moveToAngle(float angle)
Makes the motor rotate a specific angle relative to the current position.
Definition: uStepperS.cpp:283
uStepperS::dropinPrintHelp
void dropinPrintHelp()
This method is used to print the dropinCli menu explainer:
Definition: uStepperS.cpp:1198
uStepperS::setControlThreshold
void setControlThreshold(float threshold)
This method sets the control threshold for the closed loop position control in microsteps - i....
Definition: uStepperS.cpp:617
uStepperS::currentPidError
volatile float currentPidError
Definition: uStepperS.h:745
MOSI1
#define MOSI1
Definition: uStepperS.h:219
uStepperS::maxDeceleration
float maxDeceleration
Definition: uStepperS.h:710
uStepperS::setProportional
void setProportional(float P)
This method is used to change the PID proportional parameter P.
Definition: uStepperS.cpp:747
CLOCKFREQ
#define CLOCKFREQ
Definition: uStepperS.h:230
uStepperS::enablePid
void enablePid(void)
This method reenables the PID after being disabled.
Definition: uStepperS.cpp:621
uStepperS::invertPidDropinDirection
bool invertPidDropinDirection
Definition: uStepperS.h:711
uStepperDriver::setShaftDirection
void setShaftDirection(bool direction)
Set motor driver direction.
Definition: uStepperDriver.cpp:166
VACTUAL
#define VACTUAL
Definition: uStepperDriver.h:53
uStepperDriver::setDeceleration
void setDeceleration(uint32_t deceleration)
Set motor deceleration.
Definition: uStepperDriver.cpp:129
HARD
#define HARD
Definition: uStepperS.h:209
PWM_AUTOSCALE
#define PWM_AUTOSCALE(n)
Definition: uStepperDriver.h:76
CLOSEDLOOP
#define CLOSEDLOOP
Definition: uStepperS.h:227
DRV_ENN
#define DRV_ENN
Definition: uStepperS.h:212
uStepperS::setMaxDeceleration
void setMaxDeceleration(float deceleration)
Set the maximum deceleration of the stepper motor.
Definition: uStepperS.cpp:430
TIMER1_COMPA_vect
void TIMER1_COMPA_vect(void)
Definition: uStepperS.cpp:574
uStepperS::setCurrent
void setCurrent(double current)
Set motor output current.
Definition: uStepperS.cpp:441
uStepperDriver::setRampMode
void setRampMode(uint8_t mode)
Set motor driver to position mode or velocity mode.
Definition: uStepperDriver.cpp:189
uStepperDriver::xTarget
volatile int32_t xTarget
Definition: uStepperDriver.h:303
posFilter_t::posEst
float posEst
Definition: uStepperS.h:199
uStepperDriver::writeRegister
int32_t writeRegister(uint8_t address, uint32_t datagram)
Write a register of the motor driver.
Definition: uStepperDriver.cpp:274
interrupt0
void interrupt0(void)
Used by dropin feature to take in step pulses.
Definition: uStepperS.cpp:539