View unanswered posts | View active topics It is currently Wed Aug 05, 2020 6:59 pm

Reply to topic  [ 2 posts ] 
Exit Loop that reads EV3 IR sensor while motor moving 
Author Message

Joined: Thu Mar 26, 2015 11:06 am
Posts: 5
Post Exit Loop that reads EV3 IR sensor while motor moving
I am trying to detect the location of an object by taking readings from an IR sensor mounted on a motor. The motor turns allowing the IR sensor to 'sweep' the area. The smallest IR readings will indicate the objects presence, and the motor would return to the encoder reading position where the smallest IR reading was found.

I am having an issue figuring out a way to exit the repeatUntil loop that is doing the sweep and reading the IR if the motor stops moving for some reason. Such as the motor hitting something that prevents the sweep.

What is the best method to exit the loop in this case?

Ideally once the object is found it should exit the loop as well, which would be indicated by the IR readings reaching a low point and then starting to increase again.

motor[motorA] = -20;
repeatUntil( getMotorEncoder(motorA) == -250)
motor[motorA] = -20;
if (SensorValue[IRreading] < IR_value)
IR_value = SensorValue[IRreading];
object_position = getMotorEncoder(motorA);

motor_position = getMotorEncoder(motorA)-object_position;
moveMotorTarget(motorA, motor_position, 100);

Tue Apr 21, 2015 11:00 am

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post Re: Exit Loop that reads EV3 IR sensor while motor moving
There are many ways but here is one...

Add a boolean variable called move_on
Set it to false before the loop
Change the loop to repeat until move_on = true
Use IF statements to set move_on to true in the loop based on the encoder position or IR sensor

Tue Apr 21, 2015 11:35 am
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.