Skip to content

Commit

Permalink
pbio/imu: Rename from pbio/orientation_imu.
Browse files Browse the repository at this point in the history
Now that all pure orientation functions have been moved to pbio/geometry
only the orientation_imu functions remain. So we can just rename it imu,
and make it an independent module that can be enabled just like other
hardware modules.
  • Loading branch information
laurensvalk committed Apr 1, 2023
1 parent 3aa6a45 commit 52146cf
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 58 deletions.
2 changes: 1 addition & 1 deletion bricks/_common/sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
src/drivebase.c \
src/error.c \
src/geometry.c \
src/imu.c \
src/int_math.c \
src/integrator.c \
src/iodev.c \
Expand All @@ -211,7 +212,6 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
src/motor_process.c \
src/motor/servo_settings.c \
src/observer.c \
src/orientation.c \
src/parent.c \
src/protocol/lwp3.c \
src/protocol/nus.c \
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/doc/doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ PREDEFINED = \
PBIO_CONFIG_LIGHT=1 \
PBIO_CONFIG_MOTOR_PROCESS=1 \
PBIO_CONFIG_NUM_DRIVEBASES=1 \
PBIO_CONFIG_ORIENTATION_IMU=1 \
PBIO_CONFIG_IMU=1 \
PBIO_CONFIG_SERVO=1 \
PBIO_CONFIG_SERVO_NUM_DEV=4 \
PBIO_CONFIG_TACHO=1 \
Expand Down
42 changes: 21 additions & 21 deletions lib/pbio/include/pbio/orientation.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,65 +20,65 @@

#include <pbdrv/imu.h>

#if PBIO_CONFIG_ORIENTATION_IMU
#if PBIO_CONFIG_IMU

void pbio_orientation_imu_init(void);
void pbio_imu_init(void);

pbio_error_t pbio_orientation_set_base_orientation(pbio_geometry_xyz_t *x_axis, pbio_geometry_xyz_t *z_axis);

bool pbio_orientation_imu_is_stationary(void);
bool pbio_imu_is_stationary(void);

void pbio_orientation_imu_set_stationary_thresholds(float angular_velocity, float acceleration);
void pbio_imu_set_stationary_thresholds(float angular_velocity, float acceleration);

void pbio_orientation_imu_get_angular_velocity(pbio_geometry_xyz_t *values);
void pbio_imu_get_angular_velocity(pbio_geometry_xyz_t *values);

void pbio_orientation_imu_get_acceleration(pbio_geometry_xyz_t *values);
void pbio_imu_get_acceleration(pbio_geometry_xyz_t *values);

pbio_geometry_side_t pbio_orientation_imu_get_up_side(void);
pbio_geometry_side_t pbio_imu_get_up_side(void);

float pbio_orientation_imu_get_heading(void);
float pbio_imu_get_heading(void);

void pbio_orientation_imu_set_heading(float desired_heading);
void pbio_imu_set_heading(float desired_heading);

void pbio_orientation_imu_get_heading_scaled(pbio_angle_t *heading, int32_t ctl_steps_per_degree);
void pbio_imu_get_heading_scaled(pbio_angle_t *heading, int32_t ctl_steps_per_degree);

#else // PBIO_CONFIG_ORIENTATION_IMU
#else // PBIO_CONFIG_IMU

static inline void pbio_orientation_imu_init(void) {
static inline void pbio_imu_init(void) {
}

static inline pbio_error_t pbio_orientation_set_base_orientation(pbio_geometry_xyz_t *x_axis, pbio_geometry_xyz_t *z_axis) {
return PBIO_ERROR_NOT_IMPLEMENTED;
}

static inline bool pbio_orientation_imu_is_stationary(void) {
static inline bool pbio_imu_is_stationary(void) {
return false;
}

static inline void pbio_orientation_imu_set_stationary_thresholds(float angular_velocity, float acceleration) {
static inline void pbio_imu_set_stationary_thresholds(float angular_velocity, float acceleration) {
}

static inline void pbio_orientation_imu_get_angular_velocity(pbio_geometry_xyz_t *values) {
static inline void pbio_imu_get_angular_velocity(pbio_geometry_xyz_t *values) {
}

static inline void pbio_orientation_imu_get_acceleration(pbio_geometry_xyz_t *values) {
static inline void pbio_imu_get_acceleration(pbio_geometry_xyz_t *values) {
}

static inline pbio_geometry_side_t pbio_orientation_imu_get_up_side(void) {
static inline pbio_geometry_side_t pbio_imu_get_up_side(void) {
return PBIO_GEOMETRY_SIDE_TOP;
}

static inline float pbio_orientation_imu_get_heading(void) {
static inline float pbio_imu_get_heading(void) {
return 0.0f;
}

static inline void pbio_orientation_imu_set_heading(float desired_heading) {
static inline void pbio_imu_set_heading(float desired_heading) {
}

static inline void pbio_orientation_imu_get_heading_scaled(pbio_angle_t *heading, int32_t ctl_steps_per_degree) {
static inline void pbio_imu_get_heading_scaled(pbio_angle_t *heading, int32_t ctl_steps_per_degree) {
}

#endif // PBIO_CONFIG_ORIENTATION_IMU
#endif // PBIO_CONFIG_IMU

#endif // _PBIO_ORIENTATION_H_

Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/city_hub/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#define PBIO_CONFIG_DCMOTOR (1)
#define PBIO_CONFIG_DCMOTOR_NUM_DEV (2)
#define PBIO_CONFIG_DRIVEBASE_SPIKE (0)
#define PBIO_CONFIG_IMU (0)
#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_ORIENTATION_IMU (0)
#define PBIO_CONFIG_SERVO (1)
#define PBIO_CONFIG_SERVO_NUM_DEV (2)
#define PBIO_CONFIG_SERVO_EV3_NXT (0)
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/essential_hub/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#define PBIO_CONFIG_DCMOTOR (1)
#define PBIO_CONFIG_DCMOTOR_NUM_DEV (2)
#define PBIO_CONFIG_DRIVEBASE_SPIKE (1)
#define PBIO_CONFIG_IMU (1)
#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_LIGHT_MATRIX (0)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_ORIENTATION_IMU (1)
#define PBIO_CONFIG_SERVO (1)
#define PBIO_CONFIG_SERVO_NUM_DEV (2)
#define PBIO_CONFIG_SERVO_EV3_NXT (0)
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/ev3dev_stretch/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#define PBIO_CONFIG_DCMOTOR_NUM_DEV (4)
#define PBIO_CONFIG_DRIVEBASE_SPIKE (0)
#define PBIO_CONFIG_EV3_INPUT_DEVICE (1)
#define PBIO_CONFIG_IMU (0)
#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_SERIAL (1)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_ORIENTATION_IMU (0)
#define PBIO_CONFIG_SERVO (1)
#define PBIO_CONFIG_SERVO_NUM_DEV (4)
#define PBIO_CONFIG_SERVO_EV3_NXT (1)
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/move_hub/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#define PBIO_CONFIG_DCMOTOR (1)
#define PBIO_CONFIG_DCMOTOR_NUM_DEV (4)
#define PBIO_CONFIG_DRIVEBASE_SPIKE (0)
#define PBIO_CONFIG_IMU (0)
#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LOGGER (0)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_ORIENTATION_IMU (0)
#define PBIO_CONFIG_SERVO (1)
#define PBIO_CONFIG_SERVO_NUM_DEV (4)
#define PBIO_CONFIG_SERVO_EV3_NXT (0)
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/nxt/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#define PBIO_CONFIG_DCMOTOR (1)
#define PBIO_CONFIG_DCMOTOR_NUM_DEV (3)
#define PBIO_CONFIG_DRIVEBASE_SPIKE (0)
#define PBIO_CONFIG_IMU (0)
#define PBIO_CONFIG_LIGHT (0)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_ORIENTATION_IMU (0)
#define PBIO_CONFIG_SERVO (1)
#define PBIO_CONFIG_SERVO_NUM_DEV (3)
#define PBIO_CONFIG_SERVO_EV3_NXT (1)
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/prime_hub/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#define PBIO_CONFIG_DCMOTOR (1)
#define PBIO_CONFIG_DCMOTOR_NUM_DEV (6)
#define PBIO_CONFIG_DRIVEBASE_SPIKE (1)
#define PBIO_CONFIG_IMU (1)
#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_LIGHT_MATRIX (1)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_ORIENTATION_IMU (1)
#define PBIO_CONFIG_SERVO (1)
#define PBIO_CONFIG_SERVO_NUM_DEV (6)
#define PBIO_CONFIG_SERVO_EV3_NXT (0)
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/technic_hub/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#define PBIO_CONFIG_DCMOTOR (1)
#define PBIO_CONFIG_DCMOTOR_NUM_DEV (4)
#define PBIO_CONFIG_DRIVEBASE_SPIKE (0)
#define PBIO_CONFIG_IMU (1)
#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_ORIENTATION_IMU (1)
#define PBIO_CONFIG_SERVO (1)
#define PBIO_CONFIG_SERVO_NUM_DEV (4)
#define PBIO_CONFIG_SERVO_EV3_NXT (0)
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/test/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#define PBIO_CONFIG_DCMOTOR (1)
#define PBIO_CONFIG_DCMOTOR_NUM_DEV (6)
#define PBIO_CONFIG_DRIVEBASE_SPIKE (0)
#define PBIO_CONFIG_IMU (0)

#define PBIO_CONFIG_LIGHT (1)
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_LIGHT_MATRIX (1)

#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_MOTOR_PROCESS_AUTO_START (0)
#define PBIO_CONFIG_ORIENTATION_IMU (0)
#define PBIO_CONFIG_SERVO (1)
#define PBIO_CONFIG_SERVO_NUM_DEV (6)
#define PBIO_CONFIG_SERVO_EV3_NXT (1)
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/platform/virtual_hub/pbioconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define PBIO_CONFIG_LOGGER (1)
#define PBIO_CONFIG_LIGHT_MATRIX (0)
#define PBIO_CONFIG_MOTOR_PROCESS (1)
#define PBIO_CONFIG_ORIENTATION_IMU (0)
#define PBIO_CONFIG_IMU (0)
#define PBIO_CONFIG_SERVO (1)
#define PBIO_CONFIG_SERVO_NUM_DEV (6)
#define PBIO_CONFIG_SERVO_EV3_NXT (1)
Expand Down
2 changes: 1 addition & 1 deletion lib/pbio/src/drivebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static pbio_error_t pbio_drivebase_get_state_control(pbio_drivebase_t *db, pbio_

// Optionally use gyro to override the heading source for more accuracy.
if (db->use_gyro) {
pbio_orientation_imu_get_heading_scaled(&state_heading->position, db->control_heading.settings.ctl_steps_per_app_step);
pbio_imu_get_heading_scaled(&state_heading->position, db->control_heading.settings.ctl_steps_per_app_step);
}

return PBIO_SUCCESS;
Expand Down
28 changes: 14 additions & 14 deletions lib/pbio/src/orientation.c → lib/pbio/src/imu.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <pbio/orientation.h>
#include <pbio/util.h>

#if PBIO_CONFIG_ORIENTATION_IMU
#if PBIO_CONFIG_IMU

static pbdrv_imu_dev_t *imu_dev;
static pbdrv_imu_config_t *imu_config;
Expand Down Expand Up @@ -66,7 +66,7 @@ static void pbio_imu_handle_stationary_data_func(const int32_t *gyro_data_sum, c
/**
* Initializes global imu module.
*/
void pbio_orientation_imu_init(void) {
void pbio_imu_init(void) {
pbio_error_t err = pbdrv_imu_get_imu(&imu_dev, &imu_config);
if (err != PBIO_SUCCESS) {
return;
Expand Down Expand Up @@ -101,7 +101,7 @@ pbio_error_t pbio_orientation_set_base_orientation(pbio_geometry_xyz_t *front_si
return err;
}

pbio_orientation_imu_set_heading(0.0f);
pbio_imu_set_heading(0.0f);

return PBIO_SUCCESS;
}
Expand All @@ -111,7 +111,7 @@ pbio_error_t pbio_orientation_set_base_orientation(pbio_geometry_xyz_t *front_si
*
* @return True if it has been stationary for about a second, false if moving.
*/
bool pbio_orientation_imu_is_stationary(void) {
bool pbio_imu_is_stationary(void) {
return pbdrv_imu_is_stationary(imu_dev);
}

Expand All @@ -123,7 +123,7 @@ bool pbio_orientation_imu_is_stationary(void) {
* @param [in] angular_velocity Angular velocity threshold in deg/s.
* @param [in] acceleration Acceleration threshold in mm/s^2
*/
void pbio_orientation_imu_set_stationary_thresholds(float angular_velocity, float acceleration) {
void pbio_imu_set_stationary_thresholds(float angular_velocity, float acceleration) {
int16_t gyro_threshold = pbio_int_math_bind(angular_velocity / imu_config->gyro_scale, 1, INT16_MAX);
int16_t accl_threshold = pbio_int_math_bind(acceleration / imu_config->accel_scale, 1, INT16_MAX);
pbdrv_imu_set_stationary_thresholds(imu_dev, gyro_threshold, accl_threshold);
Expand All @@ -134,7 +134,7 @@ void pbio_orientation_imu_set_stationary_thresholds(float angular_velocity, floa
*
* @param [out] values The angular velocity vector.
*/
void pbio_orientation_imu_get_angular_velocity(pbio_geometry_xyz_t *values) {
void pbio_imu_get_angular_velocity(pbio_geometry_xyz_t *values) {
pbio_geometry_vector_map(&pbio_orientation_base_orientation, &angular_velocity, values);
}

Expand All @@ -143,7 +143,7 @@ void pbio_orientation_imu_get_angular_velocity(pbio_geometry_xyz_t *values) {
*
* @param [out] values The acceleration vector.
*/
void pbio_orientation_imu_get_acceleration(pbio_geometry_xyz_t *values) {
void pbio_imu_get_acceleration(pbio_geometry_xyz_t *values) {
pbio_geometry_vector_map(&pbio_orientation_base_orientation, &acceleration, values);
}

Expand All @@ -152,7 +152,7 @@ void pbio_orientation_imu_get_acceleration(pbio_geometry_xyz_t *values) {
*
* @return Which side is up.
*/
pbio_geometry_side_t pbio_orientation_imu_get_up_side(void) {
pbio_geometry_side_t pbio_imu_get_up_side(void) {
// Up is which side of a unit box intersects the +Z vector first.
// So read +Z vector of the inertial frame, in the body frame.
// For now, this is the gravity vector. In the future, we can make this
Expand All @@ -167,7 +167,7 @@ static float heading_offset = 0;
*
* @return Heading angle in the base frame.
*/
float pbio_orientation_imu_get_heading(void) {
float pbio_imu_get_heading(void) {

pbio_geometry_xyz_t heading_mapped;

Expand All @@ -184,8 +184,8 @@ float pbio_orientation_imu_get_heading(void) {
*
* @param [in] desired_heading The desired heading value.
*/
void pbio_orientation_imu_set_heading(float desired_heading) {
heading_offset = pbio_orientation_imu_get_heading() + heading_offset - desired_heading;
void pbio_imu_set_heading(float desired_heading) {
heading_offset = pbio_imu_get_heading() + heading_offset - desired_heading;
}

/**
Expand All @@ -198,10 +198,10 @@ void pbio_orientation_imu_set_heading(float desired_heading) {
* @param [out] heading The output angle object.
* @param [in] ctl_steps_per_degree The number of control steps per heading degree.
*/
void pbio_orientation_imu_get_heading_scaled(pbio_angle_t *heading, int32_t ctl_steps_per_degree) {
void pbio_imu_get_heading_scaled(pbio_angle_t *heading, int32_t ctl_steps_per_degree) {

// Heading in degrees of the robot.
float heading_degrees = pbio_orientation_imu_get_heading();
float heading_degrees = pbio_imu_get_heading();

// Number of whole rotations in control units (in terms of wheels, not robot).
heading->rotations = heading_degrees / (360000 / ctl_steps_per_degree);
Expand All @@ -211,4 +211,4 @@ void pbio_orientation_imu_get_heading_scaled(pbio_angle_t *heading, int32_t ctl_
heading->millidegrees = truncated * ctl_steps_per_degree;
}

#endif // PBIO_CONFIG_ORIENTATION_IMU
#endif // PBIO_CONFIG_IMU
2 changes: 1 addition & 1 deletion lib/pbio/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void pbio_init(void) {
pbio_motor_process_start();
#endif

pbio_orientation_imu_init();
pbio_imu_init();
}

/**
Expand Down
Loading

0 comments on commit 52146cf

Please sign in to comment.