[Pogamut-list] Rotate bot in the right angle when hearing noise

michal.bida pogamut-forum at diana.ms.mff.cuni.cz
Thu Apr 28 09:47:07 CEST 2011


Re: Rotate bot in the right angle when hearing noise

Author: michal.bida

TurnTo command does not interrupt moving. However, pathExecutor overrides turn command - because it is sending focus attribute in move commands, that overrides anything sent in TurnTo command immediately. 

The rotation exported in HearNoise command is absolute rotation the bot should be facing when wanting to face the noise. So just issue TurnTo command and set ROTATION attribute with the rotation obtained through HearNoise.
 
Is you cast Rotation toLocation tou obtain a direction vector - not absolute one. Turning to a direction vector doesn't make sense, because it does not represent a location, it represent just a direction of the point (from the location of the bot). 

Look at the implementation of strafeLeft, Right methods in getLocomotion module in Pogamut, where you see examples how to compute directions and positions in various angles from the bot. 

E.g. this code makes bot strafeLeft by distance specified in the argument:
{CODE()}
	public void strafeLeft(double distance) {
		if (self == null) {
			self = agent.getWorldView().getSingle(Self.class);
		}
		if (self != null) {
			Location startLoc = self.getLocation();
			Location directionVector = self.getRotation().toLocation();
			Location targetVec = directionVector.cross(new Location(0, 0, 1))
					.getNormalized().scale(distance);

			agent.getAct().act(
					new Move().setFirstLocation(startLoc.add(targetVec))
							.setFocusLocation(
									startLoc.add(directionVector
											.getNormalized().scale(
													FOCUS_DISTANCE))));
		}
	}
{CODE}

If you are using pathExecutor Jakub is right that you should change focus of the bot (which is an absolute position). You'll need to do something like this:

{CODE()}
//pseudo code
//first we'll get the direction vector 
Location directionVector = HearNoise.getRotation().toLocation().getNormalized();

//we will need also bot location beacause we need to compute absolute focus point location
Location botLocation = info.getLocation();

//now we have everything needed for the computation. We normalized our direction vector which is a good idea, because generally you don't know how "big" it is, so we will scale it, so our the distance between botlocation and focus point location is big enough (in example below it will be 500 ut units = ~500 cm)
Location newAbsoluteFocusLocation = botLocation.add(directionVector.scale(500));

pathExecutor.setFocus(newAbsoluteFocusLocation);

//To tell path executor you dont want it to focus something anymore:

pathExecutor.setFocus(null);

{CODE}

Look at linear algebra and vector computations - it will help you a lot when developing bots, because you need to compute location and angle and test some conditions such as what is closer to the bot very often.

Best,
Michal

-- 
Reply Link: <http://diana.ms.mff.cuni.cz/main/tiki-view_forum_thread.php?forumId=4&comments_reply_threadId=4&comments_parentId=708&post_reply=1#form>





More information about the Pogamut-list mailing list