#include "mbed.h"
#include "libs/Kernel.h"
#include "libs/utils.h"
+#include "libs/Pin.h"
#include <string>
using std::string;
if( this->found == false && this->default_set == true ){
return this->default_double;
}else{
- double result = atof(remove_non_number(value).c_str());
+ double result = atof(remove_non_number(this->value).c_str());
if( result == 0.0 && this->value.find_first_not_of("0.") != string::npos ){
error("config setting '%s' with value '%s' is not a valid number, please see http://smoothieware.org/configuring-smoothie\r\n", this->key.c_str(), this->value.c_str() );
}
return result;
}
+
+ }
+
+ std::string as_string(){
+ if( this->found == false && this->default_set == true ){
+ return this->default_string;
+ }else{
+ return this->value;
+ }
}
bool as_bool(){
return false;
}
}
+ }
+ Pin* as_pin(){
+ Pin* pin = new Pin();
+ pin->from_string(this->value);
+ return pin;
}
ConfigValue* by_default(double value){
return this;
}
+ ConfigValue* by_default(std::string value){
+ this->default_set = true;
+ this->default_string = value;
+ return this;
+ }
+
bool has_characters( string mask ){
if( this->value.find_first_of(mask) != string::npos ){ return true; }else{ return false; }
}
bool found;
bool default_set;
double default_double;
+ string default_string;
};
// Append a block to the queue, compute it's speed factors
void Planner::append_block( int target[], double feed_rate, double distance, double deltas[] ){
- // Do not append block with no movement
- //if( target[ALPHA_STEPPER] == this->position[ALPHA_STEPPER] && target[BETA_STEPPER] == this->position[BETA_STEPPER] && target[GAMMA_STEPPER] == this->position[GAMMA_STEPPER] ){ this->computing = false; return; }
-
-
-
// Stall here if the queue is ful
- //this->kernel->serial->printf("aaa\r\n");
while( this->kernel->player->queue.size() >= this->kernel->player->queue.capacity()-2 ){
wait_us(500);
}
- //this->kernel->serial->printf("bbb\r\n");
Block* block = this->kernel->player->new_block();
block->planner = this;
// Direction bits
block->direction_bits = 0;
- char direction_bits[3] = {this->kernel->stepper->alpha_dir_pin, this->kernel->stepper->beta_dir_pin, this->kernel->stepper->gamma_dir_pin};
for( int stepper=ALPHA_STEPPER; stepper<=GAMMA_STEPPER; stepper++){
- if( target[stepper] < position[stepper] ){ block->direction_bits |= (1<<direction_bits[stepper]); }
+ if( target[stepper] < position[stepper] ){ block->direction_bits |= (1<<stepper); }
}
// Number of steps for each stepper
NVIC_SetPriority(TIMER1_IRQn, 3);
LPC_TIM0->TCR = 1;
-
- // Step and Dir pins as outputs
- this->step_gpio_port->FIODIR |= this->step_mask;
- this->dir_gpio_port->FIODIR |= this->dir_mask;
-
}
// Get configuration from the config file
void Stepper::on_config_reload(void* argument){
- LPC_GPIO_TypeDef *gpios[5] ={LPC_GPIO0,LPC_GPIO1,LPC_GPIO2,LPC_GPIO3,LPC_GPIO4};
+
this->microseconds_per_step_pulse = this->kernel->config->value(microseconds_per_step_pulse_ckeckusm )->by_default(5 )->as_number();
this->acceleration_ticks_per_second = this->kernel->config->value(acceleration_ticks_per_second_checksum)->by_default(100 )->as_number();
this->minimum_steps_per_minute = this->kernel->config->value(minimum_steps_per_minute_checksum )->by_default(1200 )->as_number();
this->base_stepping_frequency = this->kernel->config->value(base_stepping_frequency_checksum )->by_default(100000)->as_number();
- this->step_gpio_port = gpios[(int)this->kernel->config->value(step_gpio_port_checksum )->by_default(0 )->as_number()];
- this->dir_gpio_port = gpios[(int)this->kernel->config->value(dir_gpio_port_checksum )->by_default(0 )->as_number()];
- this->alpha_step_pin = this->kernel->config->value(alpha_step_pin_checksum )->by_default(1 )->as_number();
- this->beta_step_pin = this->kernel->config->value(beta_step_pin_checksum )->by_default(2 )->as_number();
- this->gamma_step_pin = this->kernel->config->value(gamma_step_pin_checksum )->by_default(3 )->as_number();
- this->alpha_dir_pin = this->kernel->config->value(alpha_dir_pin_checksum )->by_default(4 )->as_number();
- this->beta_dir_pin = this->kernel->config->value(beta_dir_pin_checksum )->by_default(5 )->as_number();
- this->gamma_dir_pin = this->kernel->config->value(gamma_dir_pin_checksum )->by_default(6 )->as_number();
- this->step_mask = ( 1 << this->alpha_step_pin ) + ( 1 << this->beta_step_pin ) + ( 1 << this->gamma_step_pin );
- this->dir_mask = ( 1 << this->alpha_dir_pin ) + ( 1 << this->beta_dir_pin ) + ( 1 << this->gamma_dir_pin );
- this->step_bits[ALPHA_STEPPER ] = this->alpha_step_pin;
- this->step_bits[BETA_STEPPER ] = this->beta_step_pin;
- this->step_bits[GAMMA_STEPPER ] = this->gamma_step_pin;
- this->step_invert_mask = ( this->kernel->config->value( alpha_step_pin_checksum )->is_inverted() << this->alpha_step_pin ) +
- ( this->kernel->config->value( beta_step_pin_checksum )->is_inverted() << this->beta_step_pin ) +
- ( this->kernel->config->value( gamma_step_pin_checksum )->is_inverted() << this->gamma_step_pin );
- this->dir_invert_mask = ( this->kernel->config->value( alpha_dir_pin_checksum )->is_inverted() << this->alpha_dir_pin ) +
- ( this->kernel->config->value( beta_dir_pin_checksum )->is_inverted() << this->beta_dir_pin ) +
- ( this->kernel->config->value( gamma_dir_pin_checksum )->is_inverted() << this->gamma_dir_pin );
+ this->alpha_step_pin = this->kernel->config->value(alpha_step_pin_checksum )->by_default("1.21" )->as_pin()->as_output();
+ this->beta_step_pin = this->kernel->config->value(beta_step_pin_checksum )->by_default("1.23" )->as_pin()->as_output();
+ this->gamma_step_pin = this->kernel->config->value(gamma_step_pin_checksum )->by_default("1.22!" )->as_pin()->as_output();
+ this->alpha_dir_pin = this->kernel->config->value(alpha_dir_pin_checksum )->by_default("1.18" )->as_pin()->as_output();
+ this->beta_dir_pin = this->kernel->config->value(beta_dir_pin_checksum )->by_default("1.20" )->as_pin()->as_output();
+ this->gamma_dir_pin = this->kernel->config->value(gamma_dir_pin_checksum )->by_default("1.19" )->as_pin()->as_output();
// Set the Timer interval for Match Register 1,
LPC_TIM0->MR1 = (( SystemCoreClock/4 ) / 1000000 ) * this->microseconds_per_step_pulse;
if((LPC_TIM0->IR >> 1) & 1){
LPC_TIM0->IR |= 1 << 1;
// Clear step pins
- stepper->step_gpio_port->FIOSET = stepper->step_invert_mask & stepper->step_mask;
- stepper->step_gpio_port->FIOCLR = ~stepper->step_invert_mask & stepper->step_mask;
+ stepper->alpha_step_pin->set(0);
+ stepper->beta_step_pin->set(0);
+ stepper->gamma_step_pin->set(0);
}
if((LPC_TIM0->IR >> 0) & 1){
LPC_TIM0->IR |= 1 << 0;
// config_step_timer. It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
inline void Stepper::main_interrupt(){
- // TODO: Explain this magic
// Step dir pins first, then step pinse, stepper drivers like to know the direction before the step signal comes in
- // Clear dir pins
- this->dir_gpio_port->FIOSET = this->dir_invert_mask & this->dir_mask;
- this->dir_gpio_port->FIOCLR = ~ this->dir_invert_mask & this->dir_mask;
- // Set dir pins
- this->dir_gpio_port->FIOSET = ( this->out_bits ^ this->dir_invert_mask ) & this->dir_mask;
- this->dir_gpio_port->FIOCLR = ( ~ ( this->out_bits ^ this->dir_invert_mask ) ) & this->dir_mask;
- // Set step pins
- this->step_gpio_port->FIOSET = ( this->out_bits ^ this->step_invert_mask ) & this->step_mask;
- this->step_gpio_port->FIOCLR = ( ~ ( this->out_bits ^ this->step_invert_mask ) ) & this->step_mask;
+ this->alpha_dir_pin->set( ( this->out_bits >> 0 ) & 1 );
+ this->beta_dir_pin->set( ( this->out_bits >> 1 ) & 1 );
+ this->gamma_dir_pin->set( ( this->out_bits >> 2 ) & 1 );
+ this->alpha_step_pin->set( ( this->out_bits >> 3 ) & 1 );
+ this->beta_step_pin->set( ( this->out_bits >> 4 ) & 1 );
+ this->gamma_step_pin->set( ( this->out_bits >> 5 ) & 1 );
if( this->current_block != NULL ){
// Set bits for direction and steps
if( this->counters[stpr] > this->offsets[stpr] && this->stepped[stpr] < this->current_block->steps[stpr] ){
this->counters[stpr] -= this->offsets[stpr] ;
this->stepped[stpr]++;
- this->out_bits |= (1 << this->step_bits[stpr]);
+ this->out_bits |= (1 << (stpr+3) );
}
}
// If current block is finished, reset pointer