Go to Post Remember, GP doesnt just need to apply to FIRST; if we all apply in our lives as a whole, the world will be a better place. - Dillon Compton [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 27-08-2003, 08:57
ZACH P. ZACH P. is offline
Insert Custom User Title
#0321 (Robolancers)
 
Join Date: Jan 2003
Location: Philly!!
Posts: 228
ZACH P. is on a distinguished road
Send a message via AIM to ZACH P.
Comparing Sensor Readings in NQC

Hey guys, I'm prototyping some designs using the LEGO Mindstorms, and Im using Not Quite C . I'm new to this language, and have never worked with C before. That said, I need some help. What I need is tips/help on creating a program that reads the raw value of SENSOR_1, saves it, and then takes another reading and compares it to the origional to see if there was a change. Basically i need a program to monitor the sensor, and then start another task if there is a change in the reading. Any help would be much appreicated.
P.S. If you are going to post code, please include comments that explain it, as i am trying to learn this language. Thanks.
__________________
pi is exactly 3

IM me at: zmstr265
  #2   Spotlight this post!  
Unread 30-08-2003, 14:56
Josh Hambright's Avatar
Josh Hambright Josh Hambright is offline
{Error Processing Custom Title}
AKA: oneangrydwarf/jtosh
no team (old school gangsta)
Team Role: Alumni
 
Join Date: Apr 2002
Rookie Year: 2000
Location: Indiana
Posts: 1,421
Josh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond reputeJosh Hambright has a reputation beyond repute
Send a message via AIM to Josh Hambright
I haven't used NQC in like 2 years but if i remeber correctly you should be able to take the value of the sensor and store it in a variable and compare that variable to the current value, if the values are different then you can tell it to do something using an if else statement.

Look around on the net i know that there are some good tutorials out there if you look for them.

Goodluck and sorry i couldn't be more helpful.
__________________
Former 461 Student/Mentor. Former 1272 and 1018 Mentor. Team 1555 Super-Fan.
Science and Engineering Can Open New Doors. --S.E.C.O.N.D.--
=~=!=@= #=$=%=
Co-Founder IndianaFIRST

Share your FIRST photos on Flickr!
  #3   Spotlight this post!  
Unread 30-08-2003, 16:47
rlowerr_1's Avatar
rlowerr_1 rlowerr_1 is offline
Registered User
#0930 (M³)
 
Join Date: Jan 2002
Location: Wisconsin
Posts: 61
rlowerr_1 is an unknown quantity at this point
Send a message via AIM to rlowerr_1
Code:
int rawvalue;

task main()
{
  SetSensor(SENSOR_1,SENSOR_LIGHT);
  rawvalue = SENSOR_1;
  OnFwd(OUT_A);
  until (rawvalue != SENSOR_1);
  OnRev(OUT_A);
}
Alright another mindstormer!

I think the above code is what you need. I will explain it line by line:

int rawvalue; - creates a variable named rawvalue in which I will store to reading from sensor_1

SetSensor(SENSOR_1,SENSOR_LIGHT); - Sets sensor port 1 to a light sensor

rawvalue = SENSOR_1; - takes the value of sensor 1 and stores it in the variable

OnFwd(OUT_A) - turns motor A on and runs it forward

until (rawvalue != SENSOR_1); - the program will not continue until the rawvalue doesnot equal sensor 1 (In other words the sensor value has changed from when you last stored it)

OnRev(OUT_A); - once the value of sensor 1 changes motor A will be run in reverse

I hope this helps/is what you needed. If not just respond.
__________________
Ryan Lowerr - Ryan@lowerr.com
Check out my LEGO creations here!
  #4   Spotlight this post!  
Unread 30-08-2003, 17:08
ZACH P. ZACH P. is offline
Insert Custom User Title
#0321 (Robolancers)
 
Join Date: Jan 2003
Location: Philly!!
Posts: 228
ZACH P. is on a distinguished road
Send a message via AIM to ZACH P.
Yep, thanks guys. Thats basically exactly what i needed. Now i just need to write a function to convert the raw value of the sensor into an angle reading, and then another task for motor control.
__________________
pi is exactly 3

IM me at: zmstr265
  #5   Spotlight this post!  
Unread 30-08-2003, 17:13
rlowerr_1's Avatar
rlowerr_1 rlowerr_1 is offline
Registered User
#0930 (M³)
 
Join Date: Jan 2002
Location: Wisconsin
Posts: 61
rlowerr_1 is an unknown quantity at this point
Send a message via AIM to rlowerr_1
You’re welcome, glad I could help. But do you mind if I ask what it is that you are prototyping?
__________________
Ryan Lowerr - Ryan@lowerr.com
Check out my LEGO creations here!
  #6   Spotlight this post!  
Unread 30-08-2003, 17:33
ZACH P. ZACH P. is offline
Insert Custom User Title
#0321 (Robolancers)
 
Join Date: Jan 2003
Location: Philly!!
Posts: 228
ZACH P. is on a distinguished road
Send a message via AIM to ZACH P.
A camera-equipped rover to aid the mobility impaired, particually those in wheelchairs. I need that code for motor control, because although we are using an R/C remote for the link, im gonna need a microcontroller to mix the signals together, because im using tank-type steering.
__________________
pi is exactly 3

IM me at: zmstr265
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Spreadsheet comparing ALL First motors Nuts4FIRST Motors 0 08-01-2002 09:20


All times are GMT -5. The time now is 19:55.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi