Moving sensor line follower!

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Moving sensor line follower!

Postby hb.mortensen » Wed Apr 02, 2008 11:31 am

Hey!

We're doing a project about a line follower NXJ with a moving sensor on the front of the robot.
To track if there's a line we use for-loops for every degree it turns (we use motor port A) and track the light sensor readings. But this makes the sensor really slow and the motion is very 'laggy' and unstable.

Anyone who can help us getting a more smooth circular motion?

Our loop looks something like this:

for (int v=0; v<80; v = v+1){
if(Motor.A.isMoving()==true){
Motor.A.flt();
}
else{
Motor.A.rotate(1);
}
int vinkel = Motor.A.getTachoCount();
LCD.clearDisplay();
LCD.refresh();
LCD.drawInt(vinkel, 3, 9, 0);
LCD.refresh();
}

Didnt include the light sensor part, since that's not the problem at the moment. Her its only rotating about 80 degrees to the right, so we got 3 more of these (80 degrees each) to cover the 160 degree vision field.

Appreciate it!

Regards
Henrik
hb.mortensen
New User
 
Posts: 10
Joined: Wed Apr 02, 2008 11:26 am

Postby hb.mortensen » Wed Apr 02, 2008 11:40 am

Think I fixed it with:
Something like:

Motor.A.rotateTo(90, true);
while(Motor.A.isRotating()){
int vinkel = Motor.A.getTachoCount();
if(light.readValue() > blackWhiteThreshold){
P1 = vinkel;
Motor.A.stop();
}
}

IS that the way to do it properly? Seems to work... :)
hb.mortensen
New User
 
Posts: 10
Joined: Wed Apr 02, 2008 11:26 am

Postby 99jonathan » Thu Apr 03, 2008 3:55 am

Motor.A.rotateTo(90, true);
while(Motor.A.isRotating()){
if(light.readValue() > blackWhiteThreshold){
P1 = Motor.A.getTachoCount();
Motor.A.stop();
}
}

that'll cut out a meaningless variable and speed it up a slight bit
99jonathan
Moderator
 
Posts: 122
Joined: Thu Mar 01, 2007 5:30 am

Postby hb.mortensen » Tue Apr 15, 2008 11:28 am

It's working now, and while turning from left to right we note the degrees for left and right edges of the line, and the same on the way back. While the robot stands still we've tested the accuracy of this, and it seems that the angle varies from 5-10 degrees comparing the clockwise and counter clockwise motions. How to fix this??

Our motor seems to move a bit laggy as well, even though i use smoothAcceleration(true) and regulateSpeed(true). How can we improve this motion to become more smooth and constant?
hb.mortensen
New User
 
Posts: 10
Joined: Wed Apr 02, 2008 11:26 am


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff