Tracking service problem on Linux installation

I had buried this at the end of my replay on my other thread, so I'm expanding on it here and giving it it's own Subject.  One of the issues is no longer present in the latest build so that was fixed, but I still have the Tracking service crashing and am looking for the cause and a solution.

I am running MRL on Linux Mint 18.  This is on my notebook and that installation of Mint is using the OpenJDK and NOT Oracle's Java.

After I got MRLComm properly installed I was able to get the servo service to attach and run a servo attached to an Arduino Nano.  So that is working smoothly.

On to my first real test to try and get Tracking working with the InMoov head I am building.

I found a Video tutorial that appears to be good, but the script that was being used in that video was giving me errors.  Initially I thought that it was the second line in the script, but I then found that if I removed that line the error moved on down.  So looking closer at the log I find that there is an actual crash from the Runtime.createAndStart invokation of Tracking.  This also happens if I right click Tracking in the runtime list and start it from there.

There were several cases of the following in the log file:

[runtime] INFO c.m.i.FileIO [FileIO.java:979] looking for /resource/Arduino/MrlComm/MRLComm.ino
23:01:01.366 [runtime] ERROR c.m.i.FileIO [FileIO.java:994] can not find resource [/resource/Arduino/MrlComm/MRLComm.ino]

There was NO MrlComm directory in the installed MRL resource/Arduino tree, just MRLComm  So I tried creating a MrlComm directory and copying the contents from MRLComm but that didn't resolve that error.  So then looking at the path in the message I set up a /resource/Arduino/MrlComm directory tree with proper permissions and copied the content from MRLComm there.  But that didn't eliminate the error either.

Moving on...

Here's the crash point:

23:01:01.406 [runtime] INFO o.m.s.Tracking [Tracking.java:319] rest
23:01:01.407 [runtime] ERROR c.m.s.Arduino [Arduino.java:1244] getDeviceId could not find device tracking.x
23:01:01.407 [runtime] ERROR c.m.f.Service [Service.java:2131] runtime error createAndStart(tracking, org.myrobotlab.service.Tracking) error  <=== BBB Here's the crash point!!!
23:01:01.413 [runtime] ERROR c.m.l.Logging [Logging.java:19] ------
java.lang.NullPointerException
    at org.myrobotlab.service.Arduino.servoWrite(Arduino.java:2340)
    at org.myrobotlab.service.Servo.moveTo(Servo.java:367)
    at org.myrobotlab.service.Servo.rest(Servo.java:411)
    at org.myrobotlab.service.Tracking.rest(Tracking.java:320)
    at org.myrobotlab.service.Tracking.startService(Tracking.java:506)
    at org.myrobotlab.service.Runtime.createAndStart(Runtime.java:267)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.myrobotlab.framework.Service.invokeOn(Service.java:1315)
    at org.myrobotlab.framework.Service.invoke(Service.java:1253)
    at org.myrobotlab.framework.Service.run(Service.java:1676)
    at java.lang.Thread.run(Thread.java:745)

 

Note that the rest of "Tracking" continues to be set up including opencv and I can capture the eye webcam(s) and select points but of course I cannot attach to the servos to move the head since the actual Tracking service crashed.

So I just tried with the latest build:

With that I see that the MRLComm directory is now MrlComm and that MRLComm.ino is now MrlComm.ino and I no longer get the errors about cannot find MrlComm/MrlComm.ino so that has been fixed.

But I still get the crash when trying to start Tracking service, and as a bonus there is now a NULL pointer exception from logging when shutting down MRL.

Has anyone else seen this problem when running on Linux Mint 18?  Are you using OpenJDK on Linux or are you using Oracle Java?

Thanks,

Burt

burtbick's picture

OK, I have tried the Oracle

OK,

I have tried the Oracle V8 JRE and here is what I get with that:

09:27:29.113 [New I/O worker #8] INFO c.m.s.WebGui [WebGui.java:843] tracker.y.getMethodMap([])
09:27:29.130 [runtime] ERROR c.m.f.Instantiator [Instantiator.java:24] getNewInstance failed
java.lang.reflect.InvocationTargetException: null
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_121]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_121]
    at org.myrobotlab.framework.Instantiator.getThrowableNewInstance(Instantiator.java:56) [myrobotlab.jar:na]
    at org.myrobotlab.framework.Instantiator.getNewInstance(Instantiator.java:20) [myrobotlab.jar:na]
    at org.myrobotlab.framework.Instantiator.getNewInstance(Instantiator.java:34) [myrobotlab.jar:na]
    at org.myrobotlab.service.Runtime.createService(Runtime.java:369) [myrobotlab.jar:na]
    at org.myrobotlab.service.Runtime.create(Runtime.java:255) [myrobotlab.jar:na]
    at org.myrobotlab.service.Runtime.createAndStart(Runtime.java:268) [myrobotlab.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.myrobotlab.framework.Service.invokeOn(Service.java:1440) [myrobotlab.jar:na]
    at org.myrobotlab.framework.Service.invoke(Service.java:1378) [myrobotlab.jar:na]
    at org.myrobotlab.framework.Service.run(Service.java:1789) [myrobotlab.jar:na]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: java.lang.NullPointerException: null
    at org.myrobotlab.service.Arduino.attach(Arduino.java:1532) ~[myrobotlab.jar:na]
    at org.myrobotlab.service.Servo.attach(Servo.java:617) ~[myrobotlab.jar:na]
    at org.myrobotlab.service.Tracking.<init>(Tracking.java:186) ~[myrobotlab.jar:na]
    ... 18 common frames omitted
09:27:29.131 [runtime] ERROR c.m.f.Service [Service.java:2230] runtime error createAndStart(tracker, org.myrobotlab.service.Tracking) error
09:27:29.131 [runtime] ERROR c.m.l.Logging [Logging.java:19] ------
java.lang.NullPointerException
    at org.myrobotlab.service.Runtime.createAndStart(Runtime.java:269)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.myrobotlab.framework.Service.invokeOn(Service.java:1440)
    at org.myrobotlab.framework.Service.invoke(Service.java:1378)
    at org.myrobotlab.framework.Service.run(Service.java:1789)
    at java.lang.Thread.run(Thread.java:745)
------
 

So this doesn't appear to be related to the OpenJDK vs Oracle JDK/JRE.  Does anyone have any other suggestions on something I may be missing that is leading to this problem?  Is there something that needs to be activated that Tracking depends on that is causing the crash?

Thanks,

Burt

 

kwatters's picture

script problem, not environment related.

the error you are seeing is because either the servo or the arduino service isnt created prior to you starting tracking.

This is anissue with your script, not with your operating system.  You shouldsenda no worky... better yet, you should check in the  script that you are using.  That is where the issue lies.

burtbick's picture

Thanks,   I tried that

Thanks,

 

I tried that combination last night with the latest stable release (that is create the servos first) and it still crashed.  But I haven't tried it with the latest release.  So here we go:

 

OK, I created an x and y servo and for good measure a servo Servo service.  So I have x y and servo in the right box.

Note that I am NOT using a script for this test, just created the arduino service, then I created 3 servo services x, y and servo.

Then I created a Tracking service "Tracker" and kaboom, still crashes with the same exception.

Here's the script that I found on Alessandro Didonna's tutorial video.  The only changes I made for this test was the addition of the creating of the x and y servo objects and the comm port.  Note this is the original script without adding the creation of x and y servo objects.

tracker = Runtime.createAndStart("tracker", "Tracking")
tracker.setRestPosition(90, 90);
tracker.setSerialPort("/dev/ttyUSB0");
tracker.setXServoPin(3);
tracker.setYServoPin(4);
tracker.setCameraIndex(1);

tracker.initTracking();
tracker.initControl();
tracker.initInput();

tracker.trackLKPoint();
 

So it doesn't appear that the problem is due to not having the x and y servo objects created before starting Tracking.

Any other suggestions?

Burt

 

kwatters's picture

Sequence of what gets started matters.

Hi Burtbick,

  So, the tracking service is a little tempermental.  It needs to make sure that all of the servos and arduino is started before starting the tracking service, and those servos and arduinos need to have the proper names associated with them.. and the servos need to be attached to the arduino... then you can start the tracking.

Otherwise, you'll get a "null pointer exception" ..  This sort of exception happens when something is not created before you try to use it.  A little bit of a chicken & egg problem.

When in doubt, use the source luke!  Ok.. jokes aside.  Here's what I did to get it to work

https://github.com/MyRobotLab/myrobotlab/blob/develop/src/org/myrobotlab...

You'll notice this is the main function in java, where I have things relatively hard coded for my setup, but it will also work in python.  The syntax should be able to be mapped from java to python relatively easy.

I don't have a chance to test it, but I think the python equivilant of this would look something like the following:

# update this script with your pins / com port  & camera index.

 

xPin = 13;

yPin = 12;
arduinoPort = "COM12";
cameraIndex = 0;
 
# These all need to be created ahead of time o/w we get null pointer exceptions.
# create the servos that will control our x and our y tracking.
x = Runtime.createAndStart("tracker.x", "Servo");
y = Runtime.createAndStart("tracker.y", "Servo");
 
x.setPin(xPin);
x.setVelocity(-1);
y.setPin(yPin);
y.setVelocity(-1);
 
controller = Runtime.createAndStart("tracker.controller", "Arduino");
controller.connect(arduinoPort);
 
# now create the tracker service.
Tracking tracker = (Tracking)Runtime.createAndStart("tracker", "Tracking");
# uncomment if your camera is rotated 90 degrees
# tracker.addTransposeFilter();
 
tracker.connect(arduinoPort, xPin, yPin, cameraIndex);
tracker.startService();
tracker.startLKTracking();

 

 

Good luck!

 

burtbick's picture

Thanks, Here's what I wound

Thanks,

Here's what I wound up with for the script (so far):

xPin = 3;
yPin = 4;
 
arduinoPort = "/dev/ttyUSB0"; 
cameraIndex = 1;   # These all need to be created ahead of time o/w we get null pointer exceptions. 
 
# create the servos that will control our x and our y tracking. 
x = Runtime.createAndStart("tracker.x", "Servo"); 
y = Runtime.createAndStart("tracker.y", "Servo");   
x.setPin(xPin);
x.setVelocity(-1); 
y.setPin(yPin); 
y.setVelocity(-1);   
controller = Runtime.createAndStart("tracker.controller", "Arduino");
controller.connect(arduinoPort);   # now create the tracker service.
tracker = Runtime.createAndStart("tracker", "Tracking"); 
# uncomment if your camera is rotated 90 degrees 
# tracker.addTransposeFilter();   
tracker.connect(arduinoPort, xPin, yPin, cameraIndex); 
tracker.startService(); 
tracker.startLKTracking();
======= End of script
 
And no crashes so that was a big help.
 
I have a couple more questions on Tracking:
 
It sort of tracks, but winds up overshooting.  So I need to tweak some settings a bit, and since I only have pan ability right now I suspect that is part of the issue when I get home I'll be able to add the tilt to the head and I expect that it will be much better.
 
Thanks foer all your help!
Burt
kwatters's picture

PID value adjustments

If you're tracking is overshooting, you might need to tune the pid values for the x and y pid controls...

Default values here set here:

https://github.com/MyRobotLab/myrobotlab/blob/develop/src/org/myrobotlab...

If you want, you can get ahold of the pid service and update the values in python to some different values so the pid tracking works better.  This tuning depends on how fast the servos are, and how fast the camera is.

Sounds like it's a pretty good step forward,  I promise when the pid is tuned up, it does a good job of keeping the point that is being tracked in the center of the screen.

 

 

 

burtbick's picture

Thanks, I figured it was

Thanks,

I figured it was probably the PID values, and yes from what I've seen on YouTube it does a pretty darn good job of tracking.

I wound up having to travel for a few days and didn't have time to finish the head before hitting the road.  That is I have to finish hooking up the eye servos, and adding the "piston" for tilting the head.  That will help quite a bit too since the eyes can move a bit on their own when the head moves right now.

Still it is a great amount of forward progress.  It really helped to see what you had to do to get Tracking to work.

When I'm back in the shop I'll finish up things and should be able to do some significant testing.  I've been playing with tracking just in opencv without the Tracking service running just to get a feel for it and have had some good success with learning to tweak opencv settings.

Thanks again,

Burt