I agree with the comments: It is hard to imagine what an "acceptable" answer could be. As simple as such a task may seem, it's a highly complex process that involves the classical "Sense-Plan-Act" cycle of
- Detecting objects with the sensors and integrating this into your knowledge about the world
- Planning a path, including the acquired knowledge
- Acting by moving towards the goal
There are many unknowns here. For example, what about "degenerate" cases, where the robot is surrounded by a wall of obstacles? Does the robot know its orientation (i.e. the direction in which it is heading)? How to you control the robot? Using the DifferentialPilot class? Does the robot know its size (width) in centimeters, so that it may detect whether it can pass through two obstacles that are close together? Should the robot try to take some "shortest path", or is it OK to extensively explore the world for a while? Is it valid to assume hat obstacles are detected via the distance sensor and the parking area via the color sensor? Is it true that the color sensor only has a range of a few centimeters? And maybe most importantly: Do you know where the parking position is?
Considering all these questions, one can only try to give general hints about possible approaches. I'll try to do this before the answer is closed. But this should not be considered as a really profound step-by-step solution, but only as suggestions, because all the questions mentioned above have to be answered before one can say whether a solution might work at all (and whether it will work is another question...)
You should think about your intended representation of the "World" (or describe this representation, if you already thought of one!). I could imagine that some sort of "grid" may be sufficient here. But it would probably be beneficial to use a LineMap for the representation of the world, because this enables you to use the existing infrastructure of the NXT API.
Once your have a representation of the world, you have to find its center. Again, when there are obstacles, this may not even be possible (I'm thinking about the Allegory of the Cave here). But when there are no obstacles, you could just spin the robot in place, about 360°: This will provide distance information for all the wall points. Given this information, it should be possible to detect the corners of the world - these would exactly be the corners of the bounding rectangle of the LineMap
. Computing the average of these corner positions will yield the center.
After moving to the center, you have to move to the parking position. If I understood the setup correcly, you do not even know where this parking position is. In this case, you'd have to start a systematic exploration: You could try to move in "spirals" outwards, starting from the center. Whenever you encounter an obstacle, you try to move to the next free point on this "spiral". If you know where the parking position is, you could try to move directly to this position, avoiding all obstacles.
In both cases, you'd have a "current position" and a "target position" - the latter either being the "next free point on the spiral", or the "parking position". In order to find a path between these points in the world map, you could use a A* search algorithm. Fortunately, the NXT API already offers a ShortestPathFinder. Integrating this so that it properly controls your robot may nevertheless be tricky. But if you use, for example, the DifferentialPilot
class, there are probably many resources of free/sample source code for tasks that are already similar to what you are trying to do, maybe you can find some ... "inspiration" there.