Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nan value when ranges are overranged #13

Merged
merged 3 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions include/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ static UARTSerial microros_serial(RPI_SERIAL_TX, RPI_SERIAL_RX);

static volatile bool distance_sensors_enabled = false;

static volatile bool button1_publish_flag = false;
static volatile bool button2_publish_flag = false;
static volatile bool buttons_publish_flag[BUTTONS_COUNT] = {false, false};
static volatile float button_release_time = 0.1;

static volatile float battery_voltage = 0.0;

static volatile bool is_speed_watchdog_enabled = true;
Expand Down Expand Up @@ -53,6 +54,7 @@ std::map<double, uint8_t> servo_voltage_configuration{
#define MOTOR_FL MOTOR4
#define MOTOR_RR MOTOR2
#define MOTOR_RL MOTOR3
time_t last_button_press_time[BUTTONS_COUNT];

constexpr uint8_t POLARITY = 0b00111100;
constexpr float ROBOT_LENGTH = 0.197;
Expand Down
25 changes: 13 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ std_msgs__msg__Bool button_msgs[BUTTONS_COUNT];
static uint32_t spin_count = 1;

static void button1Callback() {
button1_publish_flag = true;
buttons_publish_flag[0] = true;
}

static void button2Callback() {
button2_publish_flag = true;
buttons_publish_flag[1] = true;
}

void range_sensors_msg_handler() {
Expand Down Expand Up @@ -111,16 +111,17 @@ void battery_msg_handler() {
}

void button_msgs_handler() {
if (button1_publish_flag) {
button_msgs[0].data = 1;
button1_publish_flag = false;
publish_button_msg(&button_msgs[0], 0);
}

if (button2_publish_flag) {
button_msgs[1].data = 1;
button2_publish_flag = false;
publish_button_msg(&button_msgs[1], 1);
for(auto i = 0u; i < BUTTONS_COUNT; ++i){
if (buttons_publish_flag[i]) {
button_msgs[i].data = true;
buttons_publish_flag[i] = false;
publish_button_msg(&button_msgs[i], i);
last_button_press_time[i] = time(NULL);
}
else if(time(NULL) - last_button_press_time[i] > button_release_time){
button_msgs[i].data = false;
publish_button_msg(&button_msgs[i], i);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/microros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,7 @@ void fill_range_msg(sensor_msgs__msg__Range *msg, uint8_t id) {
msg->field_of_view = 0.26;
msg->min_range = 0.01;
msg->max_range = 0.90;
if(msg->range > msg->max_range || msg->range < msg->min_range){
msg->range = NAN;
}
}