From: Joseph Coffland Date: Fri, 5 Jan 2018 06:35:34 +0000 (-0800) Subject: Updated test program X-Git-Url: https://git.buildbotics.com/?a=commitdiff_plain;h=8b099dfb68eae2b9c362921b125be7baee3a8507;p=bbctrl-firmware Updated test program --- diff --git a/src/avr/test/Makefile b/src/avr/test/Makefile index f3a56a1..9425111 100644 --- a/src/avr/test/Makefile +++ b/src/avr/test/Makefile @@ -1,7 +1,7 @@ TESTS=planner-test -PLANNER_TEST_SRC = gcode_parser.c gcode_expr.c machine.c status.c util.c axis.c report.c \ - command.c vars.c +PLANNER_TEST_SRC = status.c util.c axis.c report.c type.c exec.c base64.c \ + command.c commands.c vars.c state.c line.c PLANNER_TEST_SRC := $(patsubst %,../src/%,$(PLANNER_TEST_SRC)) PLANNER_TEST_SRC += $(wildcard ../src/plan/*.c) planner-test.c hal.c diff --git a/src/avr/test/hal.c b/src/avr/test/hal.c index 45ecfde..f4119df 100644 --- a/src/avr/test/hal.c +++ b/src/avr/test/hal.c @@ -28,13 +28,16 @@ #include "status.h" #include "spindle.h" #include "i2c.h" +#include "type.h" +#include "exec.h" #include "cpp_magic.h" -#include "plan/buffer.h" #include #include #include #include +#include +#include typedef uint8_t flags_t; @@ -58,8 +61,7 @@ typedef const char *pstring; #undef VAR -void command_mreset(int argc, char *argv[]) {} -void command_home(int argc, char *argv[]) {} +float square(float x) {return x * x;} void i2c_set_read_callback(i2c_read_cb_t cb) {} void print_status_flags(uint8_t flags) {DEBUG_CALL();} uint8_t hw_disable_watchdog() {return 0;} @@ -71,29 +73,19 @@ bool estop = false; void estop_trigger(stat_t reason) { DEBUG_CALL("%s", status_to_pgmstr(reason)); - mp_queue_dump(); estop = true; abort(); } -void estop_clear() { - DEBUG_CALL(); - estop = false; -} - - +void estop_clear() {DEBUG_CALL(); estop = false;} bool estop_triggered() {return estop;} -void hw_request_hard_reset() { - DEBUG_CALL(); - exit(0); -} +void hw_request_hard_reset() {DEBUG_CALL(); exit(0);} bool usart_tx_empty() {return true;} -bool usart_tx_full() {return false;} char *usart_readline() { @@ -107,69 +99,35 @@ char *usart_readline() { size_t n = 0; if (getline(&cmd, &n, stdin) == -1) { free(cmd); - cmd = 0; + return 0; } - return cmd; -} - - -void coolant_init() {} - - -void coolant_set_mist(bool x) { - DEBUG_CALL("%s", x ? "true" : "false"); -} + n = strlen(cmd); + while (n && isspace(cmd[n - 1])) cmd[--n] = 0; - -void coolant_set_flood(bool x) { - DEBUG_CALL("%s", x ? "true" : "false"); -} - - -void spindle_init() {} - - -void spindle_set_speed(float speed) { - DEBUG_CALL("%f", speed); -} - - -void spindle_set_mode(spindle_mode_t mode) { - DEBUG_CALL("%d", mode); + return cmd; } +void coolant_set_mist(bool x) {DEBUG_CALL("%s", x ? "true" : "false");} +void coolant_set_flood(bool x) {DEBUG_CALL("%s", x ? "true" : "false");} +void spindle_set_speed(float speed) {DEBUG_CALL("%f", speed);} void spindle_stop() {} -void motor_set_position(int motor, int32_t position) { - DEBUG_CALL("%d, %d", motor, position); -} - - -bool switch_is_active(int index) { - DEBUG_CALL("%d", index); - return false; +void st_set_position(int32_t position[AXES]) { + DEBUG_CALL("%d, %d, %d, %d", + position[0], position[1], position[2], position[3]); } -bool switch_is_enabled(int index) { - DEBUG_CALL("%d", index); - return false; -} +bool switch_is_active(int index) {DEBUG_CALL("%d", index); return false;} +bool switch_is_enabled(int index) {DEBUG_CALL("%d", index); return false;} static uint32_t ticks = 0; - - uint32_t rtc_get_time() {return ticks;} - - -bool rtc_expired(uint32_t t) { - return true; - return 0 <= (int32_t)(ticks - t); -} +bool rtc_expired(uint32_t t) {return true;} bool motor_is_enabled(int motor) {return true;} @@ -181,52 +139,40 @@ int motor_get_axis(int motor) {return motor;} #define STEP_ANGLE 1.8 -float motor_position[MOTORS] = {0}; - - -float motor_get_steps_per_unit(int motor) { - return 360 * MICROSTEPS / TRAVEL_REV / STEP_ANGLE; -} - - -int32_t motor_get_encoder(int motor) { - DEBUG_CALL("%d", motor); - return 0; -} - - -void motor_end_move(int motor) { - DEBUG_CALL("%d", motor); -} - - +int32_t motor_get_encoder(int motor) {DEBUG_CALL("%d", motor); return 0;} +void motor_end_move(int motor) {DEBUG_CALL("%d", motor);} int32_t motor_get_error(int motor) {return 0;} -int32_t motor_get_position(int motor) {return motor_position[motor];} bool st_is_busy() {return false;} -float square(float x) {return x * x;} - - stat_t st_prep_line(float time, const float target[]) { - DEBUG_CALL("%f, (%f, %f, %f, %f)", - time, target[0], target[1], target[2], target[3]); + ASSERT(isfinite(time)); - float p[MOTORS] = {0, 0, 0, 0}; + const float maxTarget = 1000; + for (int i = 0; i < 3; i++) { + ASSERT(isfinite(target[i])); + ASSERT(-maxTarget < target[i] && target[i] < maxTarget); + } - for (int i = 0; i < MOTORS; i++) { - motor_position[i] = target[i]; - p[i] = target[i] / motor_get_steps_per_unit(i); + static int32_t line = -1; + if (exec_get_line() != line) { + line = exec_get_line(); + printf("line=%d\n", line); } - printf("%0.10f, %0.10f, %0.10f, %0.10f\n", time, p[0], p[1], p[2]); + printf("%0.10f, %0.10f, %0.10f, %0.10f\n", + time, target[0], target[1], target[2]); return STAT_OK; } -void st_prep_dwell(float seconds) { - DEBUG_CALL("%f", seconds); -} +void st_prep_dwell(float seconds) {DEBUG_CALL("%f", seconds);} + + +// Command callbacks +stat_t command_estop(char *cmd) {DEBUG_CALL(); return STAT_OK;} +stat_t command_clear(char *cmd) {DEBUG_CALL(); return STAT_OK;} +stat_t command_jog(char *cmd) {DEBUG_CALL(); return STAT_OK;} diff --git a/src/avr/test/planner-test.c b/src/avr/test/planner-test.c index 3161da5..c68fab9 100644 --- a/src/avr/test/planner-test.c +++ b/src/avr/test/planner-test.c @@ -26,37 +26,35 @@ \******************************************************************************/ #include "axis.h" -#include "machine.h" #include "command.h" -#include "plan/arc.h" -#include "plan/planner.h" -#include "plan/exec.h" -#include "plan/state.h" +#include "exec.h" +#include "state.h" +#include "vars.h" +#include "report.h" #include #include int main(int argc, char *argv[]) { - mp_init(); // motion planning - machine_init(); // gcode machine axis_map_motors(); + exec_init(); // motion exec + vars_init(); // configuration variables + command_init(); stat_t status = STAT_OK; while (true) { - mach_arc_callback(); // arc generation runs - bool reading = !feof(stdin); - if (reading && mp_queue_get_room()) { - mp_state_callback(); - command_callback(); + report_callback(); - if (mp_queue_get_room()) continue; + if (reading) { + state_callback(); + if (command_callback()) continue; } - status = mp_exec_move(); + status = exec_next(); printf("EXEC: %s\n", status_to_pgmstr(status)); switch (status) { @@ -76,7 +74,7 @@ int main(int argc, char *argv[]) { if (!reading) break; } - printf("STATE: %s\n", mp_get_state_pgmstr(mp_get_state())); + printf("STATE: %s\n", state_get_pgmstr(state_get())); return 0; }