bool BinaryConnection::update() { if (mIsConnected == false) { return false; } return deleteMaps() && updateMaps(); }
void Costmap2D::copyCostmapWindow(const Costmap2D& map, double win_origin_x, double win_origin_y, double win_size_x, double win_size_y){ //check for self windowing if(this == &map){ ROS_ERROR("Cannot convert this costmap into a window of itself"); return; } //clean up old data deleteMaps(); deleteKernels(); //compute the bounds of our new map unsigned int lower_left_x, lower_left_y, upper_right_x, upper_right_y; if(!map.worldToMap(win_origin_x, win_origin_y, lower_left_x, lower_left_y) || ! map.worldToMap(win_origin_x + win_size_x, win_origin_y + win_size_y, upper_right_x, upper_right_y)){ ROS_ERROR("Cannot window a map that the window bounds don't fit inside of"); return; } size_x_ = upper_right_x - lower_left_x; size_y_ = upper_right_y - lower_left_y; resolution_ = map.resolution_; origin_x_ = win_origin_x; origin_y_ = win_origin_y; ROS_DEBUG("ll(%d, %d), ur(%d, %d), size(%d, %d), origin(%.2f, %.2f)", lower_left_x, lower_left_y, upper_right_x, upper_right_y, size_x_, size_y_, origin_x_, origin_y_); //initialize our various maps and reset markers for inflation initMaps(size_x_, size_y_); //copy the window of the static map and the costmap that we're taking copyMapRegion(map.costmap_, lower_left_x, lower_left_y, map.size_x_, costmap_, 0, 0, size_x_, size_x_, size_y_); copyMapRegion(map.static_map_, lower_left_x, lower_left_y, map.size_x_, static_map_, 0, 0, size_x_, size_x_, size_y_); max_obstacle_range_ = map.max_obstacle_range_; max_obstacle_height_ = map.max_obstacle_height_; max_raytrace_range_ = map.max_raytrace_range_; inscribed_radius_ = map.inscribed_radius_; circumscribed_radius_ = map.circumscribed_radius_; inflation_radius_ = map.inflation_radius_; cell_inscribed_radius_ = map.cell_inscribed_radius_; cell_circumscribed_radius_ = map.cell_circumscribed_radius_; cell_inflation_radius_ = map.cell_inflation_radius_; //set the cost for the circumscribed radius of the robot circumscribed_cost_lb_ = map.circumscribed_cost_lb_; weight_ = map.weight_; //copy the cost and distance kernels copyKernels(map, cell_inflation_radius_); }
bool SQLitePersister::resetState (Campaign* campaign) { Transaction t(*this); const int lives = INITIAL_LIVES; if (saveLives(lives, campaign->getId()) && deleteMaps(campaign) && activateCampaign(campaign)) { campaign->setLives(lives); getSystem().syncFiles(); return true; } Log::error(LOG_CAMPAIGN, "error reseting the state"); return false; }
void Costmap2D::replaceFullMap(double win_origin_x, double win_origin_y, unsigned int data_size_x, unsigned int data_size_y, const std::vector<unsigned char>& static_data){ //delete our old maps deleteMaps(); //update the origin and size of the new map size_x_ = data_size_x; size_y_ = data_size_y; origin_x_ = win_origin_x; origin_y_ = win_origin_y; //initialize our various maps initMaps(size_x_, size_y_); //make sure the inflation queue is empty at the beginning of the cycle (should always be true) ROS_ASSERT_MSG(inflation_queue_.empty(), "The inflation queue must be empty at the beginning of inflation"); unsigned int index = 0; unsigned char* costmap_index = costmap_; std::vector<unsigned char>::const_iterator static_data_index = static_data.begin(); //copy static data into the costmap for(unsigned int i = 0; i < size_y_; ++i){ for(unsigned int j = 0; j < size_x_; ++j){ //check if the static value is above the unknown or lethal thresholds if(track_unknown_space_ && unknown_cost_value_ > 0 && *static_data_index == unknown_cost_value_) *costmap_index = NO_INFORMATION; else if(*static_data_index >= lethal_threshold_) *costmap_index = LETHAL_OBSTACLE; else *costmap_index = FREE_SPACE; if(*costmap_index == LETHAL_OBSTACLE){ unsigned int mx, my; indexToCells(index, mx, my); enqueue(index, mx, my, mx, my, inflation_queue_); } ++costmap_index; ++static_data_index; ++index; } } //now... let's inflate the obstacles inflateObstacles(inflation_queue_); //we also want to keep a copy of the current costmap as the static map memcpy(static_map_, costmap_, size_x_ * size_y_ * sizeof(unsigned char)); }
Costmap2D& Costmap2D::operator=(const Costmap2D& map) { //check for self assignement if(this == &map) return *this; //clean up old data deleteMaps(); deleteKernels(); size_x_ = map.size_x_; size_y_ = map.size_y_; resolution_ = map.resolution_; origin_x_ = map.origin_x_; origin_y_ = map.origin_y_; //initialize our various maps initMaps(size_x_, size_y_); //copy the static map memcpy(static_map_, map.static_map_, size_x_ * size_y_ * sizeof(unsigned char)); //copy the cost map memcpy(costmap_, map.costmap_, size_x_ * size_y_ * sizeof(unsigned char)); max_obstacle_range_ = map.max_obstacle_range_; max_obstacle_height_ = map.max_obstacle_height_; max_raytrace_range_ = map.max_raytrace_range_; inscribed_radius_ = map.inscribed_radius_; circumscribed_radius_ = map.circumscribed_radius_; inflation_radius_ = map.inflation_radius_; cell_inscribed_radius_ = map.cell_inscribed_radius_; cell_circumscribed_radius_ = map.cell_circumscribed_radius_; cell_inflation_radius_ = map.cell_inflation_radius_; //set the cost for the circumscribed radius of the robot circumscribed_cost_lb_ = map.circumscribed_cost_lb_; weight_ = map.weight_; //copy the cost and distance kernels copyKernels(map, cell_inflation_radius_); return *this; }
void Costmap2D::reshapeStaticMap(double win_origin_x, double win_origin_y, unsigned int data_size_x, unsigned int data_size_y, const std::vector<unsigned char>& static_data){ int m_ox, m_oy; worldToMapNoBounds(win_origin_x, win_origin_y, m_ox, m_oy); //compute the bounds for the size of our new map int bl_x = std::min(m_ox, 0); int bl_y = std::min(m_oy, 0); int ur_x = std::max(m_ox + data_size_x, size_x_); int ur_y = std::max(m_oy + data_size_y, size_y_); //create a temporary map to hold our static data and copy the old static map into it unsigned char* static_map_copy = new unsigned char[size_x_ * size_y_]; memcpy(static_map_copy, static_map_, size_x_ * size_y_ * sizeof(unsigned char)); //delete our old maps... the user will lose any //cost information not stored in the static map when reshaping a map deleteMaps(); //update the origin and sizes, and cache data we'll need double old_origin_x = origin_x_; double old_origin_y = origin_y_; unsigned int old_size_x = size_x_; unsigned int old_size_y = size_y_; size_x_ = ur_x - bl_x; size_y_ = ur_y - bl_y; origin_x_ = std::min(origin_x_, win_origin_x); origin_y_ = std::min(origin_y_, win_origin_y); //initialize our various maps initMaps(size_x_, size_y_); //reset our maps to be full of unknown space if appropriate resetMaps(); //now, copy the old static map into the new costmap unsigned int start_x, start_y; worldToMap(old_origin_x, old_origin_y, start_x, start_y); copyMapRegion(static_map_copy, 0, 0, old_size_x, costmap_, start_x, start_y, size_x_, old_size_x, old_size_y); delete[] static_map_copy; //now we want to update the map with the new static map data replaceStaticMapWindow(win_origin_x, win_origin_y, data_size_x, data_size_y, static_data); }
Costmap2D::~Costmap2D(){ deleteMaps(); deleteKernels(); }