Sensor Monitor not working properly

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

Sensor Monitor not working properly

Postby Chiodo » Fri May 16, 2014 4:34 pm

Hello everyone!

I am new to Java and LeJOS, therefore my question could be seen as stupid, but please be patient ^^
I wrote a simple program to be uploaded on the NXT, and I would like to monitor the sensors during runtime through Bluetooth. Somewhere on the website I found that this piece of code that must be present somewhere for the Monitor utility included in the LeJOS package:

static LCPBTResponder lcpThread = new LCPBTResponder();
lcpThread.setDaemon(true);
lcpThread.start();

I did as advised, the program compiles and runs properly, but I can't read sensor values. Ultrasonic sensor stays at 1023 even if there's something in front of it, and touch sensor gives -1 even if pressed.
Am I missing something? :roll:
Chiodo
New User
 
Posts: 4
Joined: Fri May 16, 2014 4:24 pm

Re: Sensor Monitor not working properly

Postby gloomyandy » Fri May 16, 2014 4:55 pm

Hi, and welcome to leJOS.
Please when asking for help tell us as much as you can...
1. What version of leJOS.
2. What host system are you using (Mac/Windows etc.), what version.
3. Does the sensor monitor work if you run it with just the leJOS menu running?
4. What exactly is it you are doing...
* Start your program?
* run the sensor monitor? What command line if any?
* What happens? What did you expect to happen?
* Please make sure you explain the exact sequence you are using, so others can try and reproduce things.
5. What is your program doing other than running the monitor?
6. If possible post a small code sample that demonstrates the problem (I know you posted some code, but for all we know that code may never be getting executed). Please try and post a short complete program, something that others can simply try.
7. Make your test program as simple as possible. You may find that in the process of simplifying things you actually find the problem!



Note that in general the leJOS sensor classes are not thread safe, so reading the sensors from multiple concurrent threads may case odd results. This is what you will be doing if you use the monitor and are reading the same sensors in your own code.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4239
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Sensor Monitor not working properly

Postby Chiodo » Fri May 16, 2014 6:23 pm

You're totally right.
I'm using leJOS 0.9.1 under Windows 7.
The NXJ Monitor displays correctly tacho measures and battery level if nothing but the leJOS menu is running, but no sensor is detected.
My program just displays on the LCD the values for the distance sensor and the C motor tacho, while waiting for the user to rotate freely the motor or push buttons.

public class Robot_test {

static TouchSensor touch= new TouchSensor(SensorPort.S1);
static UltrasonicSensor sonic= new UltrasonicSensor(SensorPort.S2);
static LCPBTResponder lcpThread = new LCPBTResponder();

public static void main(String[] args) throws Exception {

lcpThread.setDaemon(true);
lcpThread.start();
Motor.C.resetTachoCount();
Motor.C.flt();
Motor.C.setSpeed(80);

while(!Button.ESCAPE.isDown()){

LCD.clearDisplay();
LCD.drawString("Rotation Monitor", 0, 0);
LCD.drawString("Angle: "+Motor.C.getTachoCount(), 0, 2);
LCD.drawString("Distance: "+sonic.getDistance(), 0, 4);
}}}}


What I get from the NXJ monitor (no command line) connecting via bluetooth during runtime is this:
Image
I expect those Sensor Scaled fields to report meaningful data; those fields however don't change, although the LCD strings give the correct readings.
I hope I made myself clear.
Chiodo
New User
 
Posts: 4
Joined: Fri May 16, 2014 4:24 pm

Re: Sensor Monitor not working properly

Postby gloomyandy » Fri May 16, 2014 6:41 pm

I'm not that familiar with the monitor code, but if it does not display anything useful with just the menu running then it will not display anything useful in your program as the responder code used is the same for both.

When your program is running do you get battery level and motor position reported (like you do with just the menu running)?

Also the tight loop you have displaying the sensor etc. readings means that if the monitor also accesses the sensors/motors etc. you now have multiple threads calling the same classes, which is at best going to be unpredictable and is likely to cause errors.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4239
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Sensor Monitor not working properly

Postby Chiodo » Fri May 16, 2014 7:21 pm

The picture above has been taken as a snapshot while running the program on the nxt.

Edit: I get the same results even if there is nothing else in the loop but a Thread.sleep.
Chiodo
New User
 
Posts: 4
Joined: Fri May 16, 2014 4:24 pm

Re: Sensor Monitor not working properly

Postby gloomyandy » Fri May 16, 2014 8:28 pm

I'm still confused as to what you get if you run the monitor program without your program running. As I said if that doesn't work then there is no way it will work in your own code. Looking at the code of the monitor I'm not convinced it will ever be able to work for i2c sensors like the Ultrasonic sensor. It probably should work for a touch sensor though. Perhaps Lawrie, will comment as I think this is his code.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4239
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Sensor Monitor not working properly

Postby Chiodo » Fri May 16, 2014 8:48 pm

When nothing's running but the main menu, the monitor displays correctly tachometer measures and battery level, although it displays "Not Connected" for the sensors.
When the program is running, the monitor displays tacho and battery level measures, and 1023 as a raw value for both sensors.

I'm sorry if I'm not getting myself understood, English is not my first language :oops:
Chiodo
New User
 
Posts: 4
Joined: Fri May 16, 2014 4:24 pm

Re: Sensor Monitor not working properly

Postby lawrie » Wed May 21, 2014 8:28 am

As Andy says, NXJMonitor does not work for i2c sensors link the ultrasonic sensor. It should work for the touch sensor and other analog sensors.
lawrie
leJOS Team Member
 
Posts: 934
Joined: Mon Feb 05, 2007 1:27 pm


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff