diff --git a/implementation/software/.gitignore b/implementation/software/.gitignore new file mode 100644 index 0000000..36f971e --- /dev/null +++ b/implementation/software/.gitignore @@ -0,0 +1 @@ +bin/* diff --git a/implementation/software/Makefile b/implementation/software/Makefile new file mode 100644 index 0000000..b727add --- /dev/null +++ b/implementation/software/Makefile @@ -0,0 +1,10 @@ +APPLICATION = stepper + +BOARD ?= nucleo-f411re + +RIOTBASE ?= /home/wouter/Development/RIOT/ + +USEMODULE += xtimer + + +include $(RIOTBASE)/Makefile.include diff --git a/implementation/software/design/design_spec.md b/implementation/software/design/design_spec.md index 780b2a2..6e00c83 100644 --- a/implementation/software/design/design_spec.md +++ b/implementation/software/design/design_spec.md @@ -76,7 +76,6 @@ or [gb_math.h](https://github.com/gingerBill/gb/blob/master/gb_math.h) ## Kinematics struct - * ArmLengthA float * Motor motor1 * ArmLengthB float diff --git a/implementation/software/include/sensor.h b/implementation/software/include/sensor.h index 06e9df1..b009087 100644 --- a/implementation/software/include/sensor.h +++ b/implementation/software/include/sensor.h @@ -1,9 +1,11 @@ -#infdef SENSOR_H +#ifndef SENSOR_H #define SENSOR_H #include +#include +#include "periph/adc.h" #ifdef __cplusplus extern "C" { @@ -18,7 +20,7 @@ typedef struct { typedef struct { sensor_params_t p; -} sensor_t +} sensor_t; /** * @brief Initializes the sensor diff --git a/implementation/software/include/sensor_params.h b/implementation/software/include/sensor_params.h index d42e821..0bf20e2 100644 --- a/implementation/software/include/sensor_params.h +++ b/implementation/software/include/sensor_params.h @@ -6,7 +6,6 @@ extern "C" { #endif #include "board.h" -#include "adc.h" #ifndef SENSOR_PARAMS #define SENSOR_PARAMS \ diff --git a/implementation/software/include/stepper.h b/implementation/software/include/stepper.h index 1f6d83b..cde16f2 100644 --- a/implementation/software/include/stepper.h +++ b/implementation/software/include/stepper.h @@ -1,14 +1,25 @@ -#infdef STEPPER_H +#ifndef STEPPER_H #define STEPPER_H #include +#include "periph/gpio.h" +#include "periph/uart.h" +#include "sensor.h" #ifdef __cplusplus extern "C" { #endif +#define STEPPER_PARAM_VEL_MAX (25) +#define STEPPER_PARAM_ACC_MAX (200) +#define STEPPER_PARAM_VELOCITY_DEFAULT (0) +#define STEPPER_PARAM_MICROSTEP_DEFAULT (16) +#define STEPPER_PARAM_DIVISION_DEFAULT (200) +#define STEPPER_PARAM_ANGLE_DEFAULT (0) +#define STEPPER_PARAM_HOMING_ANGLE_DEFAULT (20) + /** * @brief Status and error codes */ @@ -25,14 +36,13 @@ extern "C" { STEPPER_REVERSE = 0x1, } stepper_direction_t; - /** * @brief Data structure holding the device parameters needed for initialization */ typedef struct { gpio_t step_pin; gpio_t dir_pin; - uint8_t addr; + uint8_t uart; uint8_t vel_max; uint8_t acc_max; uint8_t microstep; @@ -48,7 +58,7 @@ typedef struct { */ typedef struct { stepper_params_t p; -} stepper_t +} stepper_t; int stepper_init(stepper_t *dev, const stepper_params_t *params); diff --git a/implementation/software/include/stepper_params.h b/implementation/software/include/stepper_params.h index d628abf..0d0774c 100644 --- a/implementation/software/include/stepper_params.h +++ b/implementation/software/include/stepper_params.h @@ -7,53 +7,52 @@ extern "C" { #include "board.h" -#ifndef STEPPER_STEP_PIN -#define STEPPER_STEP_PIN GPIO_PIN(0, 0) +#ifndef STEPPER_PARAM_STEP_PIN +#define STEPPER_PARAM_STEP_PIN GPIO_PIN(0, 0) #endif -#ifndef STEPPER_DIR_PIN -#define STEPPER_DIR_PIN GPIO_PIn(0, 1) +#ifndef STEPPER_PARAM_DIR_PIN +#define STEPPER_PARAM_DIR_PIN GPIO_PIN(0, 1) #endif -#ifndef STEPPER_UART -#define STEPPER_UART UART(0) +#ifndef STEPPER_PARAM_UART +#define STEPPER_PARAM_UART UART_DEV(0) #endif -#ifndef STEPPER_VEL_MAX -#define STEPPER_VEL_MAX STEPPER_VEL_MAX_DEFAULT +#ifndef STEPPER_PARAM_VEL_MAX +#define STEPPER_PARAM_VEL_MAX STEPPER_PARAM_VEL_MAX_DEFAULT #endif -#ifndef STEPPER_ACC_MAX -#define STEPPER_ACC_MAX STEPPER_ACC_MAX_DEFAULT +#ifndef STEPPER_PARAM_ACC_MAX +#define STEPPER_PARAM_ACC_MAX STEPPER_PARAM_ACC_MAX_DEFAULT #endif -#ifndef STEPPER_MICROSTEP -#define STEPPER_MICROSTEP STEPPER_MICROSTEP_DEFAULT +#ifndef STEPPER_PARAM_MICROSTEP +#define STEPPER_PARAM_MICROSTEP STEPPER_PARAM_MICROSTEP_DEFAULT #endif -#ifndef STEPPER_DIVISION -#define STEPPER_DIVISION STEPPER_DIVISION_DEFAULT +#ifndef STEPPER_PARAM_DIVISION +#define STEPPER_PARAM_DIVISION STEPPER_PARAM_DIVISION_DEFAULT #endif -#ifndef STEPPER_ANGLE -#define STEPPER_ANGLE STEPPER_ANGLE_DEFAULT +#ifndef STEPPER_PARAM_ANGLE +#define STEPPER_PARAM_ANGLE STEPPER_PARAM_ANGLE_DEFAULT #endif -#ifndef STEPPER_VELOCITY -#define STEPPER_VELOCITY STEPPER_VELOCITY_DEFAULT +#ifndef STEPPER_PARAM_VELOCITY +#define STEPPER_PARAM_VELOCITY STEPPER_PARAM_VELOCITY_DEFAULT #endif -#ifndef STEPPER_SENSOR -#define STEPPER_SENSOR STEPPER_SENSOR_DEFAULT +#ifndef STEPPER_PARAM_SENSOR +#define STEPPER_PARAM_SENSOR STEPPER_PARAM_SENSOR_DEFAULT #endif -#ifndef STEPPER_HOMING_ANGLE -#define STEPPER_HOMING_ANGLE STEPPER_HOMING_ANGLE_DEFAULT +#ifndef STEPPER_PARAM_HOMING_ANGLE +#define STEPPER_PARAM_HOMING_ANGLE STEPPER_PARAM_HOMING_ANGLE_DEFAULT #endif #ifndef STEPPER_PARAMS #define STEPPER_PARAMS \ - { .step_pin = stepper_param_step_pin, \ - .dir_pin = stepper_param_dir_pin, \ - .addr = stepper_param_addr, \ - .vel_max = stepper_param_vel_max, \ - .acc_max = stepper_param_acc_max, \ - .microstep = stepper_param_microstep, \ - .division = stepper_param_division, \ - .angle = stepper_param_angle, \ - .velocity = stepper_param_velocity, \ - .sensor = stepper_param_sensor, \ - .homing_angle = stepper_param_homing_angle, \ + { .step_pin = STEPPER_PARAM_STEP_PIN, \ + .dir_pin = STEPPER_PARAM_DIR_PIN, \ + .uart = STEPPER_PARAM_UART, \ + .vel_max = STEPPER_PARAM_VEL_MAX, \ + .acc_max = STEPPER_PARAM_ACC_MAX, \ + .microstep = STEPPER_PARAM_MICROSTEP, \ + .division = STEPPER_PARAM_DIVISION, \ + .angle = STEPPER_PARAM_ANGLE, \ + .velocity = STEPPER_PARAM_VELOCITY, \ + .homing_angle = STEPPER_PARAM_HOMING_ANGLE, \ } #endif diff --git a/implementation/software/main.c b/implementation/software/main.c new file mode 100644 index 0000000..1731523 --- /dev/null +++ b/implementation/software/main.c @@ -0,0 +1,20 @@ +#include +#include + +#include "include/stepper.h" +#include "include/stepper_params.h" +#include "include/sensor.h" +#include "xtimer.h" + +int main(void) +{ + + stepper_t dev; + stepper_init(&dev, &stepper_params[0]); + while (1) { + xtimer_usleep(100000); + stepper_step(&dev, STEPPER_FORWARD); + } + + return 0; +} diff --git a/implementation/software/src/stepper.c b/implementation/software/stepper.c similarity index 53% rename from implementation/software/src/stepper.c rename to implementation/software/stepper.c index 5e5660e..770444d 100644 --- a/implementation/software/src/stepper.c +++ b/implementation/software/stepper.c @@ -2,19 +2,26 @@ #include "periph/gpio.h" #include "periph/uart.h" -#include "stepper.h" -#include "sensor.h" +#include "include/stepper.h" +#include "include/stepper_params.h" +#include "include/sensor.h" #define ENABLE_DEBUG (0) #include "debug.h" +#define STEP_PIN (dev->p.step_pin) +#define DIR_PIN (dev->p.dir_pin) + int stepper_init(stepper_t *dev, const stepper_params_t *params) { assert(dev && params); dev->p = *params; + gpio_init(STEP_PIN, GPIO_OUT); + + return STEPPER_OK; } @@ -22,6 +29,11 @@ int stepper_init(stepper_t *dev, const stepper_params_t *params) int stepper_step(stepper_t *dev, stepper_direction_t *direction) { + assert(direction); + gpio_toggle(STEP_PIN); + + return STEPPER_OK; +}