yarf 0.1
Yet Another RepRap Firmware
|
00001 /* 00002 * advance.h 00003 * 00004 * Copyright 2011 Pieter Agten 00005 * 00006 * This file is part of Yarf. 00007 * 00008 * Yarf is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * Yarf is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with Yarf. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 00161 #ifndef ADVANCE_H 00162 #define ADVANCE_H 00163 00164 #if ADVANCE_ALGORITHM 00165 00166 #include "yarf.h" 00167 #include "block.h" 00168 #include "util/math.h" 00169 #include "util/fixed_point.h" 00170 00179 #define EXTRUDER_HZ (2.0*E_MAX_ADVANCE_SPEED*E_STEPS_PER_MM/60.0) 00180 00184 #define EXTRUDER_TIMER_TICKS ((unsigned int)lround(F_CPU/8/EXTRUDER_HZ)) 00185 00189 #define FILAMENT_INPUT_AREA_SQUARED (FILAMENT_INPUT_AREA*FILAMENT_INPUT_AREA) 00190 00193 #define FILAMENT_OUTPUT_AREA_SQUARED (FILAMENT_OUTPUT_AREA*FILAMENT_OUTPUT_AREA) 00194 00199 #define ADVANCE_CONSTANT (FILAMENT_DENSITY * FILAMENT_INPUT_AREA * \ 00200 (FILAMENT_INPUT_AREA_SQUARED - FILAMENT_OUTPUT_AREA_SQUARED) / \ 00201 (2.0 * EXTRUDER_K * FILAMENT_OUTPUT_AREA_SQUARED)) 00202 00211 #define ADVANCE_MULTIPLIER_E (ADVANCE_CONSTANT * E_STEPS_PER_MM_IN) 00212 00222 #define ADVANCE_MULTIPLIER_O (ADVANCE_CONSTANT * E_STEPS_PER_MM_OUT) 00223 // ADVANCE_MULTIPLIER should be between about 0.1 - 10, so will fit in a 00224 // fxp16u16 00225 00231 #define ADVANCE_DEPRIME_STEPS lround(ADVANCE_DEPRIME_MM_OUT * E_STEPS_PER_MM_OUT) 00232 00242 inline float 00243 advance_get_multiplier(block_t *b) // about 5e+09 00244 { 00245 // TODO: use fixed point math 00246 #if ADVANCE_BASE_FEEDRATE_E 00247 return MAX(fsquare(b->mm_ticks_per_step_min) * b->direction[E_AXIS] * ADVANCE_MULTIPLIER_E, 0.0); 00248 #else 00249 return MAX(fsquare(b->mm_ticks_per_step_min) * ADVANCE_MULTIPLIER_O, 0.0); 00250 #endif 00251 } 00252 00262 inline int32_t 00263 advance_get_value(block_t *b) 00264 { 00265 if (b->use_advance) { 00266 // TODO: use fixed point math 00267 float advance = b->advance_multiplier/fsquare(fxp16u16_to_float(b->timer_ticks)); 00268 return (int32_t)advance; 00269 } else { 00270 return -ADVANCE_DEPRIME_STEPS; 00271 } 00272 } 00273 00274 #endif 00275 00276 #endif //ADVANCE_H