Welcome, Guest. Please login or register.
June 19, 2013, 11:11:17 PM
<< Back to The NXT Step Home Page    Home Help Search Login Register

+  The NXT STEP Forum
|-+  Programming Software
| |-+  NXT-G
| | |-+  Automated door panel with NXT
« previous next »
Pages: [1] 2 Print
Author Topic: Automated door panel with NXT  (Read 4313 times)
itry
Newbie
*
Posts: 6


View Profile
« on: June 10, 2007, 05:08:48 PM »

Hi.  I'm new to NXT, and trying to figure out the basics of programming.  I need a light sensor to detect change in ambient light levels, and if above a certain range to activate rotation of a motor in the forward direction 4 turns & stop, and if below a certain range to activate rotation of the same motor in the reverse direction 4 turns and stop.  The motor needs to complete its assigned 4 rotations before being allowed to reverse.  The program needs to run continuously, forever, so that once the light level changes beyond the threshold in either direction, the motor will react.  HELP?
Report to moderator   Logged
JimKelly
Nxt Step Authors
Hero Member
*****
Posts: 232


View Profile
« Reply #1 on: June 10, 2007, 07:36:28 PM »

To do this, you'll obviously need to place everything in one LOOP block.  The LOOP block will be set to run forever.

Inside the LOOP block, you'll do the following:

1.  Send the light value from the Light sensor block (using a data wire) to a COMPARE block.  You'll use this COMPARE block to compare the value (from Light Sensor) to a value you define... and you'll set to compare whether it is equal to, less than, or greater than.

2.  You'll also want to send that same value to a second COMPARE block.  This one will also compare the other value (maybe the lower value)... again, set it to check for less than or greater than and then set your value to compare it to.

3.  You can then drag a data wire out of each of these COMPARE blocks - one wire goes into one SWITCH block and the other wire goes into a second SWITCH block.  The data wire will be a Logic type (True or False) and the SWITCH blocks will be configured to test for a Logic value.

So, if you the first COMPARE block detects a light value "greater than" your set value, the first SWITCH block will run whatever is dropped in its "True" section...

And, if the second COMPARE block detects a light value "less than" your set value, a True value is sent to the second SWITCH block and the "True" section is run for it...

Jim

Report to moderator   Logged
JimKelly
Nxt Step Authors
Hero Member
*****
Posts: 232


View Profile
« Reply #2 on: June 11, 2007, 08:56:45 AM »

Itry,

I posted one solution to your question on the blog with a screenshot of the program.  Hope this helps.

Jim
Report to moderator   Logged
admin
Administrator
Sr. Member
*****
Posts: 152


View Profile WWW
« Reply #3 on: June 11, 2007, 10:06:55 AM »


In reply to blog entry:
http://thenxtstep.blogspot.com/2007/06/programming-question-from-our-forum.html

Couldn't you also program it with light-sensor switch blocks?
see attached images here


* light1.PNG (87.73 KB, 546x596 - viewed 258 times.)
Report to moderator   Logged
brdavis
Nxt Step Authors
Hero Member
*****
Posts: 547


View Profile
« Reply #4 on: June 11, 2007, 12:45:41 PM »

Here's yet another way to do it (well, if I figured out how to post it in the forum) - remember you can wire in things like direction into those motor blocks.

--
Brian Davis


* Picture 1.png (78.37 KB, 625x339 - viewed 320 times.)
Report to moderator   Logged
Robolab 2.9
Nxt Step Authors
Sr. Member
*****
Posts: 131


View Profile
« Reply #5 on: June 11, 2007, 12:59:09 PM »

David,

Wouldn't the second swtich in your example be unnessecary? Since the first switch already decided if it was black or white, I don't think you need the second one.

Also, what if it so happened that the first time the robot sampled, it was below the threshold, the second time it sampled it, it was above the threshold? Then the robot wouldn't move at all!

Richard
Report to moderator   Logged
admin
Administrator
Sr. Member
*****
Posts: 152


View Profile WWW
« Reply #6 on: June 11, 2007, 01:22:59 PM »

Richard,
The first switch checks for > 50.. if true the moves forward,
if false then there needs to be another evaluation to see if the number is < 20

"Also, what if it so happened that the first time the robot sampled, it was below the threshold, the second time it sampled it, it was above the threshold? Then the robot wouldn't move at all!"
 
I suppose that is possible however is it also possible ( and much more likely ) that the ambient light level would hit two or more threshold levels whilst waiting for a move block to finish its rotations.

As a result I'd say it is OK to do two readings in one pass of the loop given then they will happen so close together.

 





Report to moderator   Logged
Robolab 2.9
Nxt Step Authors
Sr. Member
*****
Posts: 131


View Profile
« Reply #7 on: June 11, 2007, 04:58:22 PM »

David,

Ah... You can't tell just by looking at the pic without looking at the block specs... Yeah, my way would only allow one threshold.

Yeah, I know it's pretty safe... I was just messin' around.

Richard
Report to moderator   Logged
admin
Administrator
Sr. Member
*****
Posts: 152


View Profile WWW
« Reply #8 on: June 11, 2007, 05:07:37 PM »

Richard,

Yes.  I should have added comments.  I was just offering a comparison to Jim's screen shot that you see on the blog posting.

I think we would all be better off with a switch block that offers more then two cases.

 Grin
Report to moderator   Logged
Robolab 2.9
Nxt Step Authors
Sr. Member
*****
Posts: 131


View Profile
« Reply #9 on: June 12, 2007, 12:05:07 PM »

Yes.  I should have added comments.  I was just offering a comparison to Jim's screen shot that you see on the blog posting.

I thought educators were supposed to encourge students to use comments? ;-)

I think we would all be better off with a switch block that offers more then two cases.

But then again it would that one more bit of proccessing to get that second reading so....

Richard
Report to moderator   Logged
admin
Administrator
Sr. Member
*****
Posts: 152


View Profile WWW
« Reply #10 on: June 12, 2007, 01:13:44 PM »


A Switch block with more than two Cases would eliminate the need to nest Switch blocks so there wouldn't be a second reading ( not that a 2nd reading a bad thing )

Switch light-sensor-value
case > 50  then forward
case < 20 then backward
else  do nothing

Report to moderator   Logged
JimKelly
Nxt Step Authors
Hero Member
*****
Posts: 232


View Profile
« Reply #11 on: June 12, 2007, 02:15:25 PM »

This is fun... I'm learning something new all the time Smiley

Jim
Report to moderator   Logged
admin
Administrator
Sr. Member
*****
Posts: 152


View Profile WWW
« Reply #12 on: June 13, 2007, 07:07:51 AM »

Here's yet another way to do it (well, if I figured out how to post it in the forum) - remember you can wire in things like direction into those motor blocks.
--
Brian Davis


Here's an interesting observation.  It looks like you can't run a wire through a switch block and connect it to the motor block unless you have the flat-view of the switch turned off.   This is actually mentioned in the Switch-help section although  I'm not sure why  this would be design intent.
Report to moderator   Logged
brdavis
Nxt Step Authors
Hero Member
*****
Posts: 547


View Profile
« Reply #13 on: June 13, 2007, 12:19:57 PM »

It's not (I think) the design intent, as much as the complexity of the data dependancy of wires crossing boundries of structures like that. In "tabbed view", wires can cross in and connect with block inside a structure, but not across from state to state. In "flat view", you could create a wire that runs from the "true" state to the "false" state, for instance, which makes no sense - such a wire could function, and in fact half the time would hang the execution as a block waits for a valid signal to come in on a wire that can never happen.

In short, it's not a design consequence, but a natural aspect of data dependancy in wires. See, isn't that clear as mud Grin?

--
Brian Davis
Report to moderator   Logged
mike123
Jr. Member
**
Posts: 12


View Profile
« Reply #14 on: June 19, 2007, 08:35:03 AM »

Last time i checked mud wasn't so clear  Cheesy
Report to moderator   Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!