@@ -633,207 +633,6 @@ class Insist : public Pattern {
633633
634634};
635635
636- /* *************************************************************************/
637- /* !
638- @brief Vibrational pattern that works like a jack hammer. Vibrates on the
639- way in and pulls out smoothly in one go. Sensation sets the vibration
640- amplitude.
641- */
642- /* *************************************************************************/
643- class JackHammer : public Pattern {
644- public:
645- JackHammer (const char *str) : Pattern (str) {}
646- void setSensation (float sensation) {
647- _sensation = sensation;
648- _updateVibrationParameters ();
649- }
650- void setTimeOfStroke (float speed = 0 ) {
651- _timeOfStroke = 0.5 * speed;
652- _updateVibrationParameters ();
653- }
654- void setStroke (int stroke) {
655- _stroke = stroke;
656- _updateVibrationParameters ();
657- }
658- void setSpeedLimit (unsigned int maxSpeed, unsigned int maxAcceleration, unsigned int stepsPerMM) {
659- _maxSpeed = maxSpeed;
660- _maxAcceleration = maxAcceleration;
661- _stepsPerMM = stepsPerMM;
662- _updateVibrationParameters ();
663- }
664- motionParameter nextTarget (unsigned int index) {
665-
666- // revert position for the first move or if depth is exceeded
667- if (index == 0 || _nextMove.stroke >= _depth) {
668- // Return strokes goes at regular speed without vibration back to 0
669-
670- // maximum speed of the trapezoidal motion
671- _nextMove.speed = int (1.5 * _stroke/_timeOfStroke);
672- // acceleration to meet the profile
673- _nextMove.acceleration = int (3.0 * float (_nextMove.speed )/_timeOfStroke);
674- // all they way out to start
675- _nextMove.stroke = _depth - _stroke;
676- // we are done here
677- return _nextMove;
678- }
679-
680- // only calculate new position, if index has incremented: no mid-stroke update, as vibration is sufficiently fast
681- // except for return stroke if depth is exceeded.
682- if (index != _index) {
683-
684- // Vibration happens at maximum speed and acceleration of the machine
685- _nextMove.speed = _maxSpeed;
686- _nextMove.acceleration = _maxAcceleration;
687-
688- // odd stroke is shaking out
689- if (index % 2 ) {
690- _nextMove.stroke = _nextMove.stroke - _outVibrationDistance;
691- // even stroke is shaking in
692- } else {
693- // limit range to _depth
694- _nextMove.stroke = min ((_nextMove.stroke + _inVibrationDistance), _depth);
695- }
696- }
697- _index = index;
698- return _nextMove;
699- }
700- protected:
701- int _inVibrationDistance = 0 ;
702- int _outVibrationDistance = 0 ;
703- int _strokeInSpeed = 0 ;
704- void _updateVibrationParameters () {
705- // Hammering in takes considerable longer then backing off
706- _strokeInSpeed = int (0.5 * _stroke/_timeOfStroke);
707-
708- // Scale vibration amplitude from 1mm to 15mm with sensation
709- _inVibrationDistance = (int )fscale (-100.0 , 100.0 , (float )(3.0 *_stepsPerMM), (float )(25.0 *_stepsPerMM), _sensation, 0.0 );
710-
711- /* Calculate _outVibrationDistance to match with stroking speed
712- d_out = d_in * (v_vib - v_stroke) / (v_vib + v_stroke)
713- Formula neglects acceleration. Real timing will be slower due to finite acceleration & deceleration
714- */
715- _outVibrationDistance = _inVibrationDistance * (_maxSpeed - _strokeInSpeed) / (_maxSpeed + _strokeInSpeed);
716-
717- #ifdef DEBUG_PATTERN
718- Serial.println (" _maxSpeed: " + String (_maxSpeed) + " _strokeInSpeed: " + String (_strokeInSpeed) + " _strokeOutSpeed: " + String (int (1.5 * _stroke/_timeOfStroke)));
719- Serial.println (" inDist: " + String (_inVibrationDistance) + " outDist: " + String (_outVibrationDistance));
720- #endif
721-
722- }
723- };
724-
725- /* *************************************************************************/
726- /* !
727- @brief Simple vibrational overlay pattern. Vibrates on the way in and out.
728- Sensation sets the vibration amplitude.
729- */
730- /* *************************************************************************/
731- class StrokeNibbler : public Pattern {
732- public:
733- StrokeNibbler (const char *str) : Pattern (str) {}
734- void setSensation (float sensation) {
735- _sensation = sensation;
736- _updateVibrationParameters ();
737- }
738- void setTimeOfStroke (float speed = 0 ) {
739- _timeOfStroke = speed;
740- _updateVibrationParameters ();
741- }
742- void setStroke (int stroke) {
743- _stroke = stroke;
744- _updateVibrationParameters ();
745- }
746- void setSpeedLimit (unsigned int maxSpeed, unsigned int maxAcceleration, unsigned int stepsPerMM) {
747- _maxSpeed = maxSpeed;
748- _maxAcceleration = maxAcceleration;
749- _stepsPerMM = stepsPerMM;
750- _updateVibrationParameters ();
751- }
752- motionParameter nextTarget (unsigned int index) {
753-
754- // revert position to start for the first stroke
755- if (index == 0 ) {
756- // Set motion parameter
757- _nextMove.speed = int (1.5 * _stroke/_timeOfStroke);
758- _nextMove.acceleration = _maxAcceleration;
759-
760- // go to back position
761- _nextMove.stroke = _depth - _stroke;
762-
763- // store index and return
764- _index = index;
765- return _nextMove;
766- }
767-
768- // Vibration happens at maximum speed and acceleration of the machine
769- _nextMove.speed = _maxSpeed;
770- _nextMove.acceleration = _maxAcceleration;
771-
772- // check if we have reached one of the ends and reverse direction
773- if (_nextMove.stroke >= _depth) {
774- _returnStroke = true ;
775- }
776- if (_nextMove.stroke <= (_depth - _stroke)) {
777- _returnStroke = false ;
778- }
779-
780- // only calculate new position, if index has incremented: no mid-stroke update, as vibration is sufficiently fast
781- if (index != _index) {
782- if (_returnStroke == true ) {
783- // long vibration distance on way out
784- // odd stroke is shaking out
785- if (index % 2 ) {
786- // limit stroke to _depth - _stroke
787- _nextMove.stroke = max (_nextMove.stroke - _inVibrationDistance, _depth - _stroke);
788-
789- // even stroke is shaking in
790- } else {
791- _nextMove.stroke = _nextMove.stroke + _outVibrationDistance;
792- }
793-
794- } else {
795- // long vibration distance on way in
796- // odd stroke is shaking out
797- if (index % 2 ) {
798- _nextMove.stroke = _nextMove.stroke - _outVibrationDistance;
799-
800- // even stroke is shaking in
801- } else {
802- // limit stroke to _depth
803- _nextMove.stroke = min (_nextMove.stroke + _inVibrationDistance, _depth);
804- }
805- }
806- }
807-
808- _index = index;
809- return _nextMove;
810- }
811- protected:
812- bool _returnStroke = false ;
813- int _inVibrationDistance = 0 ;
814- int _outVibrationDistance = 0 ;
815- int _strokeSpeed = 0 ;
816- void _updateVibrationParameters () {
817- // Empirical factor to compensate time losses due to finite acceleration.
818- _strokeSpeed = int (5.0 * _stroke/_timeOfStroke);
819-
820- // Scale vibration amplitude from 3mm to 25mm with sensation
821- _inVibrationDistance = (int )fscale (-100.0 , 100.0 , (float )(3.0 *_stepsPerMM), (float )(25.0 *_stepsPerMM), _sensation, 0.0 );
822-
823- /* Calculate _outVibrationDistance to match with stroking speed
824- d_out = d_in * (v_vib - v_stroke) / (v_vib + v_stroke)
825- Formula neglects acceleration. Real timing will be slower due to finite acceleration & deceleration
826- */
827- _outVibrationDistance = _inVibrationDistance * (_maxSpeed - _strokeSpeed) / (_maxSpeed + _strokeSpeed);
828-
829- #ifdef DEBUG_PATTERN
830- Serial.println (" _maxSpeed: " + String (_maxSpeed) + " _strokeSpeed: " + String (_strokeSpeed));
831- Serial.println (" inDist: " + String (_inVibrationDistance) + " outDist: " + String (_outVibrationDistance));
832- #endif
833-
834- }
835- };
836-
837636/* *************************************************************************/
838637/*
839638 Array holding all different patterns. Please include any custom pattern here.
@@ -846,9 +645,7 @@ static Pattern *patternTable[] = {
846645 new HalfnHalf (" Half'n'Half" ),
847646 new Deeper (" Deeper" ),
848647 new StopNGo (" Stop'n'Go" ),
849- new Insist (" Insist" ),
850- new JackHammer (" Jack Hammer" ),
851- new StrokeNibbler (" Stroke Nibbler" )
648+ new Insist (" Insist" )
852649 // <-- insert your new pattern class here!
853650 };
854651
0 commit comments