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

Dock when rain detected and only dock when mowing #72

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions src/mower_logic/cfg/MowerLogic.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ gen.add("add_fake_obstacle", bool_t, 0, "True to add a fake obstacle to hopefull
gen.add("ignore_gps_errors", bool_t, 0, "True to ignore gps errors. USE ONLY FOR SIMULATION!", False)
gen.add("max_first_point_attempts", int_t, 0, "Maximum attempts to reach the first point of the mow path before trimming", 3, 1, 10)
gen.add("max_first_point_trim_attempts", int_t, 0, "After <max_first_point_attempts> we start to trim the path beginning this often", 3, 1, 10)
gen.add("dock_when_raining", bool_t, 0, "True to dock when rain is detected", False)

exit(gen.generate("mower_logic", "mower_logic", "MowerLogic"))
3 changes: 2 additions & 1 deletion src/mower_logic/src/mower_logic/behaviors/IdleBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern dynamic_reconfigure::Server<mower_logic::MowerLogicConfig> *reconfigServe
extern ros::ServiceClient mapClient;
extern ros::ServiceClient dockingPointClient;

extern bool rain;

IdleBehavior IdleBehavior::INSTANCE;

Expand Down Expand Up @@ -72,7 +73,7 @@ Behavior *IdleBehavior::execute() {
const bool automatic_mode = last_config.automatic_mode == eAutoMode::AUTO;
const bool active_semiautomatic_task = last_config.automatic_mode == eAutoMode::SEMIAUTO && shared_state->active_semiautomatic_task == true;
const bool mower_ready = last_status.v_battery > last_config.battery_full_voltage && last_status.mow_esc_status.temperature_motor < last_config.motor_cold_temperature &&
!last_config.manual_pause_mowing;
!last_config.manual_pause_mowing && !(last_config.dock_when_raining && rain);

if (manual_start_mowing || ((automatic_mode || active_semiautomatic_task) && mower_ready)) {
// set the robot's position to the dock if we're actually docked
Expand Down
38 changes: 36 additions & 2 deletions src/mower_logic/src/mower_logic/mower_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include "xbot_msgs/RegisterActionsSrv.h"
#include <mutex>
#include <atomic>
#include <sstream>
#include <ios>

ros::ServiceClient pathClient, mapClient, dockingPointClient, gpsClient, mowClient, emergencyClient, pathProgressClient, setNavPointClient, clearNavPointClient, clearMapClient, positioningClient, actionRegistrationClient;

Expand Down Expand Up @@ -79,6 +81,10 @@ mower_msgs::HighLevelStatus high_level_status;

std::atomic<bool> mowerEnabled;

ros::Time last_rain_check;
bool rain = false;
bool rain_detected_status = true;

Behavior *currentBehavior = &IdleBehavior::INSTANCE;


Expand Down Expand Up @@ -464,8 +470,34 @@ void checkSafety(const ros::TimerEvent &timer_event) {

// we are in non emergency, check if we should pause. This could be empty battery, rain or hot mower motor etc.
bool dockingNeeded = false;
if (last_status.v_battery < last_config.battery_empty_voltage || last_status.mow_esc_status.temperature_motor >= last_config.motor_hot_temperature ||
last_config.manual_pause_mowing) {
std::stringstream dockingReason("Docking: ", std::ios_base::ate | std::ios_base::in | std::ios_base::out);

if (last_config.manual_pause_mowing) {
dockingReason << "Manual pause";
dockingNeeded = true;
}

// rain_detected_status is initialized to true and flips to false if rain is not detected
// continuously for 20s. This is to avoid false positives due to noise
rain_detected_status = rain_detected_status && last_status.rain_detected;
if (ros::Time::now() - last_rain_check > ros::Duration(20.0)) {
rain = rain_detected_status;
last_rain_check = ros::Time::now();
rain_detected_status = true;
}

if(!dockingNeeded && rain && last_config.dock_when_raining) {
dockingReason << "Rain detected";
dockingNeeded = true;
}

if(!dockingNeeded && last_status.v_battery < last_config.battery_empty_voltage) {
dockingReason << "Battery low: " << last_status.v_battery;
dockingNeeded = true;
}

if (!dockingNeeded && last_status.mow_esc_status.temperature_motor >= last_config.motor_hot_temperature) {
dockingReason << "Over temp: " << last_status.mow_esc_status.temperature_motor;
dockingNeeded = true;
}

Expand All @@ -474,6 +506,7 @@ void checkSafety(const ros::TimerEvent &timer_event) {
currentBehavior != &DockingBehavior::INSTANCE &&
currentBehavior != &UndockingBehavior::RETRY_INSTANCE
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed this in a rebase, should be:

            dockingNeeded &&
            currentBehavior != &DockingBehavior::INSTANCE &&
            currentBehavior != &UndockingBehavior::RETRY_INSTANCE &&
            currentBehavior != &IdleBehavior::INSTANCE &&
            currentBehavior != &UndockingBehavior::INSTANCE &&
            currentBehavior != &AreaRecordingBehavior::INSTANCE

) {
ROS_INFO_STREAM(dockingReason.rdbuf());
abortExecution();
}
}
Expand Down Expand Up @@ -757,6 +790,7 @@ int main(int argc, char **argv) {



last_rain_check = ros::Time::now();
ros::Timer safety_timer = n->createTimer(ros::Duration(0.5), checkSafety);
ros::Timer ui_timer = n->createTimer(ros::Duration(1.0), updateUI);

Expand Down
3 changes: 3 additions & 0 deletions src/open_mower/config/mower_config.sh.example
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ export OM_AUTOMATIC_MODE=0

export OM_OUTLINE_OFFSET=0.05

# Return to dock when rain detected and pause automatic start until rain sensor is dry
export OM_DOCK_WHEN_RAINING=False

################################
## External MQTT Broker ##
################################
Expand Down
1 change: 1 addition & 0 deletions src/open_mower/launch/open_mower.launch
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<param name="motor_cold_temperature" value="$(env OM_MOWING_MOTOR_TEMP_LOW)"/>
<param name="gps_wait_time" value="$(optenv OM_GPS_WAIT_TIME_SEC 10.0)"/>
<param name="gps_timeout" value="$(optenv OM_GPS_TIMEOUT_SEC 10.0)"/>
<param name="dock_when_raining" value="$(optenv OM_DOCK_WHEN_RAINING False)"/>
</node>
<node pkg="slic3r_coverage_planner" type="slic3r_coverage_planner" name="slic3r_coverage_planner" output="screen"/>

Expand Down
Loading