Hi Forum.
@luni from teensyStep
Please excuse me my ignorance.
Having no technical background and totally no programming experience.
Just a musician trying to engineer something useful. (i.e. grinding a bassoon reed. For reference a bassoon sounds like this: https://www.youtube.com/watch?v=ldMz94OGbIM)
The situation:
Using following stepper/servo motor: https://shop.cnc-technics.de/Integrated-Servo-Motor-36VDC-JMC-iHSV57-30-18-36-62-126.html
(and the same problem arises with the other stepper motor I have for testing: https://shop.cnc-technics.de/IHSS60-36-30-31-2phase-Hybrid-3Nm-Closed-Loop-Schrittmotor-39-40-172.html
Using a teensy 3.2 custom pcb from the same shop.
Searched online and offline for a way to advance and reverse the given motor using following basic code:
The motor.setTargetAbs(10000) advances the motor clock-wise.
I would excpect the statement "motor.setTargetAbs(-10000) to go counter-clockwise.
Hower the motor just keeps advancing.
In a more extended example, the motor.getPosition() before and after advancing gives a correct position but the motor is not physically reversing direction.
Need some desperate help for this.
@luni from teensyStep
Please excuse me my ignorance.
Having no technical background and totally no programming experience.
Just a musician trying to engineer something useful. (i.e. grinding a bassoon reed. For reference a bassoon sounds like this: https://www.youtube.com/watch?v=ldMz94OGbIM)
The situation:
Using following stepper/servo motor: https://shop.cnc-technics.de/Integrated-Servo-Motor-36VDC-JMC-iHSV57-30-18-36-62-126.html
(and the same problem arises with the other stepper motor I have for testing: https://shop.cnc-technics.de/IHSS60-36-30-31-2phase-Hybrid-3Nm-Closed-Loop-Schrittmotor-39-40-172.html
Using a teensy 3.2 custom pcb from the same shop.
Searched online and offline for a way to advance and reverse the given motor using following basic code:
Code:
#include "TeensyStep.h"
Stepper motor (2,15); // Basic stepper
StepControl controller; // Use default settings
void setup() {
motor.setMaxSpeed(66000);
motor.setAcceleration(60000);
}
void loop() {
Serial.println(millis()); // Just so I know something is happening
motor.setTargetAbs(10000); // motor advances clock wise
controller.move(motor);
delay(1000);
motor.setTargetAbs(-10000); // I should expect motor reversing counter-clock wise, but it still advances. Examening the currentposition hower gives the startposition (i.e. 0)
controller.move(motor);
delay(1000);
}
The motor.setTargetAbs(10000) advances the motor clock-wise.
I would excpect the statement "motor.setTargetAbs(-10000) to go counter-clockwise.
Hower the motor just keeps advancing.
In a more extended example, the motor.getPosition() before and after advancing gives a correct position but the motor is not physically reversing direction.
Need some desperate help for this.
Code:
#include "TeensyStep.h"
Stepper motor (2,15); // Basic stepper
// Stepper GrindingMtr (2, 15); // STEP pin: 2, DIR pin: 15
// Stepper RotateMtr (3, 14); // STEP pin: 3, DIR pin: 14
StepControl controller; // Use default settings
RotateControl rotator; // Use default settings for the GrindingController
const int rpm = 1600;
const int spindlePPR = 3200; // Hardware settings pulse per revolution (dip switches)
const int spindleSPR = 200; // steps per revolution (360/1.8°)
const int spindleAccel = 75000; // spindle acceleration
constexpr signed spindleSpeed = (rpm * spindlePPR) / 60; // steps per second
const int ledPin = 13; // Led pin
void setup()
{
Serial.begin(9600); // USB is always 12 or 480 Mbit/sec
while (!Serial);
// Define ledpin
pinMode(ledPin, OUTPUT);
// Parameter for the stepper motor
motor
.setAcceleration(spindleAccel)
.setMaxSpeed(spindleSpeed);
// H for HELP ME !
Serial.println("h for help");
}
void loop()
{
handleCommands();
}
void moveToPosition(int numberOfSteps)
{
int newPosition = motor.getPosition() + numberOfSteps;
if (!controller.isRunning() && !rotator.isRunning()) // skip move command if motor is running already
{
printTxt("Requested number of steps: ", numberOfSteps);
printTxt(" Resulting in (new) position : ", newPosition);
printTxt(" Moving from current position : ", motor.getPosition());
// motor.setStepPinPolarity(HIGH); // ????
motor.setTargetAbs(newPosition);
controller.move(motor);
Serial.println(" Started Motor movement.");
printTxt(" Motor now at position: ", motor.getPosition());
}
else
{
Serial.println("Ignored, Motor is already running");
}
}
void handleCommands()
{
if (Serial.available() > 0) // skip if the serial buffer is empty
{
char cmd = Serial.read(); // get one char from the buffer...
switch (cmd) // ... and analyze it
{
// ------------------
// move command
// ------------------
case 'p':
moveToPosition(0);
break;
case 'f':
moveToPosition(spindleSPR); // forward is ok
break;
// ------------------
// Reverse move
// ------------------
case 'r': // reverse direction
moveToPosition(-spindleSPR/2); // reverse is NOT OK. Position will be correct, but motor not spinning counter clock wise !
break;
// ------------------
// Start to rotate at the given rpm (using the rotator control)
// ------------------
case 'g':
{
if (!rotator.isRunning() && !controller.isRunning())
{
// Async so the rotation motor can do its stuff
printTxt("Grinding process started at speed : ", rotator.getCurrentSpeed());
rotator.rotateAsync(motor);
while(rotator.getCurrentSpeed() < spindleSpeed)
{
printTxt(" ", rotator.getCurrentSpeed());
delay(50);
}
Serial.println("Full speed achieved.");
printTxt("Rotator currentspeed (MAX): ", rotator.getCurrentSpeed());
}
else
{
printTxt("Command to grind ignored. Spindle already running", "");
}
}
break;
// ------------------
// Stop all movement
// ------------------
case 's': // stop command
if (controller.isRunning())
{
controller.stopAsync(); // initiate stopping procedure
Serial.println("Stopping motor");
}
if (rotator.isRunning())
{
rotator.stopAsync();
Serial.println("Stopping rotator");
}
break;
// ------------------
// Blink a while
// ------------------
case 'b':
Blink(5);
// ------------------
// HELP ME
// ------------------
case 'h': // help / usage command
case 'u':
Serial.println("\nUsage:");
Serial.println(" f: move Motor Forward.");
Serial.println(" r: move Motor Backward.");
Serial.println(" g: start grinding process. Spindle up to speed.");
Serial.println(" p: go to position 0.");
Serial.println(" --------------------------------------------");
Serial.println(" s: stop motor.");
Serial.println(" --------------------------------------------");
Serial.println(" b: blink the led.");
Serial.println(" h: display this help.");
break;
default:
break;
}
}
}
void printTxt(String t1, String t2)
{
Serial.print(t1);
Serial.println(t2);
}
void Blink(int numberOfTimes)
{
if (numberOfTimes <= 0) numberOfTimes = 1;
for (int i = 0; i < numberOfTimes; i++)
{
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for half a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for half a second
}
}
Last edited: