View unanswered posts | View active topics It is currently Wed Jun 20, 2018 9:39 am






Reply to topic  [ 6 posts ] 
Sensor Troubles 
Author Message
Rookie

Joined: Fri Mar 06, 2015 8:58 am
Posts: 4
Post Sensor Troubles
Hello all,

I've had a decent amount of experience with icon based programming, but this is my first foray into C-programing with Lego Mindstorms and NXT's.

I pulled up the online training program and ran through the motor tutorial without any problems and moved onto the sensor programs.This is where my problems began. Neither my written programs nor the pre-written sample programs that involve sensors seem to be working correctly.

The tutorial and all other help topics I could find all say that a touch sensor only has two values "0" and "1." Yet, when I pull up the NXT Device Debugger, my Touch Sensor values are "1023" when not pressed and about "181" when pressed. I suspect this is why the programs are not running properly. However, even when I edit the code to work based off those values, the programs still do not run correctly.

Any help would be much appreciated, thank you in advance. :bigthumb:

Possible helpful info:
RobotC Version: 4.10
Platform: NXT
OS: Windows 7 Professional


Fri Mar 06, 2015 9:10 am
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: Sensor Troubles
The NXT Devices window will show the raw values of the sensors attached to the NXT; however, ROBOTC will convert the values to more usable values (in the case of the touch sensor, a value of 1 when pressed or 0 when released). These values will appear in the 'Robot -> Debugger Windows -> Sensors' debug menu when the NXT is attached and the program is running.

The issue you are encountering is most likely caused by a programming error; can you post your code using the [code] tags (and let us know which line specifically is giving you the issues)?

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Fri Mar 06, 2015 10:56 am
Profile
Rookie

Joined: Fri Mar 06, 2015 8:58 am
Posts: 4
Post Re: Sensor Troubles
Sure, it's just the sample program that came with the software: "Go until Push"

It seems to skip the Motor C and Motor B forward at 100% lines completely. I am assuming that it does that because it is not sensing that the value is "0" because my touch sensor is reading "1023" on the debugger. However, even when I alter the program to match that value, it still skips that part of the 'while' code.

#pragma config(Sensor, S1, touchSensor, sensorTouch)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

/*--------------------------------------------------------------------------------------------------------*\
|* *|
|* - Go until Push - *|
|* ROBOTC on NXT *|
|* *|
|* This program allows your taskbot to move forward indefinately while monitoring a Touch Sensor. *|
|* If the Touch Sensor is bumped, the robot will reverse and stop. *|
|* *|
|* ROBOT CONFIGURATION *|
|* NOTES: *|
|* 1) The Touch Sensor should be mounted on the front. *|
|* *|
|* MOTORS & SENSORS: *|
|* [I/O Port] [Name] [Type] [Description] *|
|* Port B motorB NXT Right motor *|
|* Port C motorC NXT Left motor *|
|* Port 1 touchSensor Touch Sensor Front mounted *|
\*---------------------------------------------------------------------------------------------------4246-*/


task main()
{
while(SensorValue(touchSensor) == 0) // While the Touch Sensor is inactive (hasn't been pressed):
{
motor[motorB] = 100; /* Run motors B and C forward */
motor[motorC] = 100; /* with a power level of 100. */
}
// Otherwise (the touch sensor has been activated [pressed] ):
motor[motorB] = -75; /* Run motors B and C backwards */
motor[motorC] = -75; /* with a power level of -75. */

wait1Msec(1000); // Wait 1000 milliseconds (1 second) before moving to further code.
}


Fri Mar 06, 2015 12:24 pm
Profile
Rookie

Joined: Fri Mar 06, 2015 8:58 am
Posts: 4
Post Re: Sensor Troubles
I am experiencing the same problems with the ultrasonic sensor as well. I've set it to reverse when anything comes within 25cm, as per the online directions. However, the robot reverses even when there is no objects near it. I've even moved any objects that might get caught in it's peripheral vision. Then at other times, with absolutely no changes to the programing, it runs as it should. But 9 times out of 10 it doesn't. It just keeps going in reverse and the debugger reads out the the sensor keeps reading exactly "25" Even as it moves.

I know I am new at this, but I feel like this is a systematic issue with this somewhere along the line. The sensors worked fine when I did icon based programing so it's not them. Same with the cables. I've rotated in a different NXT block and still the same problem. Could it be the firmware?

Really appreciate any help I can get here...

Here's the code I am using:

#pragma config(Sensor, S4, sonarSensor, sensorSONAR)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()
{

while(SensorValue(sonarSensor) > 25)
{
motor[motorC] = 50;
motor[motorB] = 50;

}

motor[motorC] = -50;
motor[motorB] = -50;
wait1Msec(2000);


}


Fri Mar 06, 2015 1:46 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 722
Post Re: Sensor Troubles
To confirm, which version of ROBOTC are you currently using? In your initial post, you listed ROBOTC 4.10; this was a beta build and there have been several bug and stability fixes between that version and the latest version, ROBOTC 4.30.

You can check which version of ROBOTC you have installed by navigating to the 'Help -> About ROBOTC' menu option (the version will appear in the bottom left corner of the window that appears), and you can update to the latest version by downloading the latest version directly from our downloads page. You may want to uninstall the 4.10 beta version of ROBOTC from your computer through the Add/Remove programs list as I do not think the new installer will automatically uninstall the beta build from your computer.

Please let me know if updating to the latest version resolves this issue, as the code appears to be correct.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our updated help documentation and the ROBOTC Forums.


Fri Mar 06, 2015 1:58 pm
Profile
Rookie

Joined: Fri Mar 06, 2015 8:58 am
Posts: 4
Post Re: Sensor Troubles
I tried updating it yesterday to no affect. However, I deleted and re-downloaded it again today based on your advice and it seems to have fixed my touch sensor issues (for now) :bigthumb:

Thank you sir!

However, the ultrasonic sensor is still behaving oddly even with the update. The first time I run the program, it works fine. Debugger shows everything normal, values between 0-255 and stops around 25 like it's supposed to. However, the second time I run the program, it immediately reads 25 and starts reversing; completely by passing the beginning part of the code.

I apologize if these questions are rudimentary.


Fri Mar 06, 2015 2:20 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.