⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 map.c

📁 机器人仿真平台,和stage配合运行
💻 C
字号:
/************************************************************************** * Desc: Global map (grid-based) * Author: Andrew Howard * Date: 6 Feb 2003 * CVS: $Id: map.c,v 1.3.2.1 2003/04/18 19:01:09 inspectorg Exp $**************************************************************************/#include <assert.h>#include <math.h>#include <stdlib.h>#include <string.h>#include "map.h"// Create a new mapmap_t *map_alloc(double scale){  map_t *map;  map = (map_t*) malloc(sizeof(map_t));  // Assume we start at (0, 0)  map->origin_x = 0;  map->origin_y = 0;    // Make the size odd  map->size_x = 0;  map->size_y = 0;  map->scale = scale;  map->max_occ_dist = 0;    // Allocate storage for main map  map->cells = (map_cell_t*) NULL;    return map;}// Destroy a mapvoid map_free(map_t *map){  free(map->cells);  free(map);  return;}// Get the cell at the given pointmap_cell_t *map_get_cell(map_t *map, double ox, double oy, double oa){  int i, j;  map_cell_t *cell;  i = MAP_GXWX(map, ox);  j = MAP_GYWY(map, oy);    if (!MAP_VALID(map, i, j))    return NULL;  cell = map->cells + MAP_INDEX(map, i, j);  return cell;}// Update the cspace distance valuesvoid map_update_cspace(map_t *map, double max_occ_dist){  int i, j;  int ni, nj;  int s;  double d;  map_cell_t *cell, *ncell;  map->max_occ_dist = max_occ_dist;  s = (int) ceil(map->max_occ_dist / map->scale);  // Reset the distance values  for (j = 0; j < map->size_y; j++)  {    for (i = 0; i < map->size_x; i++)    {      cell = map->cells + MAP_INDEX(map, i, j);      cell->occ_dist = map->max_occ_dist;    }  }  // Find all the occupied cells and update their neighbours  for (j = 0; j < map->size_y; j++)  {    for (i = 0; i < map->size_x; i++)    {      cell = map->cells + MAP_INDEX(map, i, j);      if (cell->occ_state != +1)        continue;                cell->occ_dist = 0;      // Update adjacent cells      for (nj = -s; nj <= +s; nj++)      {        for (ni = -s; ni <= +s; ni++)        {          if (!MAP_VALID(map, i + ni, j + nj))            continue;          ncell = map->cells + MAP_INDEX(map, i + ni, j + nj);          d = map->scale * sqrt(ni * ni + nj * nj);          if (d < ncell->occ_dist)            ncell->occ_dist = d;        }      }    }  }    return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -