This site requires JavaScript, please enable it in your browser!
Greenfoot back
ub3030
ub3030 wrote ...

2011/11/20

just looking for a little help

ub3030 ub3030

2011/11/20

#
hello i have a project to due that evolves me making a lawn mower that mows the lawn with AI. i know there are a few ways i could go about it but i am trying to see if anyone here has any input on what would be the best way. its kind of a darpa challenge. i just need to cut grass and it cant be random. any input would be great thanks.
mjrb4 mjrb4

2011/11/20

#
Is there any definition on the shape of the lawn? If it's rectangular I'd just go up and down in strips - well that's how I mow the lawn!
ub3030 ub3030

2011/11/21

#
the lawn and everything is already there for you. all i need to do is write the code for the lawn mower.
ub3030 ub3030

2011/11/21

#
i need to turn this, into a AI mower. public class RandomMower extends Mower { private int state=0; /** * Act - do whatever the AIMower wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { switch (state) { case 0: throttleUp(); state=1; break; case 1: if (bumpSensor()==true) { turnLeft(15); } else { switch (Greenfoot.getRandomNumber(5)) { case 0: turnLeft(Greenfoot.getRandomNumber(2)*15); break; case 1: turnRight(Greenfoot.getRandomNumber(2)*15); break; } } state=1; break; } // Call the Mower.act() method super.act(); } }
mjrb4 mjrb4

2011/11/21

#
You didn't answer the previous question - is the lawn always rectangular? Or could it be any shape (triangle, pentagon, irregular septagon...) If it's rectangular and you know your starting position then you can start in the bottom left, wait until you hit something then turn right 90 degrees, go forward your width, turn 90 degrees again then loop over again (until you hit something.) If it can be any shape, things get more complicated!
ub3030 ub3030

2011/11/21

#
its rectangular with objects in the way
ub3030 ub3030

2011/11/21

#
so would i use the bumpSensor(); then if true turn left or right (90)? and just loop over and over?
mjrb4 mjrb4

2011/11/21

#
Well if it has objects in the way that makes it a bit more complicated. You could keep track of your position by judging how much you've turned / travelled then work out from that if something you've hit is a likely edge or obstacle. That might give you a starting point. With these sorts of problems it's often easier to map out your logic on paper first, then turn it into code later.
You need to login to post a reply.