From 515a25fbb845fb16cb509d742b16299b3eba4cf8 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Fri, 29 Oct 2021 12:10:12 +0200 Subject: [PATCH] industry/foc/*/foc_velocity.c: add methods to set the zero velocity and direction of the velocity --- include/industry/foc/fixed16/foc_velocity.h | 20 +++++++++++ include/industry/foc/float/foc_velocity.h | 20 +++++++++++ industry/foc/fixed16/foc_velocity.c | 37 +++++++++++++++++++++ industry/foc/float/foc_velocity.c | 37 +++++++++++++++++++++ 4 files changed, 114 insertions(+) diff --git a/include/industry/foc/fixed16/foc_velocity.h b/include/industry/foc/fixed16/foc_velocity.h index cde861d43..fdab3f13f 100644 --- a/include/industry/foc/fixed16/foc_velocity.h +++ b/include/industry/foc/fixed16/foc_velocity.h @@ -72,6 +72,14 @@ struct foc_velocity_ops_b16_s CODE int (*cfg)(FAR foc_velocity_b16_t *h, FAR void *cfg); + /* Zero */ + + CODE int (*zero)(FAR foc_velocity_b16_t *h); + + /* Direction */ + + CODE int (*dir)(FAR foc_velocity_b16_t *h, b16_t dir); + /* Run */ CODE int (*run)(FAR foc_velocity_b16_t *h, @@ -110,6 +118,18 @@ int foc_velocity_deinit_b16(FAR foc_velocity_b16_t *h); int foc_velocity_cfg_b16(FAR foc_velocity_b16_t *h, FAR void *cfg); +/**************************************************************************** + * Name: foc_velocity_zero_b16 + ****************************************************************************/ + +int foc_velocity_zero_b16(FAR foc_velocity_b16_t *h); + +/**************************************************************************** + * Name: foc_velocity_dir_b16 + ****************************************************************************/ + +int foc_velocity_dir_b16(FAR foc_velocity_b16_t *h, b16_t dir); + /**************************************************************************** * Name: foc_velocity_run_b16 ****************************************************************************/ diff --git a/include/industry/foc/float/foc_velocity.h b/include/industry/foc/float/foc_velocity.h index 67e20b958..221ca0ccb 100644 --- a/include/industry/foc/float/foc_velocity.h +++ b/include/industry/foc/float/foc_velocity.h @@ -72,6 +72,14 @@ struct foc_velocity_ops_f32_s CODE int (*cfg)(FAR foc_velocity_f32_t *h, FAR void *cfg); + /* Zero */ + + CODE int (*zero)(FAR foc_velocity_f32_t *h); + + /* Direction */ + + CODE int (*dir)(FAR foc_velocity_f32_t *h, float dir); + /* Run velocity handler */ CODE int (*run)(FAR foc_velocity_f32_t *h, @@ -110,6 +118,18 @@ int foc_velocity_deinit_f32(FAR foc_velocity_f32_t *h); int foc_velocity_cfg_f32(FAR foc_velocity_f32_t *h, FAR void *cfg); +/**************************************************************************** + * Name: foc_velocity_zero_f32 + ****************************************************************************/ + +int foc_velocity_zero_f32(FAR foc_velocity_f32_t *h); + +/**************************************************************************** + * Name: foc_velocity_dir_f32 + ****************************************************************************/ + +int foc_velocity_dir_f32(FAR foc_velocity_f32_t *h, float dir); + /**************************************************************************** * Name: foc_velocity_run_f32 ****************************************************************************/ diff --git a/industry/foc/fixed16/foc_velocity.c b/industry/foc/fixed16/foc_velocity.c index a567a3e49..6b68eb808 100644 --- a/industry/foc/fixed16/foc_velocity.c +++ b/industry/foc/fixed16/foc_velocity.c @@ -130,6 +130,43 @@ int foc_velocity_cfg_b16(FAR foc_velocity_b16_t *h, FAR void *cfg) return h->ops->cfg(h, cfg); } +/**************************************************************************** + * Name: foc_velocity_zero_b16 + * + * Description: + * Zero the FOC velocity handler (fixed16) + * + * Input Parameter: + * h - pointer to FOC velocity handler + * + ****************************************************************************/ + +int foc_velocity_zero_b16(FAR foc_velocity_b16_t *h) +{ + DEBUGASSERT(h); + + return h->ops->zero(h); +} + +/**************************************************************************** + * Name: foc_velocity_dir_b16 + * + * Description: + * Set the FOC velocity handler direction (fixed16) + * + * Input Parameter: + * h - pointer to FOC velocity handler + * dir - sensor direction (1 if normal -1 if inverted) + * + ****************************************************************************/ + +int foc_velocity_dir_b16(FAR foc_velocity_b16_t *h, b16_t dir) +{ + DEBUGASSERT(h); + + return h->ops->dir(h, dir); +} + /**************************************************************************** * Name: foc_velocity_run_b16 * diff --git a/industry/foc/float/foc_velocity.c b/industry/foc/float/foc_velocity.c index 615d925e6..9f5baca50 100644 --- a/industry/foc/float/foc_velocity.c +++ b/industry/foc/float/foc_velocity.c @@ -130,6 +130,43 @@ int foc_velocity_cfg_f32(FAR foc_velocity_f32_t *h, FAR void *cfg) return h->ops->cfg(h, cfg); } +/**************************************************************************** + * Name: foc_velocity_zero_f32 + * + * Description: + * Zero the FOC velocity handler (float32) + * + * Input Parameter: + * h - pointer to FOC velocity handler + * + ****************************************************************************/ + +int foc_velocity_zero_f32(FAR foc_velocity_f32_t *h) +{ + DEBUGASSERT(h); + + return h->ops->zero(h); +} + +/**************************************************************************** + * Name: foc_velocity_dir_f32 + * + * Description: + * Set the FOC velocity handler direction (float32) + * + * Input Parameter: + * h - pointer to FOC velocity handler + * dir - sensor direction (1 if normal -1 if inverted) + * + ****************************************************************************/ + +int foc_velocity_dir_f32(FAR foc_velocity_f32_t *h, float dir) +{ + DEBUGASSERT(h); + + return h->ops->dir(h, dir); +} + /**************************************************************************** * Name: foc_velocity_run_f32 *