]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
MCL: Fixes + added prediction of of next beacon
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 30 Apr 2008 00:15:23 +0000 (02:15 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 30 Apr 2008 00:15:23 +0000 (02:15 +0200)
Maltab now draws angle as color.
Always is used BEACON_CNT beacons, because current implementation depends
on the order of beacons and omitting one beacon is not possible.

src/mcl/matlab/Makefile
src/mcl/matlab/mcl_test.mdl
src/mcl/matlab/reg_mcl.mdl
src/mcl/matlab/sf_mcl.c
src/mcl/matlab/sfdrawbitmap.m
src/mcl/mcl.c
src/mcl/mcl_laser.c
src/mcl/mcl_laser.h
src/mcl/test/testmcl_performance.c

index 2b35ebefc0a49268fd48f3a985835ec7678fdc81..17add6e03e8a40fa2c13c054f9749d95eea91099 100644 (file)
@@ -1,7 +1,7 @@
 VPATH = ../../motion
 LIBPATH=$(PWD)/../../../build/linux/_compiled/lib
 INCPATH=$(PWD)/../../../build/linux/_compiled/include
-CXXFLAGS += -I$(VPATH) -L$(LIBPATH) -I$(INCPATH)
+CXXFLAGS += -I$(VPATH) -L$(LIBPATH) -I$(INCPATH) -g
 
 all: sf_posreg.mexglx sf_trgen.mexglx sf_mcl.mexglx
 
@@ -12,8 +12,8 @@ sf_trgen.mexglx: sf_trgen.cc trgen.cc
        mex  $(CXXFLAGS) $^
 
 
-sf_mcl.mexglx: sf_mcl.c $(LIBPATH)/libmcl.a $(LIBPATH)/librobomath.a # With fast library but printf doesn't work
-# sf_mcl.mexglx: sf_mcl.c ../mcl.c ../../robomath/robomath.c # For calling printf from MCL
+sf_mcl.mexglx: sf_mcl.c $(LIBPATH)/libmcl.a $(LIBPATH)/librobomath.a $(LIBPATH)/librobodim_eb2008.a # With fast library but printf doesn't work
+#sf_mcl.mexglx: sf_mcl.c ../mcl.c ../mcl_laser.c ../../robomath/robomath.c # For calling printf from MCL
        mex $(CXXFLAGS) $^
 
 
index d5603c7fd1720f63bb12b4a103c16e932b4b4cfe..7175b50883173b62286f6843a1b3e258adb1ff5c 100644 (file)
@@ -6,14 +6,14 @@ Model {
     NumRootInports         0
     NumRootOutports        0
     ParameterArgumentNames  ""
-    ComputedModelVersion    "1.105"
+    ComputedModelVersion    "1.129"
     NumModelReferences     0
     NumTestPointedSignals   0
   }
   SavedCharacterEncoding  "UTF-8"
   PostLoadFcn            "init\nsim('mcl_test', 0)"
   SaveDefaultBlockParams  on
-  SampleTimeColors       off
+  SampleTimeColors       on
   LibraryLinkDisplay     "none"
   WideLines              off
   ShowLineDimensions     on
@@ -46,8 +46,8 @@ Model {
   ModifiedByFormat       "%<Auto>"
   LastModifiedBy         "wsh"
   ModifiedDateFormat     "%<Auto>"
-  LastModifiedDate       "Tue Apr 29 11:52:05 2008"
-  ModelVersionFormat     "1.%<AutoIncrement:105>"
+  LastModifiedDate       "Wed Apr 30 02:08:24 2008"
+  ModelVersionFormat     "1.%<AutoIncrement:129>"
   ConfigurationManager   "None"
   SimulationMode         "normal"
   LinearizationMsg       "none"
@@ -749,7 +749,7 @@ Model {
   }
   System {
     Name                   "mcl_test"
-    Location               [358, 561, 1340, 943]
+    Location               [4, 618, 986, 1000]
     Open                   on
     ModelBrowserVisibility  off
     ModelBrowserWidth      200
@@ -794,7 +794,7 @@ Model {
       System {
        Name                    "Graphs"
        Location                [962, 152, 1482, 471]
-       Open                    off
+       Open                    on
        ModelBrowserVisibility  off
        ModelBrowserWidth       200
        ScreenColor             "white"
@@ -1050,7 +1050,7 @@ Model {
       MaskIconOpaque         on
       MaskIconRotate         "none"
       MaskIconUnits          "autoscale"
-      MaskValueString        "3000|0.01|2/180*pi|3/180*pi"
+      MaskValueString        "3000|0.01|5/180*pi|1/180*pi"
       MaskTabNameString              ",,,"
     }
     Block {
@@ -1070,16 +1070,16 @@ Model {
     Block {
       BlockType                      Constant
       Name                   "No odometry"
-      Position               [385, 89, 445, 111]
+      Position               [395, 89, 455, 111]
       NamePlacement          "alternate"
       Value                  "[0 0 0]"
-      SampleTime             "0.1"
+      SampleTime             "-1"
     }
     Block {
       BlockType                      SubSystem
       Name                   "Pos to deltas"
       Ports                  [1, 1]
-      Position               [240, 101, 335, 139]
+      Position               [280, 101, 375, 139]
       MinAlgLoopOccurrences   off
       RTWSystemCode          "Auto"
       FunctionWithSeparateData off
@@ -1303,6 +1303,12 @@ Model {
        }
       }
     }
+    Block {
+      BlockType                      RateTransition
+      Name                   "Rate Transition"
+      Position               [235, 98, 255, 142]
+      OutPortSampleTime              "1/20"
+    }
     Block {
       BlockType                      SubSystem
       Name                   "Rotating laser"
@@ -1330,12 +1336,12 @@ Model {
       MaskIconOpaque         on
       MaskIconRotate         "none"
       MaskIconUnits          "normalized"
-      MaskValueString        "1|0.01|on"
+      MaskValueString        "3|0.01|on"
       MaskTabNameString              ",,"
       System {
        Name                    "Rotating laser"
-       Location                [127, 99, 1151, 684]
-       Open                    on
+       Location                [651, 66, 1675, 656]
+       Open                    off
        ModelBrowserVisibility  off
        ModelBrowserWidth       200
        ScreenColor             "white"
@@ -1519,17 +1525,70 @@ Model {
            }
          }
        }
+       Block {
+         BlockType               SubSystem
+         Name                    "Beacon memory3"
+         Ports                   [1, 1, 0, 1]
+         Position                [510, 509, 565, 541]
+         TreatAsAtomicUnit       on
+         MinAlgLoopOccurrences   off
+         RTWSystemCode           "Auto"
+         FunctionWithSeparateData off
+         MaskHideContents        off
+         System {
+           Name                    "Beacon memory3"
+           Location                [401, 346, 899, 646]
+           Open                    off
+           ModelBrowserVisibility  off
+           ModelBrowserWidth       200
+           ScreenColor             "white"
+           PaperOrientation        "landscape"
+           PaperPositionMode       "auto"
+           PaperType               "A4"
+           PaperUnits              "centimeters"
+           TiledPaperMargins       [0.500000, 0.500000, 0.500000, 0.500000]
+           TiledPageScale          1
+           ShowPageBoundaries      off
+           ZoomFactor              "100"
+           Block {
+             BlockType               Inport
+             Name                    "In1"
+             Position                [110, 103, 140, 117]
+             IconDisplay             "Port number"
+           }
+           Block {
+             BlockType               TriggerPort
+             Name                    "Trigger"
+             Ports                   []
+             Position                [225, 20, 245, 40]
+             StatesWhenEnabling      "held"
+           }
+           Block {
+             BlockType               Outport
+             Name                    "Out1"
+             Position                [360, 103, 390, 117]
+             IconDisplay             "Port number"
+             BusOutputAsStruct       off
+           }
+           Line {
+             SrcBlock                "In1"
+             SrcPort                 1
+             DstBlock                "Out1"
+             DstPort                 1
+           }
+         }
+       }
        Block {
          BlockType               Clock
          Name                    "Clock"
-         Position                [740, 310, 760, 330]
+         Position                [740, 320, 760, 340]
          Decimation              "10"
        }
        Block {
          BlockType               Reference
          Name                    "Compare\nTo Constant"
          Ports                   [1, 1]
-         Position                [50, 165, 100, 195]
+         Position                [35, 164, 100, 196]
          Orientation             "left"
          SourceBlock             "simulink/Logic and Bit\nOperations/Compare"
 "\nTo Constant"
@@ -1551,7 +1610,7 @@ Model {
          BlockType               Reference
          Name                    "Compare\nTo Zero"
          Ports                   [1, 1]
-         Position                [800, 305, 830, 335]
+         Position                [800, 315, 830, 345]
          SourceBlock             "simulink/Logic and Bit\nOperations/Compare"
 "\nTo Zero"
          SourceType              "Compare To Zero"
@@ -1577,25 +1636,23 @@ Model {
        Block {
          BlockType               Demux
          Name                    "Demux"
-         Ports                   [1, 3]
-         Position                [344, 190, 396, 200]
+         Ports                   [1, 4]
+         Position                [346, 190, 399, 200]
          Orientation             "down"
          BackgroundColor         "black"
          NamePlacement           "alternate"
          ShowName                off
-         Outputs                 "3"
          DisplayOption           "bar"
        }
        Block {
          BlockType               Demux
          Name                    "Demux1"
-         Ports                   [1, 3]
-         Position                [414, 190, 466, 200]
+         Ports                   [1, 4]
+         Position                [421, 190, 474, 200]
          Orientation             "down"
          BackgroundColor         "black"
          NamePlacement           "alternate"
          ShowName                off
-         Outputs                 "3"
          DisplayOption           "bar"
        }
        Block {
@@ -1603,7 +1660,7 @@ Model {
          Name                    "Do not produce\ndata at start. We\nhave to "
 "wait one turn."
          Ports                   [1, 1, 1]
-         Position                [825, 364, 925, 406]
+         Position                [825, 374, 925, 416]
          TreatAsAtomicUnit       on
          MinAlgLoopOccurrences   off
          RTWSystemCode           "Auto"
@@ -1729,21 +1786,20 @@ Model {
          Orientation             "left"
          NamePlacement           "alternate"
          Variance                "(noise_stdev/180*pi)^2"
-         Seed                    "abs(floor(rand(3,1)*10000))"
+         Seed                    "abs(floor(rand(4,1)*10000))"
        }
        Block {
          BlockType               Mux
          Name                    "Mux"
-         Ports                   [3, 1]
-         Position                [700, 352, 705, 418]
+         Ports                   [4, 1]
+         Position                [700, 354, 705, 436]
          ShowName                off
-         Inputs                  "3"
          DisplayOption           "bar"
        }
        Block {
          BlockType               RateTransition
          Name                    "Rate Transition"
-         Position                [750, 364, 790, 406]
+         Position                [750, 374, 790, 416]
          OutPortSampleTime       "1/rps"
        }
        Block {
@@ -1758,9 +1814,9 @@ Model {
          Ports                   [1, 1]
          Position                [585, 91, 625, 129]
          IndexOptions            "Index vector (dialog)"
-         Indices                 "[1]"
+         Indices                 "[1 2 3 4]"
          OutputSizes             "1"
-         InputPortWidth          "3"
+         InputPortWidth          "4"
        }
        Block {
          BlockType               Sum
@@ -1827,6 +1883,19 @@ Model {
          OutDataTypeMode         "Inherit via internal rule"
          SaturateOnIntegerOverflow off
        }
+       Block {
+         BlockType               Sum
+         Name                    "Sum4"
+         Ports                   [2, 1]
+         Position                [460, 515, 480, 535]
+         ShowName                off
+         IconShape               "round"
+         Inputs                  "++|"
+         CollapseMode            "All dimensions"
+         InputSameDT             off
+         OutDataTypeMode         "Inherit via internal rule"
+         SaturateOnIntegerOverflow off
+       }
        Block {
          BlockType               Sum
          Name                    "Sum5"
@@ -1858,7 +1927,7 @@ Model {
        Block {
          BlockType               Outport
          Name                    "Simultaneous"
-         Position                [965, 378, 995, 392]
+         Position                [965, 388, 995, 402]
          Port                    "3"
          IconDisplay             "Port number"
          BusOutputAsStruct       off
@@ -1872,16 +1941,8 @@ Model {
        Line {
          SrcBlock                "Demux1"
          SrcPort                 3
-         Points                  [0, 15]
-         Branch {
-           DstBlock                "Sum3"
-           DstPort                 1
-         }
-         Branch {
-           Points                  [35, 0]
-           DstBlock                "Sum"
-           DstPort                 1
-         }
+         DstBlock                "Sum3"
+         DstPort                 1
        }
        Line {
          SrcBlock                "Demux1"
@@ -1923,6 +1984,7 @@ Model {
            DstPort                 2
          }
          Branch {
+           Points                  [0, 15]
            DstBlock                "Demux1"
            DstPort                 1
          }
@@ -1983,7 +2045,7 @@ Model {
        Line {
          SrcBlock                "Demux"
          SrcPort                 3
-         Points                  [0, 81; 150, 0]
+         Points                  [0, 81; 155, 0]
          DstBlock                "Beacon memory"
          DstPort                 trigger
        }
@@ -2039,6 +2101,7 @@ Model {
          SrcPort                 1
          Points                  [15, 0]
          Branch {
+           Points                  [0, 65]
            DstBlock                "Demux"
            DstPort                 1
          }
@@ -2078,8 +2141,15 @@ Model {
                }
                Branch {
                  Points                  [0, 70]
-                 DstBlock                "Sum3"
-                 DstPort                 2
+                 Branch {
+                   DstBlock                "Sum3"
+                   DstPort                 2
+                 }
+                 Branch {
+                   Points                  [0, 70]
+                   DstBlock                "Sum4"
+                   DstPort                 2
+                 }
                }
              }
            }
@@ -2094,7 +2164,7 @@ Model {
        Line {
          SrcBlock                "Compare\nTo Constant"
          SrcPort                 1
-         Points                  [-30, 0; 0, 110]
+         Points                  [-15, 0; 0, 110]
          DstBlock                "Integrator"
          DstPort                 2
        }
@@ -2124,6 +2194,33 @@ Model {
          DstBlock                "Individual output"
          DstPort                 trigger
        }
+       Line {
+         SrcBlock                "Sum4"
+         SrcPort                 1
+         DstBlock                "Beacon memory3"
+         DstPort                 1
+       }
+       Line {
+         SrcBlock                "Demux1"
+         SrcPort                 4
+         Points                  [0, 10]
+         Branch {
+           Points                  [20, 0]
+           DstBlock                "Sum"
+           DstPort                 1
+         }
+         Branch {
+           DstBlock                "Sum4"
+           DstPort                 1
+         }
+       }
+       Line {
+         SrcBlock                "Beacon memory3"
+         SrcPort                 1
+         Points                  [55, 0; 0, -100]
+         DstBlock                "Mux"
+         DstPort                 4
+       }
       }
     }
     Block {
@@ -2142,7 +2239,7 @@ Model {
       RTWMemSecDataInternal   "Inherit from model"
       RTWMemSecDataParameters "Inherit from model"
       low                    "0"
-      gain                   "232.844"
+      gain                   "360"
       high                   "360"
     }
     Block {
@@ -2161,7 +2258,7 @@ Model {
       RTWMemSecDataInternal   "Inherit from model"
       RTWMemSecDataParameters "Inherit from model"
       low                    "0"
-      gain                   "1.47"
+      gain                   "0.7156"
       high                   "3"
     }
     Block {
@@ -2218,7 +2315,7 @@ Model {
       RTWMemSecDataConstants  "Inherit from model"
       RTWMemSecDataInternal   "Inherit from model"
       RTWMemSecDataParameters "Inherit from model"
-      sw                     "0"
+      sw                     "1"
       action                 "0"
       varsize                off
     }
@@ -2322,7 +2419,7 @@ Model {
       Labels                 [0, 0]
       SrcBlock               "Switch"
       SrcPort                1
-      Points                 [0, 0]
+      Points                 [5, 0]
       Branch {
        DstBlock                "MCL"
        DstPort                 2
@@ -2368,10 +2465,6 @@ Model {
       SrcBlock               "Mux"
       SrcPort                1
       Points                 [10, 0]
-      Branch {
-       DstBlock                "Pos to deltas"
-       DstPort                 1
-      }
       Branch {
        Points                  [0, -60; 530, 0]
        Branch {
@@ -2389,6 +2482,10 @@ Model {
        DstBlock                "Rotating laser"
        DstPort                 1
       }
+      Branch {
+       DstBlock                "Rate Transition"
+       DstPort                 1
+      }
     }
     Line {
       SrcBlock               "to rad"
@@ -2404,6 +2501,12 @@ Model {
       DstBlock               "Switch"
       DstPort                2
     }
+    Line {
+      SrcBlock               "Rate Transition"
+      SrcPort                1
+      DstBlock               "Pos to deltas"
+      DstPort                1
+    }
   }
 }
 
index ad15db2af99277b9a61d11ae1c6a2b6bcc1b8ed7..0d33cf260a39c91174f0577670f8bdb2b9b1aaa4 100644 (file)
@@ -6,7 +6,7 @@ Model {
     NumRootInports         0
     NumRootOutports        0
     ParameterArgumentNames  ""
-    ComputedModelVersion    "1.326"
+    ComputedModelVersion    "1.327"
     NumModelReferences     0
     NumTestPointedSignals   0
   }
@@ -48,8 +48,8 @@ Model {
   ModifiedByFormat       "%<Auto>"
   LastModifiedBy         "wsh"
   ModifiedDateFormat     "%<Auto>"
-  LastModifiedDate       "Tue Apr 29 11:44:26 2008"
-  ModelVersionFormat     "1.%<AutoIncrement:326>"
+  LastModifiedDate       "Wed Apr 30 02:09:53 2008"
+  ModelVersionFormat     "1.%<AutoIncrement:327>"
   ConfigurationManager   "None"
   SimulationMode         "normal"
   LinearizationMsg       "none"
@@ -791,7 +791,7 @@ Model {
   }
   System {
     Name                   "reg_mcl"
-    Location               [391, 580, 1246, 1057]
+    Location               [666, 262, 1521, 739]
     Open                   on
     ModelBrowserVisibility  off
     ModelBrowserWidth      200
@@ -1796,11 +1796,11 @@ Model {
       MaskIconOpaque         on
       MaskIconRotate         "none"
       MaskIconUnits          "normalized"
-      MaskValueString        "3|1|on"
+      MaskValueString        "3|0.01|on"
       MaskTabNameString              ",,"
       System {
        Name                    "Rotating laser"
-       Location                [84, 67, 1108, 652]
+       Location                [651, 66, 1675, 656]
        Open                    off
        ModelBrowserVisibility  off
        ModelBrowserWidth       200
@@ -1985,17 +1985,70 @@ Model {
            }
          }
        }
+       Block {
+         BlockType               SubSystem
+         Name                    "Beacon memory3"
+         Ports                   [1, 1, 0, 1]
+         Position                [510, 509, 565, 541]
+         TreatAsAtomicUnit       on
+         MinAlgLoopOccurrences   off
+         RTWSystemCode           "Auto"
+         FunctionWithSeparateData off
+         MaskHideContents        off
+         System {
+           Name                    "Beacon memory3"
+           Location                [401, 346, 899, 646]
+           Open                    off
+           ModelBrowserVisibility  off
+           ModelBrowserWidth       200
+           ScreenColor             "white"
+           PaperOrientation        "landscape"
+           PaperPositionMode       "auto"
+           PaperType               "A4"
+           PaperUnits              "centimeters"
+           TiledPaperMargins       [0.500000, 0.500000, 0.500000, 0.500000]
+           TiledPageScale          1
+           ShowPageBoundaries      off
+           ZoomFactor              "100"
+           Block {
+             BlockType               Inport
+             Name                    "In1"
+             Position                [110, 103, 140, 117]
+             IconDisplay             "Port number"
+           }
+           Block {
+             BlockType               TriggerPort
+             Name                    "Trigger"
+             Ports                   []
+             Position                [225, 20, 245, 40]
+             StatesWhenEnabling      "held"
+           }
+           Block {
+             BlockType               Outport
+             Name                    "Out1"
+             Position                [360, 103, 390, 117]
+             IconDisplay             "Port number"
+             BusOutputAsStruct       off
+           }
+           Line {
+             SrcBlock                "In1"
+             SrcPort                 1
+             DstBlock                "Out1"
+             DstPort                 1
+           }
+         }
+       }
        Block {
          BlockType               Clock
          Name                    "Clock"
-         Position                [740, 310, 760, 330]
+         Position                [740, 320, 760, 340]
          Decimation              "10"
        }
        Block {
          BlockType               Reference
          Name                    "Compare\nTo Constant"
          Ports                   [1, 1]
-         Position                [50, 165, 100, 195]
+         Position                [35, 164, 100, 196]
          Orientation             "left"
          SourceBlock             "simulink/Logic and Bit\nOperations/Compare"
 "\nTo Constant"
@@ -2017,7 +2070,7 @@ Model {
          BlockType               Reference
          Name                    "Compare\nTo Zero"
          Ports                   [1, 1]
-         Position                [800, 305, 830, 335]
+         Position                [800, 315, 830, 345]
          SourceBlock             "simulink/Logic and Bit\nOperations/Compare"
 "\nTo Zero"
          SourceType              "Compare To Zero"
@@ -2043,25 +2096,23 @@ Model {
        Block {
          BlockType               Demux
          Name                    "Demux"
-         Ports                   [1, 3]
-         Position                [344, 190, 396, 200]
+         Ports                   [1, 4]
+         Position                [346, 190, 399, 200]
          Orientation             "down"
          BackgroundColor         "black"
          NamePlacement           "alternate"
          ShowName                off
-         Outputs                 "3"
          DisplayOption           "bar"
        }
        Block {
          BlockType               Demux
          Name                    "Demux1"
-         Ports                   [1, 3]
-         Position                [414, 190, 466, 200]
+         Ports                   [1, 4]
+         Position                [421, 190, 474, 200]
          Orientation             "down"
          BackgroundColor         "black"
          NamePlacement           "alternate"
          ShowName                off
-         Outputs                 "3"
          DisplayOption           "bar"
        }
        Block {
@@ -2069,7 +2120,7 @@ Model {
          Name                    "Do not produce\ndata at start. We\nhave to "
 "wait one turn."
          Ports                   [1, 1, 1]
-         Position                [825, 364, 925, 406]
+         Position                [825, 374, 925, 416]
          TreatAsAtomicUnit       on
          MinAlgLoopOccurrences   off
          RTWSystemCode           "Auto"
@@ -2195,21 +2246,20 @@ Model {
          Orientation             "left"
          NamePlacement           "alternate"
          Variance                "(noise_stdev/180*pi)^2"
-         Seed                    "abs(floor(rand(3,1)*10000))"
+         Seed                    "abs(floor(rand(4,1)*10000))"
        }
        Block {
          BlockType               Mux
          Name                    "Mux"
-         Ports                   [3, 1]
-         Position                [700, 352, 705, 418]
+         Ports                   [4, 1]
+         Position                [700, 354, 705, 436]
          ShowName                off
-         Inputs                  "3"
          DisplayOption           "bar"
        }
        Block {
          BlockType               RateTransition
          Name                    "Rate Transition"
-         Position                [750, 364, 790, 406]
+         Position                [750, 374, 790, 416]
          OutPortSampleTime       "1/rps"
        }
        Block {
@@ -2218,6 +2268,16 @@ Model {
          Position                [735, 19, 775, 61]
          OutPortSampleTime       "1/rps"
        }
+       Block {
+         BlockType               Selector
+         Name                    "Selector"
+         Ports                   [1, 1]
+         Position                [585, 91, 625, 129]
+         IndexOptions            "Index vector (dialog)"
+         Indices                 "[1 2 3 4]"
+         OutputSizes             "1"
+         InputPortWidth          "4"
+       }
        Block {
          BlockType               Sum
          Name                    "Subtract"
@@ -2283,6 +2343,19 @@ Model {
          OutDataTypeMode         "Inherit via internal rule"
          SaturateOnIntegerOverflow off
        }
+       Block {
+         BlockType               Sum
+         Name                    "Sum4"
+         Ports                   [2, 1]
+         Position                [460, 515, 480, 535]
+         ShowName                off
+         IconShape               "round"
+         Inputs                  "++|"
+         CollapseMode            "All dimensions"
+         InputSameDT             off
+         OutDataTypeMode         "Inherit via internal rule"
+         SaturateOnIntegerOverflow off
+       }
        Block {
          BlockType               Sum
          Name                    "Sum5"
@@ -2314,11 +2387,51 @@ Model {
        Block {
          BlockType               Outport
          Name                    "Simultaneous"
-         Position                [965, 378, 995, 392]
+         Position                [965, 388, 995, 402]
          Port                    "3"
          IconDisplay             "Port number"
          BusOutputAsStruct       off
        }
+       Line {
+         SrcBlock                "Beacon memory3"
+         SrcPort                 1
+         Points                  [55, 0; 0, -100]
+         DstBlock                "Mux"
+         DstPort                 4
+       }
+       Line {
+         SrcBlock                "Demux1"
+         SrcPort                 4
+         Points                  [0, 10]
+         Branch {
+           DstBlock                "Sum4"
+           DstPort                 1
+         }
+         Branch {
+           Points                  [20, 0]
+           DstBlock                "Sum"
+           DstPort                 1
+         }
+       }
+       Line {
+         SrcBlock                "Sum4"
+         SrcPort                 1
+         DstBlock                "Beacon memory3"
+         DstPort                 1
+       }
+       Line {
+         SrcBlock                "Selector"
+         SrcPort                 1
+         Points                  [140, 0]
+         DstBlock                "Individual output"
+         DstPort                 trigger
+       }
+       Line {
+         SrcBlock                "Beacon memory1"
+         SrcPort                 1
+         DstBlock                "Mux"
+         DstPort                 2
+       }
        Line {
          SrcBlock                "Integrator"
          SrcPort                 state
@@ -2335,7 +2448,7 @@ Model {
        Line {
          SrcBlock                "Compare\nTo Constant"
          SrcPort                 1
-         Points                  [-30, 0; 0, 110]
+         Points                  [-15, 0; 0, 110]
          DstBlock                "Integrator"
          DstPort                 2
        }
@@ -2358,8 +2471,15 @@ Model {
                Points                  [0, 70]
                Branch {
                  Points                  [0, 70]
-                 DstBlock                "Sum3"
-                 DstPort                 2
+                 Branch {
+                   Points                  [0, 70]
+                   DstBlock                "Sum4"
+                   DstPort                 2
+                 }
+                 Branch {
+                   DstBlock                "Sum3"
+                   DstPort                 2
+                 }
                }
                Branch {
                  DstBlock                "Sum2"
@@ -2388,13 +2508,13 @@ Model {
          SrcPort                 1
          Points                  [15, 0]
          Branch {
-           DstBlock                "Demux"
+           DstBlock                "Selector"
            DstPort                 1
          }
          Branch {
-           Points                  [400, 0]
-           DstBlock                "Individual output"
-           DstPort                 trigger
+           Points                  [0, 65]
+           DstBlock                "Demux"
+           DstPort                 1
          }
        }
        Line {
@@ -2423,12 +2543,6 @@ Model {
          DstBlock                "Mux"
          DstPort                 1
        }
-       Line {
-         SrcBlock                "Beacon memory1"
-         SrcPort                 1
-         DstBlock                "Mux"
-         DstPort                 2
-       }
        Line {
          SrcBlock                "Beacon memory2"
          SrcPort                 1
@@ -2453,7 +2567,7 @@ Model {
        Line {
          SrcBlock                "Demux"
          SrcPort                 3
-         Points                  [0, 81; 150, 0]
+         Points                  [0, 81; 155, 0]
          DstBlock                "Beacon memory"
          DstPort                 trigger
        }
@@ -2515,6 +2629,7 @@ Model {
          SrcPort                 1
          Points                  [-30, 0]
          Branch {
+           Points                  [0, 15]
            DstBlock                "Demux1"
            DstPort                 1
          }
@@ -2557,16 +2672,8 @@ Model {
        Line {
          SrcBlock                "Demux1"
          SrcPort                 3
-         Points                  [0, 15]
-         Branch {
-           Points                  [35, 0]
-           DstBlock                "Sum"
-           DstPort                 1
-         }
-         Branch {
-           DstBlock                "Sum3"
-           DstPort                 1
-         }
+         DstBlock                "Sum3"
+         DstPort                 1
        }
        Line {
          SrcBlock                "Sum5"
@@ -2785,10 +2892,6 @@ Model {
        DstBlock                "Rate Transition2"
        DstPort                 1
       }
-      Branch {
-       DstBlock                "Rotating laser"
-       DstPort                 1
-      }
       Branch {
        Labels                  [2, 0]
        Points                  [0, -45; 300, 0]
@@ -2802,6 +2905,10 @@ Model {
          DstPort                 1
        }
       }
+      Branch {
+       DstBlock                "Rotating laser"
+       DstPort                 1
+      }
     }
     Line {
       SrcBlock               "Clock"
index 5d4d42b78903bbf1ddf926df1b3ccfc284faf17e..ffbb2c2ee63cda948fabe2487118b0d1fea03b38 100644 (file)
@@ -25,6 +25,9 @@ extern "C" { /*use the C fcn-call standard for all functions */
 
 #define BITMAP_WIDTH  300
 #define BITMAP_HEIGHT 210
+#define BITMAP_R (0*BITMAP_WIDTH*BITMAP_HEIGHT)
+#define        BITMAP_G (1*BITMAP_WIDTH*BITMAP_HEIGHT)
+#define        BITMAP_B (2*BITMAP_WIDTH*BITMAP_HEIGHT)
 
 #define PARAM_PART_COUNT_IDX 0
 #define PARAM_NOISE_XY_IDX 1
@@ -121,7 +124,14 @@ static void mdlInitializeSizes(SimStruct *S)
     
     if (!ssSetNumOutputPorts(S, 2)) return;
     ssSetOutputPortWidth(S, OUTPUT_EST_POS, 3);
-    ssSetOutputPortMatrixDimensions(S, OUTPUT_BITMAP, BITMAP_HEIGHT, BITMAP_WIDTH);
+    ssSetOutputPortDataType(S, OUTPUT_BITMAP, SS_UINT8);
+    ssAllowSignalsWithMoreThan2D(S);
+    int dims[3] = { BITMAP_HEIGHT, BITMAP_WIDTH, 3 };
+    DimsInfo_T dimsInfo = { .width = 3*BITMAP_HEIGHT*BITMAP_WIDTH,
+                           .numDims = 3,
+                           .dims = dims};
+    ssSetOutputPortDimensionInfo(S, OUTPUT_BITMAP, &dimsInfo);
+    /* ssSetOutputPortMatrixDimensions(S, OUTPUT_BITMAP, BITMAP_HEIGHT, BITMAP_WIDTH); */
 
     ssSetNumSampleTimes(S, PORT_BASED_SAMPLE_TIMES);
     ssSetNumRWork(S, 0);
@@ -300,13 +310,15 @@ static void mdlStart(SimStruct *S)
        pwork[1] = (void*)last_angles;
 
        /* MCL initialization */
-       l->beacon_cnt = 3;
        l->width = 3.0; /* in m */
        l->height = 2.1;        /* in m */
        /* the noises */
        l->pred_dnoise = NOISE_XY(S);
        l->pred_anoise = NOISE_ANGLE(S);
        l->aeval_sigma = AEVAL_SIGMA(S);
+       l->beacon_miss = 0.0;
+       l->false_beacon = 0.0;
+       
 
        mcl_laser_init(l, PART_COUNT(S));
 }
@@ -325,6 +337,25 @@ static void mdlUpdate(SimStruct *S, int_T tid)
 }
 
 
+static void hsv2rgb(uint8_t rgb[3], float hsv[3])
+{
+       float h=hsv[0], s=hsv[1], v=hsv[2];
+       int i = (int)floor(h*6) % 6;
+       float f = h*6-floor(h*6);
+       uint8_t t = v*255 * (1-s);
+       uint8_t n = v*255 * (1-s*f);
+       uint8_t p = v*255 * (1 - (s*(1-f)));
+       uint8_t e = v*255;
+       switch (i) {
+               case 0: { uint8_t o[3] = {e,p,t}; memcpy(rgb, o, sizeof(o)); break; }
+               case 1: { uint8_t o[3] = {n,e,t}; memcpy(rgb, o, sizeof(o)); break; }
+               case 2: { uint8_t o[3] = {t,e,p}; memcpy(rgb, o, sizeof(o)); break; }
+               case 3: { uint8_t o[3] = {t,n,e}; memcpy(rgb, o, sizeof(o)); break; }
+               case 4: { uint8_t o[3] = {p,t,e}; memcpy(rgb, o, sizeof(o)); break; }
+               case 5: { uint8_t o[3] = {e,t,n}; memcpy(rgb, o, sizeof(o)); break; }
+       }
+}
+
 /* Function: mdlOutputs =======================================================
  * Abstract:
  *    In this function, you compute the outputs of your S-function
@@ -338,7 +369,7 @@ static void mdlOutputs(SimStruct *S, int_T tid)
     struct mcl_laser_state *parts = l->parts;
     
     double *pos = ssGetOutputPortRealSignal(S,OUTPUT_EST_POS);
-    double *bitmap = ssGetOutputPortRealSignal(S,OUTPUT_BITMAP);
+    uint8_t *bitmap = ssGetOutputPortSignal(S,OUTPUT_BITMAP);
     InputRealPtrsType iPtrsMove = ssGetInputPortRealSignalPtrs(S, INPUT_MOVE);
     InputRealPtrsType iPtrsMeasure = ssGetInputPortRealSignalPtrs(S, INPUT_MEASURE);
     int_T             iMeasureWidth = ssGetInputPortWidth(S,INPUT_MEASURE);
@@ -383,28 +414,46 @@ static void mdlOutputs(SimStruct *S, int_T tid)
 /*                 for (i=0; i<angles.count; i++) printf(" a=%5.0f deg", angles.val[i]/M_PI*180); */
 /*                 printf("\n"); */
 
+                   struct mcl_laser_state *parts = l->parts;
                    mcl->update(mcl, &angles);
                    mcl->resample(mcl);
+                   parts = l->parts;
+/*                 for (i=0; i < l->mcl.count; i++) { */
+/*                         printf("%3d: x=%4.2f  y=%4.2g  a=%4.2g b=%d  w=%5.3g\n",  */
+/*                                i, parts[i].x, parts[i].y, parts[i].angle, parts[i].beacon, mcl->weight[i]); */
+/*                 } */
+                   /* ssSetStopRequested(S, 1); */
            }
            *last_angles = angles;
     }
 
     /* Update probability bitmap */
-    for (i=0; i<BITMAP_WIDTH*BITMAP_HEIGHT; i++)
+    /* parts = l->resampled; */
+    parts = l->parts;;
+    for (i=0; i<BITMAP_WIDTH*BITMAP_HEIGHT*3; i++)
            bitmap[i] = 0;
     double max = 0;
     for (i=0; i<mcl->count; i++)
            max = fmax(max, mcl->weight[i]);
     for (i=0; i<mcl->count; i++) {
-           int x, y;
-           double color;
+           int x, y, pixel;
+           double color = 1;
            x = parts[i].x / l->width * BITMAP_WIDTH;
            y = parts[i].y / l->height * BITMAP_HEIGHT;
            y = BITMAP_HEIGHT - 1 - y;
            if (x>=0 && x<BITMAP_WIDTH && y>=0 && y<BITMAP_HEIGHT) {
-                   color = 64.0*log(1+mcl->weight[i])/log(1+max);
-                   color = fmax(color, 16);
-                   bitmap[x*BITMAP_HEIGHT+y] = color;
+                   #if 0
+                   color = log(1+mcl->weight[i])/log(1+max);
+                   /* color = 0.3+0*mcl->weight[i]/max; */
+                   color = fmax(color, 0.2);
+                   #endif
+                   uint8_t rgb[3];
+                   float hsv[3] = {fmod(parts[i].angle, 2*M_PI)/2/M_PI, 1, color};
+                   hsv2rgb(rgb, hsv);
+                   pixel = x*BITMAP_HEIGHT+y;
+                   bitmap[BITMAP_R+pixel] = rgb[0];
+                   bitmap[BITMAP_G+pixel] = rgb[1];
+                   bitmap[BITMAP_B+pixel] = rgb[2];
            }
     }
 
index 2a71b2931d4e3b9703fe80cef629dbd809c0cebf..5fa3c1716436c85c87cb856eb68ab271707ba099 100644 (file)
@@ -43,6 +43,7 @@ function setup(block)
   block.SetSimViewingDevice(1);\r
 \r
   block.SetAccelRunOnTLC(false);\r
+  block.AllowSignalsWithMoreThan2D=true;\r
   \r
   block.RegBlockMethod('PostPropagationSetup', @DoPostPropSetup);\r
   block.RegBlockMethod('ProcessParameters', @ProcessPrms);\r
index 2bd5fba09863dd0092219a74e20cf7881e5611e7..22c069d59cd5704c32f9d101b5cc35bdef256256 100644 (file)
@@ -40,6 +40,7 @@ void mcl_init(struct mcl_model *mcl, unsigned count, void *estimated)
 {
        mcl->count = count;
        mcl->weight = malloc(count*sizeof(*mcl->weight));
+       memset(mcl->weight, 0, count*sizeof(*mcl->weight));
        mcl->estimated = estimated;
 }
 
index 8eadcce697da417c46345e409e4584836a2c856a..5746b9b041b3fb8e930754b8241cd6af3adc0bcd 100644 (file)
@@ -18,9 +18,6 @@ static void mcl_laser_reset(struct mcl_model *mcl)
        struct mcl_laser_state *parts = l->parts;
        int i;
        
-       if (l->beacon_cnt > BEACON_CNT)
-               l->beacon_cnt = BEACON_CNT;
-
        /* particles initialization */
        for (i=0; i<mcl->count; i++) {
                /* generate particles with noises. Starting weight is 1, as we 
@@ -29,6 +26,7 @@ static void mcl_laser_reset(struct mcl_model *mcl)
                parts[i].x = (rand()&0xffff)/65535.0*l->width;
                parts[i].y = (rand()&0xffff)/65535.0*l->height;
                parts[i].angle = (rand() % 360)/360.0*(2.0*M_PI);
+               parts[i].beacon = rand() % BEACON_CNT;
        }                                
 
 }
@@ -52,10 +50,15 @@ static void mcl_laser_predict(struct mcl_model *mcl, void *delta)
                parts[i].x += xdiff + l->pred_dnoise*gaussian_random();
                parts[i].y += ydiff + l->pred_dnoise*gaussian_random();
                parts[i].angle += d->angle + l->pred_anoise*gaussian_random();
-
-               /*printf("x=%f y=%f w=%f r.x=%f r.y=%f\n", 
-                       parts[i].x, parts[i].y, parts[i].weight,
-                       robot.x, robot.y);*/
+               if (drand48() < l->beacon_miss)  parts[i].beacon++;
+               if (drand48() < l->false_beacon) parts[i].beacon--;
+               if (parts[i].beacon >= BEACON_CNT)
+                       parts[i].beacon = 0;
+               if (parts[i].beacon < 0)
+                       parts[i].beacon = BEACON_CNT-1;
+
+/*             printf("%3d: x=%g  y=%g  a=%g b=%d\n",  */
+/*                    i, parts[i].x, parts[i].y, parts[i].angle, parts[i].beacon); */
        }
 
        /* Update the last estimated position without noise */
@@ -74,18 +77,17 @@ static inline double gaussian(double val, double sigma)
 static void mcl_laser_update(struct mcl_model *mcl, void *measurement)
 {
        struct mcl_laser *l = mcl_to_laser(mcl);
-       const struct mcl_laser_state * restrict parts = l->parts;
+       struct mcl_laser_state * restrict parts = l->parts;
        const struct mcl_laser_state * restrict best = &parts[0];
        const struct mcl_laser_measurement *angles = measurement;
-       mcl_thetas theta;
+       double theta;
        double p;
        double diff;
-       int i, it, im;
+       int i, im;
        mcl_weight_t wmax = 0;
 
        /* evaluate the weights of each particle */
        for (i=0; i<mcl->count; i++) {
-               mcl_pos2ang(&parts[i], theta, l->beacon_cnt, l->beacon_color);
                if (parts[i].x < 0 || parts[i].x > l->width ||
                    parts[i].y < 0 || parts[i].y > l->height) {
                        /* We cannot be out of playground */
@@ -95,13 +97,14 @@ static void mcl_laser_update(struct mcl_model *mcl, void *measurement)
 
                mcl->weight[i] = 1;
                for (im=0; im<angles->count; im++) {
-                       p=0;
-                       for (it=0; it<l->beacon_cnt; it++) {
-                               diff = fabs(theta[it] - angles->val[im]);
-                               if (diff > M_PI) diff = 2*M_PI-diff;
-                               p += gaussian(diff, 2*l->aeval_sigma);
-                       }
+                       theta = mcl_beacon_angle(&parts[i], l->beacon_color);
+                       diff = fabs(theta - angles->val[im]);
+                       if (diff > M_PI) diff = 2*M_PI-diff;
+                       p = gaussian(diff, l->aeval_sigma);
                        mcl->weight[i] *= p;
+
+                       parts[i].beacon++;
+                       parts[i].beacon %= BEACON_CNT;
                }
                if (mcl->weight[i] > wmax) {
                        wmax = mcl->weight[i];
@@ -146,7 +149,7 @@ static void mcl_laser_resample(struct mcl_model *mcl)
         * also save one pass as compared to standalone
         * mcl_normalize(). */
        sum = Q[mcl->count];
-       for (i = 1; i <= mcl->count; i++)
+       for (i = 0; i <= mcl->count; i++)
                Q[i] /= sum;
 
        /* We do not store the last element of T since it is always
@@ -197,9 +200,7 @@ struct mcl_model *mcl_laser_init(struct mcl_laser *l, unsigned count)
        l->Q = malloc(count*sizeof(*l->Q));
        l->T = malloc(count*sizeof(*l->T));
 
-       if (l->beacon_cnt > BEACON_CNT)
-               l->beacon_cnt = BEACON_CNT;
-
+       
        /* Initialize method pointers */
        mcl->reset = mcl_laser_reset;
        mcl->predict = mcl_laser_predict;
@@ -211,6 +212,33 @@ struct mcl_model *mcl_laser_init(struct mcl_laser *l, unsigned count)
        return mcl;
 }
 
+double mcl_beacon_angle(const struct mcl_laser_state *part,
+                       unsigned char color)
+{
+       double head, theta;
+       int i;
+       const struct beacon_pos *beacon;
+
+       if (color == BEACON_RED) {
+               head = part->angle + M_PI;
+               beacon = beacon_red;
+       } else {
+               head = part->angle;
+               beacon = beacon_blue;
+       }
+
+       head = (head < 0) ? 2*M_PI + head : head;
+
+
+       i = part->beacon;
+       theta = atan2(beacon[i].y-part->y, beacon[i].x-part->x);
+       /* normalize angles */
+       if (theta < 0) theta = 2*M_PI + theta;
+       theta = (theta-head < 0) ? 
+               2*M_PI+theta-head : theta-head;
+       return theta;
+}
+
 /**
  * Convert the position to angles between robot's head and reflectors 
  * (angles sense is counter-clockwise)
@@ -224,39 +252,10 @@ void mcl_pos2ang(const struct mcl_laser_state *part,
                 mcl_thetas theta,
                 unsigned char cnt, unsigned char color)
 {
-       double head;
        int i;
-
-       if (cnt > BEACON_CNT)
-               cnt = BEACON_CNT;
-
-       if (color == BEACON_RED)
-               head = part->angle + M_PI;
-       else
-               head = part->angle;
-
-       head = (head < 0) ? 2*M_PI + head : head;
-
-       /* angles between 0 and reflectors (with center at robot position) */
-       if (color == BEACON_RED) {
-               theta[0] = atan2(BEACON_RED1_Y-part->y, BEACON_RED1_X-part->x);
-               theta[1] = atan2(BEACON_RED2_Y-part->y, BEACON_RED2_X-part->x);
-               theta[2] = atan2(BEACON_RED3_Y-part->y, BEACON_RED3_X-part->x);
-               theta[3] = atan2(BEACON_RED4_Y-part->y, BEACON_RED4_X-part->x);
-       } else {
-               theta[0] = atan2(BEACON_BLUE1_Y-part->y, BEACON_BLUE1_X-part->x);
-               theta[1] = atan2(BEACON_BLUE2_Y-part->y, BEACON_BLUE2_X-part->x);
-               theta[2] = atan2(BEACON_BLUE3_Y-part->y, BEACON_BLUE3_X-part->x);
-               theta[3] = atan2(BEACON_BLUE4_Y-part->y, BEACON_BLUE4_X-part->x);
-       }
-
-       for (i=0; i<cnt; i++) {
-               /* normalize angles */
-               if (theta[i] < 0) theta[i] = 2*M_PI + theta[i];
-               theta[i] = (theta[i]-head < 0) ? 
-                       2*M_PI+theta[i]-head : theta[i]-head;
+       struct mcl_laser_state p = *part;
+       for (i=0; i<BEACON_CNT; i++) {
+               p.beacon = i;
+               theta[i] = mcl_beacon_angle(&p, color);
        }
-
-       /* sort and store results */
-       qsort(theta, cnt, sizeof(double), cmpd);
 }
index 4ab0772416a06b72690a551923ac82d42ac72a02..f8b2169b91e8fe13c7d2553ab6f25498776d3aba 100644 (file)
@@ -3,13 +3,15 @@
 
 #include <mcl.h>
 #include <robodim_eb2008.h>
+#include <stdint.h>
 
 #define MCL_LASER_MAX_MEASURE 10
 
 struct mcl_laser_state {
-       double x;
-       double y;
-       double angle;
+       float x;
+       float y;
+       float angle;
+       int8_t beacon; /* from which beacon we expect next measure */
 };
 
 struct mcl_laser_measurement {
@@ -28,6 +30,8 @@ struct mcl_laser {
        /* noises: movement noise,  */
        double pred_dnoise;     /* prediction distance noises */
        double pred_anoise;     /* prediction angle noises */
+       double beacon_miss;     /* beacon miss probability */
+       double false_beacon;    /* false beacon probability */
        /* used to evaluate the particles */
        double aeval_sigma;     /* sigma used for angles evaluating */
        /* size of the playground (in meters) */
@@ -44,7 +48,6 @@ struct mcl_laser {
        /* measured data */
        void *data;
 #endif 
-       unsigned char beacon_cnt;       /* number of beacons */
        unsigned char beacon_color;     /* red/blue beacons */
 
        /* Temporary arrays for resampling */
@@ -54,7 +57,8 @@ struct mcl_laser {
 
 
 struct mcl_model *mcl_laser_init(struct mcl_laser *l, unsigned count);
-
+double mcl_beacon_angle(const struct mcl_laser_state *part,
+                       unsigned char color);
 void mcl_pos2ang(const struct mcl_laser_state *part,
                 mcl_thetas theta,
                 unsigned char cnt, unsigned char color);
index 908beb6eb25766eaddc19643dac706ea022b83ec..856faf512d7022b19fade31cf909281ad271f019 100644 (file)
@@ -41,11 +41,10 @@ void testmcl_init()
        l.pred_anoise = 0.03;
        l.aeval_sigma = 0.90;
 
-       l.beacon_cnt = BEACON_CNT;
        l.beacon_color = BEACON_BLUE;
 
        /* Initialize with 5000 particles */
-       mcl = mcl_laser_init(&l, 5000);
+       mcl = mcl_laser_init(&l, 5);
 }
 
 int main(int argc, char *argv[])
@@ -60,7 +59,7 @@ int main(int argc, char *argv[])
        struct mcl_laser_state *est_pos;
        struct mcl_laser_state meas_pos;
        mcl_thetas theta;
-       int i;
+       int i, beacon;
 
        /* histogram parameters */
        hist_move.count = HIST_COUNT;
@@ -80,16 +79,21 @@ int main(int argc, char *argv[])
        testmcl_init();
 
        meas_pos.x = 1.0;
-       meas_pos.y = 1.0;
+       meas_pos.y = 1.05;
        meas_pos.angle = DEG2RAD(180);
-       mcl_pos2ang(&meas_pos, theta, l.beacon_cnt, l.beacon_cnt);
-       meas_angles.count = l.beacon_cnt;
-       for(i=0; i<l.beacon_cnt; i++)
+       meas_pos.beacon = 0;
+       mcl_pos2ang(&meas_pos, theta, 0, BEACON_BLUE);
+       meas_angles.count = BEACON_CNT;
+       for(i=0; i<BEACON_CNT; i++)
                meas_angles.val[i] = theta[i];
-
-
+       l.parts[0] = meas_pos;
+       beacon = 0;
        /* Main boucle */
        for(i=1; i<TEST_COUNT; i++) {
+               meas_angles.count = 1;
+               meas_angles.val[0] = theta[beacon++];
+               beacon %= BEACON_CNT;
+
                /* time measurement */
                clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts_start);
                mcl->predict(mcl, &delta);