views:

43

answers:

1

I'm working on a robot localization simulator and I created a class called "landmark".

The end result is going to be a robot that is always centered and always faces the top of the screen. As it turns, the birds eye view map will rotate around the robot. To accomplish this, I'm assuming I can rotate one class and have all elements inside rotate as well.

So, the landmark class has properties x,y, label, and radius. This is suppose to simulate a tree location in a forest.

To test everything, I need "forest data," and I wrote a script to generate 100 trees in a 100m x 100m area. The script automatically generates values within an acceptable range for x,y, radius. The generated data is stored in an object called tempForest and is 100x3.

Ideally, I want to create a class called "landmarks" (plural) that has 100 landmark instances inside.

How would I instantiate 100 instances of landmark in one instance of landmarks using that randomly generated data?

Ideally, I'd just type treeBeacons = landmarks(); and it would randomly populate 100 (user definable, set in config file) instances with x, y, radius data.

I'm not sure how to deal with a dynamic array of class "Landmark", inside another single class "landmarks."

Any ideas?

+1  A: 

I'd create a class 'landmarks' that has a property 'fixedPositions', a property 'viewDirection', and a dependent property 'apparentPositions'.

If you type treeBeacons=landmarks;, you can have the constructor fill in fixedPositions, which is the list of positions of your trees. You then set treeBeacons.facing to whatever direction the robot is facing, and you can get the forest relative to the robot as treeBeacons.apparentPositions.

I don't think it is necessary to have your trees be objects, given your description. However, if your trees really need to be individual objects, you have the constructor of landmarks create objects instead of coordinates and store them in fixedPositions (or trees) instead. Let me just suggest that you do not use both landmarks and landmark as different variable names. At least the common people like me have a very hard time telling the two apart.

classdef landmarks
    properties
        fixedPositions %# positions in a fixed coordinate system. [ x, y, radius ]
        facing = 0;%# direction in which the robot is facing
    end
    properties (Dependent)
        apparentPositions
    end
    methods
        function obj = landmarks(numberOfTrees)
             %# set  obj.fixedPositions here depending on the number of trees. 
        end
        function out = get.apparentPositions(obj)
            %# rotate obj.positions using obj.facing to generate the output
        end
        function plotMap(obj,fixedOrApparent)
            %# plots the map, either using fixed or apparent coordinates (good for testing)
        end
    end
end
Jonas
So fixed positions would be the 100x3 output from the tree generator?Would apparent positions change if heading changes? I assume I would just add an event listener to apparent positions and fire it off when I change heading?
pinnacler
@pinnacler: Yes, fixedPositions is the output from the tree generator. Since apparentPositions is a dependent function, it is re-generated whenever it is requested using the most recent values for 'facing' - thus, there is no need to use events.
Jonas