Skip to content

Commit

Permalink
Create Field_Mapper.py
Browse files Browse the repository at this point in the history
WIP #7: First go at node for mapping occupancy grid info from Kinect to a map of the field
  • Loading branch information
Dankev55 authored Apr 3, 2019
1 parent 3172bc2 commit d926e96
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions robot_slam/obstacle_avoidance/Field_Mapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python
import rospy
import numpy as np
import tf2_ros

field = Field(length = 600, width = 400)
#listener = tf.transform_listener()
tfBuffer = tf2_ros.Buffer()
listener = tf2_ros.TransformListener(tfBuffer)
rospy.Subscriber("elevation_mapping/occ_grid", OccupancyGrid, field.update_field)
rospy.spin()

This comment has been minimized.

Copy link
@partlygloudy

partlygloudy Apr 3, 2019

Put all the stuff above this (except the import statements) at the bottom within an if __name__ == "__main__:



class Field:
def __init__(self, length, width):
self.map = np.array(size=(600,400)) #length, width
self.xpos = 0
self.ypos = 0
#self.map_pub = rospy.Publisher

def update_field(self, new_map_msg):
#convert msg to numpy array
#get pose of robot relative to world
#update corresponding region of self.map
local_map = np.reshape(OccupancyGrid.data, (OccupancyGrid.info.height, OccupancyGrid.info.width))

This comment has been minimized.

Copy link
@partlygloudy

partlygloudy Apr 3, 2019

Instead of OccupancyGrid.data it should be new_map_msg.data (same for the other places you used OccupanctGrid)

cur_tf = tfBuffer.lookup_transform("world_pose", "robot_pose", rospy.time(0))
local_x = cur_tf.getOrigin().x()
local_y = cur_tf.getOrigin().y()

This comment has been minimized.

Copy link
@partlygloudy

partlygloudy Apr 3, 2019

Not 100% sure what these lines are doing (it's possible they are fine, I just don't know what all the functions do). Basically,

  1. find the transform from "world" to "robot_pose" (this will be in meters), and specifically get the X and Y coordinates for the translation component (a transform will have a translation component and a rotation component)
  2. Convert the X and Y from meters to the units of self.map (centimeters).
  3. You now have the x,y coordinates of the center of the local map in the coordinate frame of the full map
  4. Find the coordinates of one corner of the local map - this is just the center coordinates minus one half the width / height of the local map
  5. Update the correct region of the global map using the numpy slicing method described in the comment below
for y in local_map:
local_y = cur_tf.getOrigin().y()
for x in y:
self.map[local_y][local_x] = local_map[y][x]
local_y += 1
local_x += 1

This comment has been minimized.

Copy link
@partlygloudy

partlygloudy Apr 3, 2019

Rather than iterating over each row and column in the local map, you should update the whole region at once. It's easy to do this with numpy and much more efficient. If arr is a numpy array and local_map is a smaller numpy array you can do:

arr[start_row:stop_row, start_col:stop_col] = local_map

and the entire region will be updated at once, as long as the dimension of the region is the same as the dimension of local_map.

So basically, you should figure out where one corner of the local map should go in the larger map and then update the whole region using that approach.

This comment has been minimized.




def msg_callback(new_map.msg):

This comment has been minimized.

Copy link
@partlygloudy

partlygloudy Apr 3, 2019

can get rid of this



0 comments on commit d926e96

Please sign in to comment.