diff options
author | Michal Skorupinski <m.skorupinsk@samsung.com> | 2018-09-20 16:58:59 +0200 |
---|---|---|
committer | Krzysztof Wieclaw <k.wieclaw@samsung.com> | 2018-10-04 15:14:16 +0200 |
commit | 16add905b5755783daf0dccda446e63ceacc7b3f (patch) | |
tree | 1b6231d9e4d9dfe091859e00a1905f9a914c229e | |
parent | fb351254f6188fbec641e3c04e67ef5c25dc78ee (diff) | |
download | gear-racing-controller-16add905b5755783daf0dccda446e63ceacc7b3f.tar.gz gear-racing-controller-16add905b5755783daf0dccda446e63ceacc7b3f.tar.bz2 gear-racing-controller-16add905b5755783daf0dccda446e63ceacc7b3f.zip |
Config added to sensors
Change-Id: Ia70eb8041c042355a7b9eec07373723e29669749
Signed-off-by: Michal Skorupinski <m.skorupinsk@samsung.com>
-rw-r--r-- | inc/model/model_hw.h | 1 | ||||
-rw-r--r-- | inc/model/model_sensors.h | 3 | ||||
-rw-r--r-- | src/config.c | 22 | ||||
-rw-r--r-- | src/model/model_hw.c | 16 | ||||
-rw-r--r-- | src/model/model_sensors.c | 82 |
5 files changed, 90 insertions, 34 deletions
diff --git a/inc/model/model_hw.h b/inc/model/model_hw.h index eecc204..c0fc94e 100644 --- a/inc/model/model_hw.h +++ b/inc/model/model_hw.h @@ -33,5 +33,6 @@ void model_hw_subscribe_event(t_model_hw_update_cb model_update_cb); void model_hw_deactivate_rotatry(bool deactivate); void model_hw_set_bezel_params(float step, float dead_zone, bool use_blocker, int blocker_count, bool set_to_zero_when_stop); +void model_hw_set_bezel_max_min(float min, float max); #endif /* MODEL_HW_H_ */ diff --git a/inc/model/model_sensors.h b/inc/model/model_sensors.h index 427d065..41afa11 100644 --- a/inc/model/model_sensors.h +++ b/inc/model/model_sensors.h @@ -35,4 +35,7 @@ void model_sensors_set_initial_values(void); void model_sensors_sensor_accelerometer_set_initial_values(void); void model_sensors_sensor_gravity_set_initial_values(void); +void model_sensors_set_acceleration_sensor_params(float input_range, float output_range, float deadzone, float multiplier); +void model_sensors_set_gravity_sensor_params(float input_range, float output_range, float deadzone, float multiplier); + #endif /* MODEL_MODEL_SENSORS_H_ */ diff --git a/src/config.c b/src/config.c index aa9083f..6bd4836 100644 --- a/src/config.c +++ b/src/config.c @@ -17,22 +17,44 @@ #include "model/model_hw.h" #include "model/model_device_to_connection.h" +#include "model/model_sensors.h" #include "gear-racing-controller.h" +#define GRAVITY_DEADZONE 0.2f +#define MAX_GRAVITY 0.7f + +#define DIRECTION_DEADZONE 1.0f +#define MAX_DIRECTION 8.0f + +#define CAM_ELEVATION_DEADZONE 3.0f +#define MAX_CAM_ELEVATION 5.0f + void config_set_sensor_steering_bezel_velocity() { model_device_to_connection_set_control_roles(STERING_MODE_DIRETION, STERING_MODE_CAM_ELEVATION, STERING_MODE_THROTTLE, STERING_MODE_CAM_AZIMUTH); model_hw_set_bezel_params(0.03f, 0.001f, true, 15, true); + model_hw_set_bezel_max_min(-1.0f, 1.0f); + + model_sensors_set_acceleration_sensor_params(MAX_DIRECTION, 1.0f, DIRECTION_DEADZONE, 1.0f); + model_sensors_set_gravity_sensor_params(MAX_GRAVITY, 1.0f, 0.5f, 1.0f); //camera } void config_set_bezel_steering_sensor_velocity() { model_device_to_connection_set_control_roles(STERING_MODE_CAM_AZIMUTH, STERING_MODE_THROTTLE, STERING_MODE_DIRETION, STERING_MODE_CAM_ELEVATION); model_hw_set_bezel_params(-0.1f, 0.001f, false, 0, false); + model_hw_set_bezel_max_min(-1.0f, 1.0f); + + model_sensors_set_acceleration_sensor_params(MAX_DIRECTION, 1.0f, 4.0, -1.0f); //camera + model_sensors_set_gravity_sensor_params(MAX_GRAVITY, 1.0f, GRAVITY_DEADZONE, 1.0f); } void config_set_sensor_stering_sensor_velocity() { model_device_to_connection_set_control_roles(STERING_MODE_DIRETION, STERING_MODE_THROTTLE, STERING_MODE_CAM_ELEVATION, STERING_MODE_CAM_AZIMUTH); model_hw_set_bezel_params(0.03f, 0.001f, false, 0, false); + model_hw_set_bezel_max_min(-1.0f, 0.0f); + + model_sensors_set_acceleration_sensor_params(MAX_DIRECTION, 1.0f, DIRECTION_DEADZONE, 1.0f); + model_sensors_set_gravity_sensor_params(MAX_GRAVITY, 1.0f, GRAVITY_DEADZONE, 1.0f); } diff --git a/src/model/model_hw.c b/src/model/model_hw.c index dbb1086..e990759 100644 --- a/src/model/model_hw.c +++ b/src/model/model_hw.c @@ -33,6 +33,8 @@ typedef struct _s_model_hw { bool use_direction_blocker; int blocker_count; bool set_to_zero_when_stop; + float bezel_min; + float bezel_max; } s_model_hw; static s_model_hw s_info = { 0, }; @@ -63,10 +65,10 @@ static Eina_Bool _rotary_cb(void *data, Eext_Rotary_Event_Info *info) s_info.bezel_position -= s_info.bezel_step; } - if (s_info.bezel_position > 1) { - s_info.bezel_position = 1; - } else if (s_info.bezel_position < -1) { - s_info.bezel_position = -1; + if (s_info.bezel_position > s_info.bezel_max) { + s_info.bezel_position = s_info.bezel_max; + } else if (s_info.bezel_position < s_info.bezel_min) { + s_info.bezel_position = s_info.bezel_min; } @@ -139,3 +141,9 @@ void model_hw_set_bezel_params(float step, float dead_zone, bool use_blocker, in s_info.blocker_count = blocker_count; s_info.set_to_zero_when_stop = set_to_zero_when_stop; } + +void model_hw_set_bezel_max_min(float min, float max) +{ + s_info.bezel_min = min; + s_info.bezel_max = max; +} diff --git a/src/model/model_sensors.c b/src/model/model_sensors.c index f890c6e..bae135c 100644 --- a/src/model/model_sensors.c +++ b/src/model/model_sensors.c @@ -27,28 +27,19 @@ #define ACCELEROMETER_LISTENER_INTERVAL 10 #define LINEAR_LISTENER_INTERVAL 10 -#define GRAVITY_DEADZONE 0.2f -#define MAX_GRAVITY 0.7f -#define MAX_GRAVITY_WITH_DEADZONE (MAX_GRAVITY - GRAVITY_DEADZONE) - -#define DIRECTION_DEADZONE 1.0f -#define MAX_DIRECTION 8.0f -#define MAX_DIRECTION_WITH_DEADZONE (MAX_DIRECTION - DIRECTION_DEADZONE) - -#define DEADZONE 1.0f -#define MAX_ROTATION 8.0f -#define MAX_ROTATION_WITH_DEADZONE (MAX_ROTATION - DEADZONE) - -#define CAM_ELEVATION_DEADZONE 3.0f -#define MAX_CAM_ELEVATION 5.0f -#define MAX_CAM_ELEVATION_WITH_DEADZONE (MAX_CAM_ELEVATION - CAM_ELEVATION_DEADZONE) - typedef struct _s_data_history { int current_index; float sum; float array[VALUE_LIST_SIZE]; } s_data_history; +typedef struct _s_axis_params { + float deadzone; + float input_range; + float output_range; + float multiplier; +} s_axis_params; + typedef struct _s_model_sensors { t_model_sensors_update_cb sensors_update_cb; @@ -66,9 +57,12 @@ typedef struct _s_model_sensors { float last_linear_event_values[3]; float velocity_reference_vector[3]; s_model_sensors_cb_data last_model_data; - s_data_history velocity; - s_data_history direction; - s_data_history cam_elevation; + + s_data_history acceleration_sensor; + s_data_history gravity_sensor; + + s_axis_params acceleration_sensor_params; + s_axis_params gravity_sensor_params; } s_model_sensors; static s_model_sensors s_info = { @@ -111,18 +105,22 @@ static void _sensor_accelerometer_event_cb(sensor_h sensor_accelerometer, sensor vector_diff(event->values, s_info.initial_sensor_accelerometer_data, &vector[0], 3); - float direction = vector[0]; - direction = _get_average_parameter_from_history(direction, &s_info.direction); + float acceleration = vector[0]; + acceleration = _get_average_parameter_from_history(acceleration, &s_info.acceleration_sensor); - direction = _get_position_in_deadzone(direction, DIRECTION_DEADZONE); + acceleration = _get_position_in_deadzone(acceleration, s_info.acceleration_sensor_params.deadzone); - s_info.last_model_data.axis_x = math_helper_range_map(direction, -MAX_DIRECTION_WITH_DEADZONE, MAX_DIRECTION_WITH_DEADZONE, -1.0f, 1.0f); + s_info.last_model_data.axis_x = math_helper_range_map(acceleration, + -(s_info.acceleration_sensor_params.input_range - s_info.acceleration_sensor_params.deadzone), + (s_info.acceleration_sensor_params.input_range - s_info.acceleration_sensor_params.deadzone), + -s_info.acceleration_sensor_params.output_range, s_info.acceleration_sensor_params.output_range); + s_info.last_model_data.axis_x *= s_info.acceleration_sensor_params.multiplier; s_model_sensors_cb_data model_data = s_info.last_model_data; model_device_to_connection_axis_x(model_data.axis_x); - _D("MODEL VALUES: dir:% .4f ranged:% .4f", direction, model_data.axis_x); + _D("MODEL VALUES: acceleration:% .4f ranged:% .4f", acceleration, model_data.axis_x); if (s_info.sensors_update_cb) { s_info.sensors_update_cb(&model_data); } @@ -160,15 +158,20 @@ static void _sensor_gravity_event_cb(sensor_h sensor_gravity, sensor_event_s *ev vector_normalize(&vector[0], &vector[0], 3); - float axis_y = vector_dot_product(vector, s_info.velocity_reference_vector, 3); - axis_y = _get_average_parameter_from_history(axis_y, &s_info.velocity); - axis_y = _get_position_in_deadzone(axis_y, GRAVITY_DEADZONE); - s_info.last_model_data.axis_y = math_helper_range_map(axis_y, -MAX_GRAVITY_WITH_DEADZONE, MAX_GRAVITY_WITH_DEADZONE, -1.0f, 1.0f); + float gravity = vector_dot_product(vector, s_info.velocity_reference_vector, 3); + gravity = _get_average_parameter_from_history(gravity, &s_info.gravity_sensor); + gravity = _get_position_in_deadzone(gravity, s_info.gravity_sensor_params.deadzone); + s_info.last_model_data.axis_y = math_helper_range_map(gravity, + -(s_info.gravity_sensor_params.input_range - s_info.gravity_sensor_params.deadzone), + (s_info.gravity_sensor_params.input_range - s_info.gravity_sensor_params.deadzone), + -s_info.gravity_sensor_params.output_range, s_info.gravity_sensor_params.output_range); + + s_info.last_model_data.axis_x *= s_info.gravity_sensor_params.multiplier; s_model_sensors_cb_data model_data = s_info.last_model_data; model_device_to_connection_axis_y(model_data.axis_y); - _D("MODEL VALUES: axis_y:% .4f ranged:% .4f", axis_y, model_data.axis_y); + _D("MODEL VALUES: axis_y:% .4f ranged:% .4f", gravity, model_data.axis_y); if (s_info.sensors_update_cb) { s_info.sensors_update_cb(&model_data); } @@ -203,7 +206,7 @@ void model_sensors_sensor_gravity_set_initial_values(void) vector_matrix_multiply(&rotation_matrix[0][0], &reference_vector[0], &s_info.velocity_reference_vector[0], 3); _D("Initial sensor_gravity data: {%f, %f, %f}", s_info.initial_sensor_gravity_data[0], s_info.initial_sensor_gravity_data[1], - s_info.initial_sensor_gravity_data[2]); + s_info.initial_sensor_gravity_data[2]); _D("Initial velovity refernce vector: {%f, %f, %f}", s_info.velocity_reference_vector[0], s_info.velocity_reference_vector[1], s_info.velocity_reference_vector[2]); } @@ -259,6 +262,25 @@ void model_sensors_init(void) model_sensors_set_initial_values(); } + +static void _set_axis_params(s_axis_params *axis, float input_range, float output_range, float deadzone, float multiplier) +{ + axis->input_range = input_range; + axis->output_range = output_range; + axis->deadzone = deadzone; + axis->multiplier = multiplier; +} + +void model_sensors_set_acceleration_sensor_params(float input_range, float output_range, float deadzone, float multiplier) +{ + _set_axis_params(&s_info.acceleration_sensor_params, input_range, output_range, deadzone, multiplier); +} + +void model_sensors_set_gravity_sensor_params(float input_range, float output_range, float deadzone, float multiplier) +{ + _set_axis_params(&s_info.gravity_sensor_params, input_range, output_range, deadzone, multiplier); +} + void model_sensors_subscribe_event(t_model_sensors_update_cb model_update_cb) { s_info.sensors_update_cb = model_update_cb; |