this->desired_adc_value = UNDEFINED;
// Settings
- this->readings_per_second = 50;
+ this->readings_per_second = 5;
this->r0 = 100000; // Stated resistance eg. 100K
this->t0 = 25 + 273.15; // Temperature at stated resistance, eg. 25C
double average_adc_reading(){
double total;
int j=0;
- for( int i = 0; i <= this->queue.size()-1; i++ ){
+ int reading_index = this->queue.head;
+ //this->kernel->serial->printf("[");
+ //for( int i = 0; i <= this->queue.size()-1; i++ ){
+ while( reading_index != this->queue.tail ){
j++;
//this->kernel->serial->printf("value:%f\r\n", *(this->queue.get_ref(i)) );
- total += *(this->queue.get_ref(i));
+ total += this->queue.buffer[reading_index];
+ //this->kernel->serial->printf("%.4f,", this->queue.buffer[reading_index]);
+ reading_index = this->queue.next_block_index( reading_index );
}
+ //this->kernel->serial->printf("]->[%4f=%4f]\r\n", total/j, this->adc_value_to_temperature(total/j));
//this->kernel->serial->printf("total:%f, size:%d \r\n", total, this->queue.size() );
return total / j;
}
+// double average_adc_reading(){
+// double total;
+// int j=0;
+// for( int i = 0; i <= this->queue.size()-1; i++ ){
+// j++;
+// //this->kernel->serial->printf("value:%f\r\n", *(this->queue.get_ref(i)) );
+// total += *(this->queue.get_ref(i));
+// }
+// //this->kernel->serial->printf("total:%f, size:%d \r\n", total, this->queue.size() );
+// return total / j;
+// }
+
AnalogIn* thermistor_pin;
Ticker* thermistor_read_ticker;
Ticker* debug_ticker;
// Get config
void Extruder::on_config_reload(void* argument){
- this->microseconds_per_step_pulse = 5; //this->kernel->config->value(microseconds_per_step_pulse_ckeckusm)->by_default(5)->as_number();
+ this->microseconds_per_step_pulse = this->kernel->config->value(microseconds_per_step_pulse_ckeckusm)->by_default(5)->as_number();
+ this->steps_per_millimeter = this->kernel->config->value(steps_per_millimeter_checksum )->by_default(1)->as_number();
+ this->feed_rate = this->kernel->config->value(default_feed_rate_checksum )->by_default(1)->as_number();
+ this->acceleration = this->kernel->config->value(acceleration_checksum )->by_default(1)->as_number();
}
// Computer extrusion speed based on parameters and gcode distance of travel
void Extruder::on_gcode_execute(void* argument){
Gcode* gcode = static_cast<Gcode*>(argument);
- //this->kernel->serial->printf("e: %s\r\n", gcode->command.c_str() );
+ this->kernel->serial->printf("e: %s\r\n", gcode->command.c_str() );
// Absolute/relative mode
if( gcode->has_letter('M')){
this->solo_mode = true;
this->travel_distance = extrusion_distance;
this->travel_ratio = 0.0;
+ if( gcode->has_letter('F') ){
+ this->feed_rate = gcode->get_value('F');
+ }
}else{
this->solo_mode = false;
this->travel_ratio = extrusion_distance / gcode->millimeters_of_travel;
this->current_block = block;
this->start_position = this->target_position;
this->target_position = this->start_position + this->travel_distance ;
- //this->kernel->serial->printf("bb: target_position: %f, travel_distance:%f \r\n", this->target_position, this->travel_distance );
+ this->kernel->serial->printf("bb: target_position: %f, travel_distance:%f, current_position:%f \r\n", this->target_position, this->travel_distance, this->current_position );
this->on_speed_change(this);
}
if( fabs(this->travel_ratio) > 0.001 ){
this->current_block = block;
this->start_position = this->target_position;
this->target_position = this->start_position + ( this->current_block->millimeters * this->travel_ratio );
+ this->kernel->serial->printf("bb: target_position: %f, travel_ratio:%f, current_position:%f \r\n", this->target_position, this->travel_ratio, this->current_position );
this->on_speed_change(this);
}
void Extruder::on_block_end(void* argument){
Block* block = static_cast<Block*>(argument);
+ this->kernel->serial->printf("cc: target_position: %f, travel_ratio:%f, travel_distance:%f, current_position:%f \r\n", this->target_position, this->travel_ratio, this->travel_distance, this->current_position );
this->current_block = NULL;
}
double adjusted_speed = nominal_extrusion_speed * stepper_rate_ratio;
// Set timer
- if((adjusted_speed*1400) < 1 ){
+ if((adjusted_speed*this->steps_per_millimeter) < 1 ){
return;
}
- LPC_TIM1->MR0 = ((SystemCoreClock/4))/(adjusted_speed*1400);
+ LPC_TIM1->MR0 = ((SystemCoreClock/4))/(adjusted_speed*this->steps_per_millimeter);
if( LPC_TIM1->MR0 < 300 ){
this->kernel->serial->printf("tim1mr0 %d, adjusted_speed: %f\r\n", LPC_TIM1->MR0, adjusted_speed );
LPC_TIM1->MR0 = 300;
if( fabs(this->travel_distance) > 0.001 ){
// Set timer
- LPC_TIM1->MR0 = ((SystemCoreClock/4))/int(floor(1.6*1400));
+ LPC_TIM1->MR0 = ((SystemCoreClock/4))/int(floor((this->feed_rate/60)*this->steps_per_millimeter));
// In case we are trying to set the timer to a limit it has already past by
if( LPC_TIM1->TC >= LPC_TIM1->MR0 ){
//if( fabs( this->current_position - this->target_position ) >= 0.001 ){
if( ( this->current_position < this->target_position && this->direction == 1 ) || ( this->current_position > this->target_position && this->direction == -1 ) ){
- this->current_position += (double(double(1)/double(1400)))*double(this->direction);
+ this->current_position += (double(double(1)/double(1100)))*double(this->direction);
this->dir_pin = ((this->direction > 0) ? 0 : 1);
this->step_pin = 1;
}else{