yarf 0.1
Yet Another RepRap Firmware
Defines | Functions | Variables
src/input/commands.c File Reference

Implementation of g-code commands. More...

#include "commands.h"
#include "movement/planner.h"
#include "movement/block_handler.h"
#include "hardware/steppers.h"
#include "temperature/temperature.h"
#include "util/delays.h"
#include <math.h>
#include <stdbool.h>

Go to the source code of this file.

Defines

#define MIN_TEMP_C   0.0
 The lowest possible temperature that can be set for the nozzle and the print bed in degrees celcius.
#define MAX_TEMP_C   300.0
 The highest possible temperature that can be set for the nozzle and the print bed in degrees celcius.

Functions

static void ok (cmd_response_t *r)
 Initializes a cmd_reponse_t structure to be an 'OK' response.
static void invalid (cmd_response_t *r, char *info)
 Initializes a cmd_reponse_t structure to be an 'invalid' response.
static void temperatures (cmd_response_t *r, float t, float b)
 Initializes a cmd_reponse_t structure to be a 'temperatures' response.
static void coordinates (cmd_response_t *r, float x, float y, float z, float e)
 Initializes a cmd_reponse_t structure to be a 'coordinates' response.
void cmd_init ()
 Initializes the command component.
void cmd_controlled_move (cmd_response_t *r, float x, float y, float z, float e, float f)
 G1: Controlled move (buffered)
void cmd_set_units_inches (cmd_response_t *r)
 G20: Set Units to Inches.
void cmd_set_units_millimeters (cmd_response_t *r)
 G21: Set Units to Millimeters.
void cmd_move_to_origin (cmd_response_t *r, bool x, bool y, bool z)
 G28: Move to Origin (buffered)
void cmd_set_absolute_positioning (cmd_response_t *r)
 G90: Set to absolute positioning (unbuffered)
void cmd_set_relative_positioning (cmd_response_t *r)
 G91: Set to relative positioning (unbuffered)
void cmd_set_position (cmd_response_t *r, float x, float y, float z, float e)
 G92: Set Position.
void cmd_stop_idle_hold (cmd_response_t *r)
 M84: Stop idle hold (unbuffered)
static bool _is_valid_temperature (float c)
void cmd_set_extruder_temp_async (cmd_response_t *r, float c)
 M104: Set nozzle temperature (non-blocking)
void cmd_read_nozzle_and_printbed_temp (cmd_response_t *r)
 M105: Read extruder and printbed temperature.
void cmd_set_extruder_temp_sync (cmd_response_t *r, float c)
 M109: Set nozzle temperature (blocking)
void cmd_set_extruder_pwm (cmd_response_t *r, float s)
 M113: Set extruder PWM.
void cmd_get_position (cmd_response_t *r)
 M114: Get current position.
static void nozzle_temperature_wait (void)
 Waits for the nozzle temperature to have been reached.
static void printbed_temperature_wait (void)
 Waits for the print bed temperature to have been reached.
void cmd_wait (cmd_response_t *r)
 M116: Wait.
void cmd_set_printbed_temp_async (cmd_response_t *r, float c)
 M140: Set print bed temperature (non-blocking)
void cmd_select_tool (cmd_response_t *r, int tool)
 T: Select tool.

Variables

static bool use_relative_coordinates
 Whether the received coordinates are absolute or relative to the current position.
static speed_t last_feed_rate
 The feed rate of the last received movement.

Detailed Description

Implementation of g-code commands.

Author:
Pieter Agten (pieter.agten@gmail.com)
Date:
21 sep 2011

Definition in file commands.c.


Function Documentation

void cmd_controlled_move ( cmd_response_t r,
float  x,
float  y,
float  z,
float  e,
float  f 
)

G1: Controlled move (buffered)

Parameters:
rpointer to a cmd_response_t structure to write the response in
xdetermines the x coordinate of the destination position
ydetermines the y coordinate of the destination position
zdetermines the z coordinate of the destination position
edetermines the e coordinate of the destination position
fthe maximum speed of the movement in mm/min

Go in a straight line from the current position to the specified position, with a maximum feed rate of f. The x, y, z and e values are interpreted as absolute or relative coordinates, depending on whether G90 or G91 was executed.

Definition at line 153 of file commands.c.

void cmd_get_position ( cmd_response_t r)

M114: Get current position.

Parameters:
rpointer to a cmd_response_t structure to write the response in

Sends the current virtual x, y, z and e coordinates to the host.

Definition at line 301 of file commands.c.

void cmd_move_to_origin ( cmd_response_t r,
bool  x,
bool  y,
bool  z 
)

G28: Move to Origin (buffered)

Parameters:
rpointer to a cmd_response_t structure to write the response in
xwhether to move the x axis to its origin
ywhether to move the y axis to its origin
zwhether to move the z axis to its origin

This causes the machine to move one or more of its axes to its origin.

Definition at line 194 of file commands.c.

void cmd_read_nozzle_and_printbed_temp ( cmd_response_t r)

M105: Read extruder and printbed temperature.

Parameters:
rpointer to a cmd_response_t structure to write the response in

Reads the current temperature of the nozzle and the print bed in degrees celsius and sends them to the host.

Definition at line 271 of file commands.c.

void cmd_select_tool ( cmd_response_t r,
int  tool 
)

T: Select tool.

Parameters:
rpointer to a cmd_response_t structure to write the response in
tool0-based index of the tool to select

Selects the extruder to build with. Yarf only supports a single extruder, so this command will send an 'invalid' response when called with any tool index other than 0.

Definition at line 369 of file commands.c.

void cmd_set_absolute_positioning ( cmd_response_t r)

G90: Set to absolute positioning (unbuffered)

Parameters:
rpointer to a cmd_response_t structure to write the response in

Definition at line 209 of file commands.c.

void cmd_set_extruder_pwm ( cmd_response_t r,
float  s 
)

M113: Set extruder PWM.

Parameters:
rpointer to a cmd_response_t structure to write the response in
spwm value to which to set the extruder motor

This command is not supported because yarf only supports stepper motors, which do not require a PWM to be set. An 'invalid' response will be sent back to the host if the s value is anything but NAN.

Definition at line 288 of file commands.c.

void cmd_set_extruder_temp_async ( cmd_response_t r,
float  c 
)

M104: Set nozzle temperature (non-blocking)

Parameters:
rpointer to a cmd_response_t structure to write the response in
ctemperature in degrees celcius to which to set the nozzle
See also:
cmd_set_extruder_temp_sync
cmd_wait

Sets the temperature of the nozzle to the specified number of degrees and returns control to the host immediately (i.e. before that temperature has been reached by the extruder).

Definition at line 259 of file commands.c.

void cmd_set_extruder_temp_sync ( cmd_response_t r,
float  c 
)

M109: Set nozzle temperature (blocking)

Parameters:
rpointer to a cmd_response_t structure to write the response in
ctemperature in degrees celcius to which to set the nozzle
See also:
cmd_set_extruder_temp_async
cmd_wait

Sets the temperature of the nozzle to the specified number of degrees and waits for it to reach that temperature before sending a response back to the host.

Definition at line 278 of file commands.c.

void cmd_set_position ( cmd_response_t r,
float  x,
float  y,
float  z,
float  e 
)

G92: Set Position.

Parameters:
rpointer to a cmd_response_t structure to write the response in
xdetermines the x coordinate of the position
ydetermines the y coordinate of the position
zdetermines the z coordinate of the position
edetermines the e coordinate of the position

Sets the current virtual position to the specified position. The x, y, z and e values are interpreted as absolute or relative coordinates, depending on whether G90 or G91 was executed.

Definition at line 225 of file commands.c.

void cmd_set_printbed_temp_async ( cmd_response_t r,
float  c 
)

M140: Set print bed temperature (non-blocking)

Parameters:
rpointer to a cmd_response_t structure to write the response in
ctemperature in degrees celcius to which to set the print bed
See also:
cmd_wait

Sets the temperature of the print bed to the specified number of degrees and returns control to the host immediately (i.e. before that temperature has been reached by the extruder).

Definition at line 357 of file commands.c.

void cmd_set_relative_positioning ( cmd_response_t r)

G91: Set to relative positioning (unbuffered)

Parameters:
rpointer to a cmd_response_t structure to write the response in

Definition at line 217 of file commands.c.

void cmd_set_units_inches ( cmd_response_t r)

G20: Set Units to Inches.

Parameters:
rpointer to a cmd_response_t structure to write the response in

This command is not supported and will send an 'invalid' response when executed.

Definition at line 179 of file commands.c.

void cmd_set_units_millimeters ( cmd_response_t r)

G21: Set Units to Millimeters.

Parameters:
rpointer to a cmd_response_t structure to write the response in

Units from now on are in millimeters.

Definition at line 186 of file commands.c.

void cmd_stop_idle_hold ( cmd_response_t r)

M84: Stop idle hold (unbuffered)

Parameters:
rpointer to a cmd_response_t structure to write the response in

Stops the idle hold on all axes (including the extruder) by disabling their stepper motors.

Definition at line 245 of file commands.c.

void cmd_wait ( cmd_response_t r)

M116: Wait.

Parameters:
rpointer to a cmd_response_t structure to write the response in

Waits for the nozzle and print bed temperatures to reach their set values.

Definition at line 339 of file commands.c.

static void coordinates ( cmd_response_t r,
float  x,
float  y,
float  z,
float  e 
) [static]

Initializes a cmd_reponse_t structure to be a 'coordinates' response.

Parameters:
rpointer to the cmd_response_t structure to initialize
xx coordinate to put in the response
yy coordinate to put in the response
zz coordinate to put in the response
ee coordinate to put in the response

Definition at line 131 of file commands.c.

static void invalid ( cmd_response_t r,
char *  info 
) [static]

Initializes a cmd_reponse_t structure to be an 'invalid' response.

Parameters:
rpointer to the cmd_response_t structure to initialize
infopointer to a string which provides extra information on the reason of the failure

Definition at line 89 of file commands.c.

static void ok ( cmd_response_t r) [static]

Initializes a cmd_reponse_t structure to be an 'OK' response.

Parameters:
rpointer to the cmd_response_t structure to initialize

Definition at line 69 of file commands.c.

static void temperatures ( cmd_response_t r,
float  t,
float  b 
) [static]

Initializes a cmd_reponse_t structure to be a 'temperatures' response.

Parameters:
rpointer to the cmd_response_t structure to initialize
ttemperature value of the nozzle, in degrees celcius
btemperature value of the print bed, in degrees celcius

Definition at line 109 of file commands.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines