Skip to content

Commit

Permalink
rpm is now float #40
Browse files Browse the repository at this point in the history
  • Loading branch information
laurb9 committed Feb 3, 2019
1 parent 2fe6a8a commit af7501b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/BasicStepperDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BasicStepperDriver::BasicStepperDriver(short steps, short dir_pin, short step_pi
/*
* Initialize pins, calculate timings etc
*/
void BasicStepperDriver::begin(short rpm, short microsteps){
void BasicStepperDriver::begin(float rpm, short microsteps){
pinMode(dir_pin, OUTPUT);
digitalWrite(dir_pin, HIGH);

Expand All @@ -65,7 +65,7 @@ void BasicStepperDriver::begin(short rpm, short microsteps){
/*
* Set target motor RPM (1-200 is a reasonable range)
*/
void BasicStepperDriver::setRPM(short rpm){
void BasicStepperDriver::setRPM(float rpm){
if (this->rpm == 0){ // begin() has not been called (old 1.0 code)
begin(rpm, microsteps);
}
Expand Down Expand Up @@ -126,7 +126,7 @@ void BasicStepperDriver::rotate(double deg){
* Set up a new move (calculate and save the parameters)
*/
void BasicStepperDriver::startMove(long steps){
long speed;
float speed;
// set up new move
dir_state = (steps >= 0) ? HIGH : LOW;
last_action_end = 0;
Expand All @@ -137,9 +137,9 @@ void BasicStepperDriver::startMove(long steps){
case LINEAR_SPEED:
// speed is in [steps/s]
speed = rpm * motor_steps / 60;
// how many steps from 0 to target rpm
// how many microsteps from 0 to target rpm
steps_to_cruise = speed * speed * microsteps / (2 * profile.accel);
// how many steps are needed from target rpm to a full stop
// how many microsteps are needed from target rpm to a full stop
steps_to_brake = steps_to_cruise * profile.accel / profile.decel;
if (steps_remaining < steps_to_cruise + steps_to_brake){
// cannot reach max speed, will need to brake early
Expand Down
14 changes: 7 additions & 7 deletions src/BasicStepperDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* calculate the step pulse in microseconds for a given rpm value.
* 60[s/min] * 1000000[us/s] / microsteps / steps / rpm
*/
#define STEP_PULSE(steps, microsteps, rpm) (60*1000000L/steps/microsteps/rpm)
#define STEP_PULSE(steps, microsteps, rpm) (60.0*1000000L/steps/microsteps/rpm)

// don't call yield if we have a wait shorter than this
#define MIN_YIELD_MICROS 50
Expand Down Expand Up @@ -80,7 +80,7 @@ class BasicStepperDriver {
// tWAKE wakeup time, nSLEEP inactive to STEP (us)
static const int wakeup_time = 0;

short rpm = 0;
float rpm = 0;

/*
* Movement state
Expand Down Expand Up @@ -114,7 +114,7 @@ class BasicStepperDriver {
/*
* Initialize pins, calculate timings etc
*/
void begin(short rpm=60, short microsteps=1);
void begin(float rpm=60, short microsteps=1);
/*
* Set current microstep level, 1=full speed, 32=fine microstepping
* Returns new level or previous level if value out of range
Expand All @@ -129,12 +129,12 @@ class BasicStepperDriver {
/*
* Set target motor RPM (1-200 is a reasonable range)
*/
void setRPM(short rpm);
short getRPM(void){
void setRPM(float rpm);
float getRPM(void){
return rpm;
};
short getCurrentRPM(void){
return (short)(60*1000000L / step_pulse / microsteps / motor_steps);
float getCurrentRPM(void){
return (60.0*1000000L / step_pulse / microsteps / motor_steps);
}
/*
* Set speed profile - CONSTANT_SPEED, LINEAR_SPEED (accelerated)
Expand Down

0 comments on commit af7501b

Please sign in to comment.