refactored stepper_plan -> planner (untested)

This commit is contained in:
Simen Svale Skogsrud 2011-02-11 00:34:53 +01:00
parent fc1c1b7e09
commit a4c64945e0
7 changed files with 26 additions and 31 deletions

View File

@ -31,7 +31,7 @@ DEVICE = atmega328p
CLOCK = 16000000
PROGRAMMER = -c avrisp2 -P usb
OBJECTS = main.o motion_control.o gcode.o spindle_control.o wiring_serial.o serial_protocol.o stepper.o \
eeprom.o settings.o stepper_plan.o
eeprom.o settings.o planner.o
# FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
FUSES = -U hfuse:w:0xd2:m -U lfuse:w:0xff:m
# update that line with this when programmer is back up:

2
main.c
View File

@ -21,7 +21,7 @@
#include <avr/io.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include "stepper_plan.h"
#include "planner.h"
#include "stepper.h"
#include "spindle_control.h"
#include "motion_control.h"

View File

@ -26,7 +26,7 @@
#include <stdlib.h>
#include "nuts_bolts.h"
#include "stepper.h"
#include "stepper_plan.h"
#include "planner.h"
#include "wiring_serial.h"
@ -41,7 +41,7 @@ void mc_dwell(uint32_t milliseconds)
// 1/feed_rate minutes.
void mc_line(double x, double y, double z, double feed_rate, int invert_feed_rate)
{
st_buffer_line(x, y, z, feed_rate, invert_feed_rate);
plan_buffer_line(x, y, z, feed_rate, invert_feed_rate);
}
// Execute an arc. theta == start angle, angular_travel == number of radians to go along the arc,

View File

@ -1,5 +1,5 @@
/*
stepper_plan.c - buffers movement commands and manages the acceleration profile plan
planner.c - buffers movement commands and manages the acceleration profile plan
Part of Grbl
Copyright (c) 2009-2011 Simen Svale Skogsrud
@ -54,7 +54,7 @@
#include <math.h>
#include <stdlib.h>
#include "stepper_plan.h"
#include "planner.h"
#include "nuts_bolts.h"
#include "stepper.h"
#include "settings.h"
@ -404,5 +404,6 @@ void plan_buffer_line(double x, double y, double z, double feed_rate, int invert
memcpy(position, target, sizeof(target)); // position[] = target[]
if (acceleration_manager_enabled) { planner_recalculate(); }
st_wake_up();
}

View File

@ -1,5 +1,5 @@
/*
stepper_plan.h - buffers movement commands and manages the acceleration profile plan
planner.h - buffers movement commands and manages the acceleration profile plan
Part of Grbl
Copyright (c) 2009-2011 Simen Svale Skogsrud
@ -21,8 +21,8 @@
// This module is to be considered a sub-module of stepper.c. Please don't include
// this file from any other module.
#ifndef stepper_plan_h
#define stepper_plan_h
#ifndef planner_h
#define planner_h
#include <inttypes.h>
@ -59,11 +59,9 @@ extern int32_t position[3];
// Initialize the motion plan subsystem
void plan_init();
// Do not call directly unless you are writing a motor driver. In current iteration this is called by
// st_buffer_line which also wakes up the stepper subsystem.
// Add a new linear movement to the buffer. steps_x, _y and _z is the signed, relative motion in
// steps. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
// calculation the caller must also provide the physical length of the line in millimeters.
// Add a new linear movement to the buffer. x, y and z is the signed, absolute target position in
// millimaters. Feed rate specifies the speed of the motion. If feed rate is inverted, the feed
// rate is taken to mean "frequency" and would complete the operation in 1/feed_rate minutes.
void plan_buffer_line(double x, double y, double z, double feed_rate, int invert_feed_rate);
// Call when the current block is no longer needed. Discards the block and makes the memory

View File

@ -30,7 +30,7 @@
#include <util/delay.h>
#include "nuts_bolts.h"
#include <avr/interrupt.h>
#include "stepper_plan.h"
#include "planner.h"
#include "wiring_serial.h"
@ -40,13 +40,14 @@
#define STEPPING_MASK (STEP_MASK | DIRECTION_MASK) // All stepping-related bits (step/direction)
#define LIMIT_MASK ((1<<X_LIMIT_BIT)|(1<<Y_LIMIT_BIT)|(1<<Z_LIMIT_BIT)) // All limit bits
#define MINIMUM_STEPS_PER_MINUTE 1200 // The stepper subsystem will never run slower than this, exept when sleeping
#define CYCLES_PER_ACCELERATION_TICK ((TICKS_PER_MICROSECOND*1000000)/ACCELERATION_TICKS_PER_SECOND)
#define MINIMUM_STEPS_PER_MINUTE 1200 // The stepper subsystem will never run slower than this, exept when sleeping
#define ENABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 |= (1<<OCIE1A)
#define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
static block_t *current_block; // A convenience pointer to the block currently being traced
static block_t *current_block; // A pointer to the block currently being traced
// Variables used by The Stepper Driver Interrupt
static uint8_t out_bits; // The next stepping-bits to be output
@ -81,6 +82,10 @@ static uint32_t trapezoid_adjusted_rate; // The current rate of step_events
void set_step_events_per_minute(uint32_t steps_per_minute);
void st_wake_up() {
ENABLE_STEPPER_DRIVER_INTERRUPT();
}
// Initializes the trapezoid generator from the current block. Called whenever a new
// block begins.
inline void trapezoid_generator_reset() {
@ -107,15 +112,6 @@ inline void trapezoid_generator_tick() {
}
}
// Add a new linear movement to the buffer. steps_x, _y and _z is the signed, relative motion in
// steps. Microseconds specify how many microseconds the move should take to perform. To aid acceleration
// calculation the caller must also provide the physical length of the line in millimeters.
void st_buffer_line(double x, double y, double z, double feed_rate, int invert_feed_rate) {
plan_buffer_line(x, y, z, feed_rate, invert_feed_rate);
// Ensure that block processing is running by enabling The Stepper Driver Interrupt
ENABLE_STEPPER_DRIVER_INTERRUPT();
}
void st_get_position_steps(int32_t (*vector)[3]) {
memcpy(vector, position, sizeof(position)); // vector[] = position[]
}

View File

@ -1,5 +1,5 @@
/*
stepper.h - stepper motor driver: executes motion plans using stepper motors
stepper.h - stepper motor driver: executes motion plans of planner.c using the stepper motors
Part of Grbl
Copyright (c) 2009-2011 Simen Svale Skogsrud
@ -27,10 +27,6 @@
// Initialize and start the stepper motor subsystem
void st_init();
// Add a new linear movement to the buffer. steps_x, _y and _z is the signed, relative motion in
// steps. Microseconds specify how many microseconds the move should take to perform.
void st_buffer_line(double x, double y, double z, double feed_rate, int invert_feed_rate);
// Copy the current absolute position in steps into the provided vector
void st_get_position_steps(int32_t (*vector)[3]);
@ -40,4 +36,8 @@ void st_synchronize();
// Execute the homing cycle
void st_go_home();
// The stepper subsystem goes to sleep when it runs out of things to execute. Call this
// to notify the subsystem that it is time to go to work.
void st_wake_up();
#endif