| @@ -0,0 +1 @@ | |||||
| bin/* | |||||
| @@ -0,0 +1,10 @@ | |||||
| APPLICATION = stepper | |||||
| BOARD ?= nucleo-f411re | |||||
| RIOTBASE ?= /home/wouter/Development/RIOT/ | |||||
| USEMODULE += xtimer | |||||
| include $(RIOTBASE)/Makefile.include | |||||
| @@ -76,7 +76,6 @@ or [gb_math.h](https://github.com/gingerBill/gb/blob/master/gb_math.h) | |||||
| ## Kinematics struct | ## Kinematics struct | ||||
| * ArmLengthA float | * ArmLengthA float | ||||
| * Motor motor1 | * Motor motor1 | ||||
| * ArmLengthB float | * ArmLengthB float | ||||
| @@ -1,9 +1,11 @@ | |||||
| #infdef SENSOR_H | |||||
| #ifndef SENSOR_H | |||||
| #define SENSOR_H | #define SENSOR_H | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include <limits.h> | |||||
| #include "periph/adc.h" | |||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
| extern "C" { | extern "C" { | ||||
| @@ -18,7 +20,7 @@ typedef struct { | |||||
| typedef struct { | typedef struct { | ||||
| sensor_params_t p; | sensor_params_t p; | ||||
| } sensor_t | |||||
| } sensor_t; | |||||
| /** | /** | ||||
| * @brief Initializes the sensor | * @brief Initializes the sensor | ||||
| @@ -6,7 +6,6 @@ extern "C" { | |||||
| #endif | #endif | ||||
| #include "board.h" | #include "board.h" | ||||
| #include "adc.h" | |||||
| #ifndef SENSOR_PARAMS | #ifndef SENSOR_PARAMS | ||||
| #define SENSOR_PARAMS \ | #define SENSOR_PARAMS \ | ||||
| @@ -1,14 +1,25 @@ | |||||
| #infdef STEPPER_H | |||||
| #ifndef STEPPER_H | |||||
| #define STEPPER_H | #define STEPPER_H | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include "periph/gpio.h" | |||||
| #include "periph/uart.h" | |||||
| #include "sensor.h" | |||||
| #ifdef __cplusplus | #ifdef __cplusplus | ||||
| extern "C" { | extern "C" { | ||||
| #endif | #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 | * @brief Status and error codes | ||||
| */ | */ | ||||
| @@ -25,14 +36,13 @@ extern "C" { | |||||
| STEPPER_REVERSE = 0x1, | STEPPER_REVERSE = 0x1, | ||||
| } stepper_direction_t; | } stepper_direction_t; | ||||
| /** | /** | ||||
| * @brief Data structure holding the device parameters needed for initialization | * @brief Data structure holding the device parameters needed for initialization | ||||
| */ | */ | ||||
| typedef struct { | typedef struct { | ||||
| gpio_t step_pin; | gpio_t step_pin; | ||||
| gpio_t dir_pin; | gpio_t dir_pin; | ||||
| uint8_t addr; | |||||
| uint8_t uart; | |||||
| uint8_t vel_max; | uint8_t vel_max; | ||||
| uint8_t acc_max; | uint8_t acc_max; | ||||
| uint8_t microstep; | uint8_t microstep; | ||||
| @@ -48,7 +58,7 @@ typedef struct { | |||||
| */ | */ | ||||
| typedef struct { | typedef struct { | ||||
| stepper_params_t p; | stepper_params_t p; | ||||
| } stepper_t | |||||
| } stepper_t; | |||||
| int stepper_init(stepper_t *dev, const stepper_params_t *params); | int stepper_init(stepper_t *dev, const stepper_params_t *params); | ||||
| @@ -7,53 +7,52 @@ extern "C" { | |||||
| #include "board.h" | #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 | #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 | #endif | ||||
| #ifndef STEPPER_UART | |||||
| #define STEPPER_UART UART(0) | |||||
| #ifndef STEPPER_PARAM_UART | |||||
| #define STEPPER_PARAM_UART UART_DEV(0) | |||||
| #endif | #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 | #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 | #endif | ||||
| #ifndef STEPPER_MICROSTEP | |||||
| #define STEPPER_MICROSTEP STEPPER_MICROSTEP_DEFAULT | |||||
| #ifndef STEPPER_PARAM_MICROSTEP | |||||
| #define STEPPER_PARAM_MICROSTEP STEPPER_PARAM_MICROSTEP_DEFAULT | |||||
| #endif | #endif | ||||
| #ifndef STEPPER_DIVISION | |||||
| #define STEPPER_DIVISION STEPPER_DIVISION_DEFAULT | |||||
| #ifndef STEPPER_PARAM_DIVISION | |||||
| #define STEPPER_PARAM_DIVISION STEPPER_PARAM_DIVISION_DEFAULT | |||||
| #endif | #endif | ||||
| #ifndef STEPPER_ANGLE | |||||
| #define STEPPER_ANGLE STEPPER_ANGLE_DEFAULT | |||||
| #ifndef STEPPER_PARAM_ANGLE | |||||
| #define STEPPER_PARAM_ANGLE STEPPER_PARAM_ANGLE_DEFAULT | |||||
| #endif | #endif | ||||
| #ifndef STEPPER_VELOCITY | |||||
| #define STEPPER_VELOCITY STEPPER_VELOCITY_DEFAULT | |||||
| #ifndef STEPPER_PARAM_VELOCITY | |||||
| #define STEPPER_PARAM_VELOCITY STEPPER_PARAM_VELOCITY_DEFAULT | |||||
| #endif | #endif | ||||
| #ifndef STEPPER_SENSOR | |||||
| #define STEPPER_SENSOR STEPPER_SENSOR_DEFAULT | |||||
| #ifndef STEPPER_PARAM_SENSOR | |||||
| #define STEPPER_PARAM_SENSOR STEPPER_PARAM_SENSOR_DEFAULT | |||||
| #endif | #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 | #endif | ||||
| #ifndef STEPPER_PARAMS | #ifndef STEPPER_PARAMS | ||||
| #define 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 | #endif | ||||
| @@ -0,0 +1,20 @@ | |||||
| #include <stdlib.h> | |||||
| #include <stdio.h> | |||||
| #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; | |||||
| } | |||||
| @@ -2,19 +2,26 @@ | |||||
| #include "periph/gpio.h" | #include "periph/gpio.h" | ||||
| #include "periph/uart.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) | #define ENABLE_DEBUG (0) | ||||
| #include "debug.h" | #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) | int stepper_init(stepper_t *dev, const stepper_params_t *params) | ||||
| { | { | ||||
| assert(dev && params); | assert(dev && params); | ||||
| dev->p = *params; | dev->p = *params; | ||||
| gpio_init(STEP_PIN, GPIO_OUT); | |||||
| return STEPPER_OK; | 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) | int stepper_step(stepper_t *dev, stepper_direction_t *direction) | ||||
| { | { | ||||
| assert(direction); | |||||
| gpio_toggle(STEP_PIN); | |||||
| return STEPPER_OK; | |||||
| } | |||||