yarf 0.1
Yet Another RepRap Firmware
|
The planner component translates movement g-code commands into blocks that represent a linear movement and places these blocks into a queue of blocks to be executed by the block handler component. More...
#include "planner.h"
#include "yarf.h"
#include "block.h"
#include "planner_queue.h"
#include "planner_lookahead.h"
#include "block_handler.h"
#include "advance.h"
#include "scheduling/realtime_timer.h"
#include "util/math.h"
#include "util/fixed_point.h"
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <util/atomic.h>
Go to the source code of this file.
Defines | |
#define | HOME_AXIS_CALIBRATION_MM_X 5 |
The number of millimeters the machine will back up on its X axis, after reaching its X min endstop during the first stage of homing. | |
#define | HOME_AXIS_CALIBRATION_MM_Y 5 |
The number of millimeters the machine will back up on its Y axis, after reaching its Y min endstop during the first stage of homing. | |
#define | HOME_AXIS_CALIBRATION_MM_Z 1 |
The number of millimeters the machine will back up on its Z axis, after reaching its Z min endstop during the first stage of homing. | |
#define | HOME_AXIS_CALIBRATION_SPEED_X 300 |
The speed in mm/min at which the machine will move its X axis, during the second stage of homing. | |
#define | HOME_AXIS_CALIBRATION_SPEED_Y 300 |
The speed in mm/min at which the machine will move its Y axis, during the second stage of homing. | |
#define | HOME_AXIS_CALIBRATION_SPEED_Z 50 |
The speed in mm/min at which the machine will move its Z axis, during the second stage of homing. | |
Functions | |
static int32_t | intersection_steps (speed_t entry_speed, speed_t exit_speed, float distance_mm, long nb_steps) |
Given that the machine starts a movement at a certain entry speed and that it needs to end this movement at a certain exit speed after a certain distance in millimeter and number of steps, this function returns the number of steps after which the machine must end accelerating and start decelerating. | |
static fxp16u16_t | ticks_float_to_fxp16u16_safe (float ticks_fl) |
Returns the fixed point 16.16 representation of a (positive) floating point number, if the number is less than or equal to the half of the largest representable value in the fixed point representation. | |
static void | initialize_block (block_t *b, steps_t steps_x, steps_t steps_y, steps_t steps_z, steps_t steps_e, speed_t plateau_speed, void(*collision_handler)(uint8_t)) |
Initializes a number of basic parameters for a block, so it can be executed by the block handler. | |
static void | linear_movement_rel (steps_t steps_x, steps_t steps_y, steps_t steps_z, steps_t steps_e, speed_t plateau_speed, void(*collision_handler)(uint8_t)) |
Creates and initializes a block to perform a linear movement and places this block into the planning queue. | |
static void | collision (uint8_t collisions) |
Function which is used as the collision handler for all normal movements. | |
static void | homing_collision (uint8_t collisions) |
Function which is used as the collision handler for all homing movements. | |
void | plan_init (void) |
Initializes the planner component. | |
steps_t | plan_get_virtual_position (unsigned char axis) |
Returns the virtual position in number of steps from the origin for the specified axis. | |
void | plan_set_virtual_position_rel (steps_t x, steps_t y, steps_t z, steps_t e) |
Sets the virtual position of all axes. | |
void | plan_set_virtual_position_abs (steps_t x, steps_t y, steps_t z, steps_t e) |
Sets the virtual position of all axes. | |
void | plan_calculate_trapezoid (block_t *b, speed_t entry_speed, speed_t exit_speed) |
Sets a number of block parameters in order to have the block accelerate from a given entry speed at the start of the block and to have it decelerate to a given exit speed at the end of it. | |
void | plan_linear_movement_rel (steps_t steps_x, steps_t steps_y, steps_t steps_z, steps_t steps_e, speed_t plateau_speed) |
Adds a movement from the current virtual position to the specified position at the specified feed rate to the end of the planning queue. | |
void | plan_linear_movement_abs (steps_t dest_x, steps_t dest_y, steps_t dest_z, steps_t dest_e, speed_t plateau_speed) |
Adds a movement from the current virtual position to the specified position at the specified feed rate to the end of the planning queue. | |
void | plan_home_axes (bool x, bool y, bool z) |
Homes the specified axes. | |
Variables | |
static uint8_t | axis_homed |
Flags indicating which axes have been homed since boot. | |
static steps_t | virtual_position [NUM_AXES] |
The virtual position in steps of each axis. | |
static unsigned int | next_id |
The identifier number to use for the next block. |
The planner component translates movement g-code commands into blocks that represent a linear movement and places these blocks into a queue of blocks to be executed by the block handler component.
Definition in file planner.c.
static void collision | ( | uint8_t | collisions | ) | [static] |
static void homing_collision | ( | uint8_t | collisions | ) | [static] |
static void initialize_block | ( | block_t * | b, |
steps_t | steps_x, | ||
steps_t | steps_y, | ||
steps_t | steps_z, | ||
steps_t | steps_e, | ||
speed_t | plateau_speed, | ||
void(*)(uint8_t) | collision_handler | ||
) | [inline, static] |
Initializes a number of basic parameters for a block, so it can be executed by the block handler.
b | a pointer to the block to initialize |
steps_x | the number of steps the block needs to take in the x direction (can be negative) |
steps_y | the number of steps the block needs to take in the y direction (can be negative) |
steps_z | the number of steps the block needs to take in the z direction (can be negative) |
steps_e | the number of steps the block needs to take in the e direction (can be negative) |
plateau_speed | maximum speed of the block in mm/min |
collision_handler | a pointer to a function to be called when one of the endstop is hit during execution of the block |
After calling this method, the block is ready to be placed into the planning queue, to be executed by the block handler. The entry and exit speed of the block are set very conservatively to the minimum of the given plateau speed and the configured START_SPEED. These speeds can be increased by running the lookahead component after placing the block into the planning queue.
static int32_t intersection_steps | ( | speed_t | entry_speed, |
speed_t | exit_speed, | ||
float | distance_mm, | ||
long | nb_steps | ||
) | [inline, static] |
Given that the machine starts a movement at a certain entry speed and that it needs to end this movement at a certain exit speed after a certain distance in millimeter and number of steps, this function returns the number of steps after which the machine must end accelerating and start decelerating.
This function can be used to compute the intersection point between the acceleration slope and the deceleration slop for the case where the block trapezoid has no plateau:
speed ^ | + | /:\ | / : \ | / : + <-- exit speed entry speed --|-> + : | | | : | | +---|--+ | +------> intersection time |____________________________ time --> This function returns the nb of steps travelled at the intersection time. The easiest way to calculate this, is by using the classic formulas for uniform acceleration: V(t) = Vi + a*t s(t) = (Vi + Vf)*t/2 Where Vi is the entry speed in mm/min, Vf is the exit speed in mm/min, s is the displacement in mm and t is the time passed From the second equation, we get: t(s) = 2*s/(Vi+Vf) So V(s) = Vi + 2*a*s/(Vi+Vf) We can use this formula directly for the acceleration curve: Va(s) = Vi + 2*a/(Vi+Vf) * s And by shifting and mirroring it, we can also use it for the deceleration curve: Vd(s) = Vf + 2*a(Vi+Vf) * (l - s) Where l is the length in mm of the entire movement Now we can just solve for the intersection of Va and Vd, which gives us (after performing some substitutions and simplifications): s = (Vf² - Vi²)/(4*a) + l/2 All that's left is to convert s (which is in mm) to the number of linear steps. This can simply be done by multiplying by the average number of steps per mm of the movement: result = s * b/l = b * [(Vf² - Vi²)/(4*a*l) + 1/2] = b * [(Vf + Vi)(Vf - Vi)/(4*a*l) + 1/2] With b the total number of steps of the entire movement.
static void linear_movement_rel | ( | steps_t | steps_x, |
steps_t | steps_y, | ||
steps_t | steps_z, | ||
steps_t | steps_e, | ||
speed_t | plateau_speed, | ||
void(*)(uint8_t) | collision_handler | ||
) | [static] |
Creates and initializes a block to perform a linear movement and places this block into the planning queue.
The linear movement is specified by giving the number of steps to move in each direction. This function blocks if the planning queue is full.
steps_x | the number of steps to take in the x direction (can be negative) |
steps_y | the number of steps to take in the y direction (can be negative) |
steps_z | the number of steps to take in the z direction (can be negative) |
steps_e | the number of steps to take in the e direction (can be negative) |
plateau_speed | maximum speed of the block in mm/min |
collision_handler | a pointer to a function to be called when one of the endstop is hit during execution of the block |
If the lookahead component is enabled, it is called immediately after adding the new block to the queue, in order to optimize the block's entry speed and to reduce the jerkiness of the transitions between blocks. The machine's virtual position is updated to the position it will be in after this movement has been executed.
Sets a number of block parameters in order to have the block accelerate from a given entry speed at the start of the block and to have it decelerate to a given exit speed at the end of it.
These parameters are used by the block handler during execution of the block.
b | a pointer to the block for which to calculate the parameters |
entry_speed | the entry speed of the block in mm/min |
exit_speed | the exit speed of the block in mm/min |
steps_t plan_get_virtual_position | ( | unsigned char | axis | ) |
Returns the virtual position in number of steps from the origin for the specified axis.
The virtual position is the position the printer will be at when all pending blocks in the planning queue have been executed.
axis | the axis for which to get the virtual position. Valid values are X_AXIS, Y_AXIS, Z_AXIS and E_AXIS. |
void plan_home_axes | ( | bool | x, |
bool | y, | ||
bool | z | ||
) |
Homes the specified axes.
Homing an axis means moving it in the negative direction until it reaches its min endstop.
x | boolean indicating whether or not to home the x axis |
y | boolean indicating whether or not to home the y axis |
z | boolean indicating whether or not to home the z axis |
void plan_linear_movement_abs | ( | steps_t | dest_x, |
steps_t | dest_y, | ||
steps_t | dest_z, | ||
steps_t | dest_e, | ||
speed_t | plateau_speed | ||
) |
Adds a movement from the current virtual position to the specified position at the specified feed rate to the end of the planning queue.
The position arguments are interpreted as absolute positions in numbers of steps from the origin.
dest_x | the destination position of the x axis, in steps from the origin, must be within the bounds of the axis |
dest_y | the destination position of the y axis, in steps from the origin, must be within the bounds of the axis |
dest_z | the destination position of the z axis, in steps from the origin, must be within the bounds of the axis |
dest_e | the destination position of the e axis, in steps from the origin |
plateau_speed | maximum speed of the block in mm/min |
If any of the X, Y or Z axes is not homed when calling this movement, that axis is homed before making the movement.
If any of the destination parameters is out of bounds, the movement is not added to the planning queue (it is silently dropped).
If the lookahead component is enabled, it is called immediately after adding the new block to the queue, in order to optimize the block's entry speed and to reduce the jerkiness of the transitions between blocks. The machine's virtual position is updated to the position it will be in after this movement has been executed.
void plan_linear_movement_rel | ( | steps_t | steps_x, |
steps_t | steps_y, | ||
steps_t | steps_z, | ||
steps_t | steps_e, | ||
speed_t | plateau_speed | ||
) |
Adds a movement from the current virtual position to the specified position at the specified feed rate to the end of the planning queue.
The position arguments are interpreted as offsets in numbers of steps from the current virtual position.
steps_x | the number of steps to take in the x direction (can be negative), must not make the machine go out of bounds |
steps_y | the number of steps to take in the y direction (can be negative), must not make the machine go out of bounds |
steps_z | the number of steps to take in the z direction (can be negative), must not make the machine go out of bounds |
steps_e | the number of steps to take in the e direction (can be negative) |
plateau_speed | maximum speed of the block in mm/min |
If any of the X, Y or Z axes is not homed when calling this movement, that axis is homed before making the movement.
If any of the destination parameters would cause the machine to go out of bounds, the movement is not added to the planning queue (it is silently dropped).
If the lookahead component is enabled, it is called immediately after adding the new block to the queue, in order to optimize the block's entry speed and to reduce the jerkiness of the transitions between blocks. The machine's virtual position is updated to the position it will be in after this movement has been executed.
Sets the virtual position of all axes.
The arguments are interpreted as absolute positions in numbers of steps from the origin.
x | the new virtual x position in number of steps |
y | the new virtual x position in number of steps |
z | the new virtual x position in number of steps |
e | the new virtual x position in number of steps |
Sets the virtual position of all axes.
The arguments are interpreted as offsets in numbers of steps relative to the current virtual position.
x | the number of steps to add to the virtual x position |
y | the number of steps to add to the virtual y position |
z | the number of steps to add to the virtual z position |
e | the number of steps to add to the virtual e position |
static fxp16u16_t ticks_float_to_fxp16u16_safe | ( | float | ticks_fl | ) | [inline, static] |
Returns the fixed point 16.16 representation of a (positive) floating point number, if the number is less than or equal to the half of the largest representable value in the fixed point representation.
If it is larger than half of the maximum value, the half of the maximum value is returned.
ticks_fl | the floating point number to convert |
This method is used to convert floating point timer ticks into a fixed point 16.16 representation, which can safely be multiplied by 2, without causing an overflow. This is because the block handler needs to multiply the current timer tick value by two in order to calculate the new timer tick value.
unsigned int next_id [static] |
steps_t virtual_position[NUM_AXES] [static] |