Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorials:intermediate:semantic_environment_map [2016/01/14 16:57] – created gkazhoyatutorials:intermediate:semantic_environment_map [2016/06/14 13:15] (current) – [Setting up] gkazhoya
Line 14: Line 14:
 ===== Setting up ===== ===== Setting up =====
  
-**Step 1:** start publishing the semantic environment map through JSON Prolog and TF etc..+=== Step 1: start publishing the semantic environment map through JSON Prolog and TF etc. === 
 In a fresh terminal: In a fresh terminal:
  
Line 21: Line 22:
 </code> </code>
  
-**Step 2:** visualization setup.+=== Step 2: visualization setup === 
 In a separate terminal: In a separate terminal:
  
Line 28: Line 30:
 </code> </code>
  
 +The recommended RViz setup is shown below:
 +{{ :tutorials:intermediate:sem_map_rviz.png?direct&1000 |}}
 +
 +Pay attention especially at the ''tf_prefix'' of the ''RobotModel''.
 +
 +Depending on the version of your map you might also have an additional table there but it really doesn't matter.
 +
 +=== Step 3: Initializing the Lisp / CRAM environment ===
 +
 +Fire up your REPL! (If you don't know how, check the [[http://cram-system.org/installation?&#get_ready_for_development|Get ready for development]] part of the installation guide, you will need the ''roslisp_repl'' ROS package installed (''$ sudo apt-get install ros-DISTRO-roslisp-repl'').
 +
 +We will be working with the ''cram_semantic_map_costmap'' package.
 +
 +First, let's load the ASDF system:
  
 <code lisp> <code lisp>
-list code+CL-USER> , 
 +r-l-s RET 
 +cram_semantic_map_costmap RET RET
 </code> </code>
  
 +You should get the "Compilation finished. (No warnings)" message in the Emacs minibuffer.
 +
 +Now let's change the namespace:
 +
 +<code lisp>
 +CL-USER> ,
 +!p RET
 +sem-map-costmap RET
 +SEMANTIC-MAP-COSTMAP>
 +</code>
 +
 +To use semantic maps from KnowRob in CRAM we first need to set our ''*fixed-frame*'', configure the location costmap and start a new ROS node:
 +
 +<code lisp>
 +SEMANTIC-MAP-COSTMAP> (setf cram-tf:*fixed-frame* "map")
 +SEMANTIC-MAP-COSTMAP> 
 +(prolog:def-fact-group costmap-metadata ()
 +  (<- (location-costmap:costmap-size 12 12))
 +  (<- (location-costmap:costmap-origin -6 -6))
 +  (<- (location-costmap:costmap-resolution 0.05))
 +
 +  (<- (location-costmap:costmap-padding 0.2))
 +  (<- (location-costmap:costmap-manipulation-padding 0.2))
 +  (<- (location-costmap:costmap-in-reach-distance 0.9))
 +  (<- (location-costmap:costmap-reach-minimal-distance 0.1)))
 +SEMANTIC-MAP-COSTMAP> (roslisp-utilities:startup-ros)
 +</code>
 +
 +===== Semantic map objects =====
 +
 +Let's ask KnowRob for the semantic map (it might take a while):
 +
 +<code lisp>
 +SEMANTIC-MAP-COSTMAP> (cram-semantic-map:get-semantic-map)
 +#<CRAM-SEMANTIC-MAP-UTILS:SEMANTIC-MAP {1005F1CDD3}>
 +</code>
 +
 +If you right-click on the result object and click ''Inspect'', you can see how semantic maps are stored in CRAM.
 +
 +There is a hash table stored in the ''parts'' slot, which maps name strings to ''semantic-map-geom''-s, i.e. a hash table of the constituent parts of the map.
 +
 +Here are a bunch of ''semantic-map-geom''-s from the example semantic map:
 +<code>
 +"drawer_fridge_lower" = #<CRAM-SEMANTIC-MAP-UTILS:SEMANTIC-MAP-GEOM {1005EB9363}>
 +"kitchen_island" = #<CRAM-SEMANTIC-MAP-UTILS:SEMANTIC-MAP-GEOM {1005495AD3}>
 +"kitchen_island_counter_top" = #<CRAM-SEMANTIC-MAP-UTILS:SEMANTIC-MAP-GEOM {100548C003}>
 +"kitchen_sink_block" = #<CRAM-SEMANTIC-MAP-UTILS:SEMANTIC-MAP-GEOM {1004C71763}>
 +"kitchen_sink_block_counter_top" = #<CRAM-SEMANTIC-MAP-UTILS:SEMANTIC-MAP-GEOM {1004C4F603}>
 +</code>
 +
 +If you inspect a ''semantic-map-geom'' you can see the slots of that object, e.g. the ''"kitchen_island"'' looks like this:
 +{{ :tutorials:intermediate:kitchen_island_geom.png?direct&1000 |}}
 +
 +Most of the classes and utility functions are defined in the ''cram_semantic_map_utils'' package, mostly in the ''semantic-map.lisp'' file: to get a list of all the parts use ''semantic-map-parts'', for a specific part use ''semantic-map-part'', you can get the pose and dimensions of the part using ''pose'' and ''dimensions'' functions, if your semantic map contains joints there are functions to access them as well, etc., see the examples below:
 +
 +<code lisp>
 +SEMANTIC-MAP-COSTMAP> (cram-semantic-map-utils:semantic-map-parts (get-semantic-map))
 +SEMANTIC-MAP-COSTMAP> (cram-semantic-map-utils:semantic-map-part (get-semantic-map) "kitchen_island")
 +#<CRAM-SEMANTIC-MAP-UTILS:SEMANTIC-MAP-GEOM {1005495AD3}>
 +SEMANTIC-MAP-COSTMAP> (cram-semantic-map-utils:pose *)
 +#<CL-TRANSFORMS:POSE 
 +   #<3D-VECTOR (-1.0528899431228638d0 1.6562440395355225d0 0.42500001192092896d0)>
 +   #<QUATERNION (0.0d0 0.0d0 1.0d0 0.0d0)>>
 +SEMANTIC-MAP-COSTMAP> (cram-semantic-map-utils:dimensions **)
 +#<CL-TRANSFORMS:3D-VECTOR (0.800000011920929d0 2.450000047683716d0 0.8500000238418579d0)>
 +</code>
 +
 +
 +===== Designators =====
 +
 +Now let's create a symbolic object description to correspond to a part of the semantic map.
 +We cannot resolve object designators using the ''reference'' function currently, as the object designator resolving mechanism is a big flimsy right now - only perception can resolve object designators - so we will use an explicit function ''designator->semantic-map-objects'' to do that. Note, that you can have a location designator with the same property and it will work just as well:
 +
 +<code lisp>
 +SEMANTIC-MAP-COSTMAP> 
 +(cram-semantic-map-designators:designator->semantic-map-objects 
 + (cram-designators:make-designator :object '((:name "kitchen_sink_block"))))
 +(#<CRAM-SEMANTIC-MAP-UTILS:SEMANTIC-MAP-GEOM {100FB08C23}>)
 +SEMANTIC-MAP-COSTMAP> 
 +(cram-semantic-map-designators:designator->semantic-map-objects 
 + (cram-designators:make-designator :location '((:name "kitchen_island"))))
 +(#<CRAM-SEMANTIC-MAP-UTILS:SEMANTIC-MAP-GEOM {100FE7E4A3}>)
 +</code>
 +
 +We can also ask for a location of an semantic map part:
 +<code lisp>
 +SEMANTIC-MAP-COSTMAP> (make-designator :location `((:of
 +                                                    ,(make-designator :object '((:name "kitchen_island"))))))
 +#<LOCATION-DESIGNATOR ((:OF
 +                        #<OBJECT-DESIGNATOR ((:NAME "kitchen_island"))
 +                          {100E276F63}>)) {100E37ABA3}>
 +                          
 +SEMANTIC-MAP-COSTMAP> (reference *)
 +#<CL-TRANSFORMS-STAMPED:POSE-STAMPED 
 +   FRAME-ID: "map", STAMP: 0.0
 +   #<3D-VECTOR (-1.0528899431228638d0 1.6562440395355225d0 0.42500001192092896d0)>
 +   #<QUATERNION (0.0d0 0.0d0 1.0d0 0.0d0)>>
 +</code>
 +
 +A location description can be ambiguous, e.g., if we would like to have a location of an object of a certain semantic map part type:
 +<code lisp>
 +SEMANTIC-MAP-COSTMAP> 
 +(let* ((object-of-type-cupboard (make-designator :object '((:type "Cupboard"))))
 +       (location-of-cupboard (make-designator :location `((:of ,object-of-type-cupboard)))))
 +  (format t "one solution: ~a~%" (reference location-of-cupboard))
 +  (format t "another solution: ~a~%" (reference (next-solution location-of-cupboard))))
 +one solution: #<POSE-STAMPED 
 +   FRAME-ID: "map", STAMP: 0.0
 +   #<3D-VECTOR (-1.0528899431228638d0 -0.44999998807907104d0 0.36000001430511475d0)>
 +   #<QUATERNION (0.0d0 0.0d0 1.0d0 0.0d0)>>
 +another solution: #<POSE-STAMPED 
 +   FRAME-ID: "map", STAMP: 0.0
 +   #<3D-VECTOR (1.5159399509429932d0 0.30313000082969666d0 0.42500001192092896d0)>
 +   #<QUATERNION (0.0d0 0.0d0 0.0d0 1.0d0)>>
 +</code>
 +There are multiple objects of type cupboard, so we get multiple solutions.
 +
 +In the example semantic map '':type'' can be ''"Cupboard"'', ''"Drawer"'', ''"Refrigerator"'', etc., see the semantic map object for more detail.
 +
 +Now, let's use the location costmap mechanism to ground locations on or in objects:
 +<code lisp>
 +SEMANTIC-MAP-COSTMAP> (reference (make-designator :location '((:in "Refrigerator"))))
 +#<CL-TRANSFORMS-STAMPED:POSE-STAMPED 
 +   FRAME-ID: "map", STAMP: 0.0
 +   #<3D-VECTOR (1.3000001907348633d0 -0.9499998092651367d0 0.53999999538064d0)>
 +   #<QUATERNION (0.0d0 0.0d0 0.0d0 1.0d0)>>
 +</code>
 +{{ :tutorials:intermediate:in-fridge.png?direct&600 |}}
 +The big red dot is the location sampled for this designator.
 +
 +If we want a location on a specific object, not on all objects of a certain type, we can specify that using the '':name'' key:
 +<code lisp>
 +SEMANTIC-MAP-COSTMAP> (reference (make-designator :location '((:on "Cupboard")
 +                                                              (:name "kitchen_island"))))
 +#<CL-TRANSFORMS-STAMPED:POSE-STAMPED 
 +   FRAME-ID: "map", STAMP: 0.0
 +   #<3D-VECTOR (-0.6999998092651367d0 1.0500001907348633d0 0.8500000238418579d0)>
 +   #<QUATERNION (0.0d0 0.0d0 0.0d0 1.0d0)>>
 +</code>
 +{{ :tutorials:intermediate:location_on_kitchen_island.png?direct&1000 |}}
 +The marker array in RViz show a uniform distribution of all possible locations that satisfy the symbolic constraint in the designator.