NXTCamV5 Support

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

Moderators: roger, gloomyandy, skoehler

User avatar
esmetaman
Advanced Member
Posts: 358
Joined: Wed Sep 13, 2006 12:16 am
Location: UK, Milton Keynes
Contact:

NXTCamV5 Support

Postby esmetaman » Sun Jul 30, 2017 3:56 pm

Hi Andy,

I am testing the new sensor NXTCam V5 using latest LeJOS version but I think that exist some problem with the connection with this Sensor:

Code: Select all

public class NXTCamTest1 {

    public static void main(String[] args){

        System.out.println("NXTCamV5 V5 Demo");

        final NXTCam camera = new NXTCam(SensorPort.S1);
       
    }
}


When I execute in the brick, i receive the following error:

Code: Select all

root@EV3:~# jrun -cp lejos-support-all-0.1.0.jar examples.NXTCamTest1
NXTCamV5 V5 Demo
Exception in thread "main" lejos.hardware.DeviceException: unable to open port
        at lejos.internal.ev3.EV3Port.open(EV3Port.java:75)
        at lejos.hardware.sensor.I2CSensor.<init>(I2CSensor.java:68)
        at lejos.hardware.device.NXTCam.<init>(NXTCam.java:58)
        at lejos.hardware.device.NXTCam.<init>(NXTCam.java:63)
        at examples.NXTCamTest1.main(NXTCamTest1.java:15)


Apparently, the wired connection is right, I tested with some different cables and the result is the same. In the version of this sensor, when you plug the sensor to the Brick, after few seconds, the sensor turn on a blue led blinking every 1 second and this is the same behaviour when the sensor is connected with the computer when you use NXTCamView. So, physically, the sensor is connected.

Reading the docs, the back compatibility exist but maybe the way that we connect for previous version is different now:
http://www.mindsensors.com/pdfs/NXTCam5-User-Guide.pdf

Note: I tested the jar with other examples included and the jar itself is not the source of the problem.

Code: Select all

root@EV3:~# jrun -cp lejos-support-all-0.1.0.jar examples.HelloWorld
Hello World
root@EV3:~#


Besides, I tested pointing the example to a wrong port, but the answer is the same:

Code: Select all

root@EV3:~# jrun -cp lejos-support-all-0.1.0.jar examples.NXTCamBadPortTest
NXTCamV5 V5 Demo
Exception in thread "main" lejos.hardware.DeviceException: unable to open port
        at lejos.internal.ev3.EV3Port.open(EV3Port.java:75)
        at lejos.hardware.sensor.I2CSensor.<init>(I2CSensor.java:68)
        at lejos.hardware.device.NXTCam.<init>(NXTCam.java:58)
        at lejos.hardware.device.NXTCam.<init>(NXTCam.java:63)
        at examples.NXTCamBadPortTest.main(NXTCamBadPortTest.java:15)


Any idea?

Source:
https://github.com/ev3dev-lang-java/lej ... ee/develop

Juan Antonio
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://ev3dev-lang-java.github.io/#/
https://github.com/jabrena/livingrobots

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: NXTCamV5 Support

Postby gloomyandy » Sun Jul 30, 2017 5:31 pm

That error usually means that the port is already open and so you can not open it. However it looks like you are not using the standard leJOS class library so who knows what is going on. What happens if you run this under the release version of leJOS? Have you tried restarting the EV3 and running the program again?
leJOS news https://lejosnews.wordpress.com/

User avatar
esmetaman
Advanced Member
Posts: 358
Joined: Wed Sep 13, 2006 12:16 am
Location: UK, Milton Keynes
Contact:

Re: NXTCamV5 Support

Postby esmetaman » Sun Jul 30, 2017 8:21 pm

Hi Andy,

Yes, when I restarted the brick, the example run. Now, I am learning the commands.

I think that it is necessary to create a new Class in the project. NXTCam.java is oriented to previous versions but the new version of the sensor has differents commands and NXTCamV5 has a different way to operate. I am learning about it.

Take a look the documentation:
NXTCam v5: http://www.mindsensors.com/pdfs/NXTCam5-User-Guide.pdf
NXTCam v4: http://www.mindsensors.com/index.php?co ... tachment=1

Next week, I will try to run the new features.

Cheers

Juan Antonio
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://ev3dev-lang-java.github.io/#/
https://github.com/jabrena/livingrobots

User avatar
esmetaman
Advanced Member
Posts: 358
Joined: Wed Sep 13, 2006 12:16 am
Location: UK, Milton Keynes
Contact:

Re: NXTCamV5 Support

Postby esmetaman » Mon Jul 31, 2017 6:22 pm

Hi Andy,

the new sensor run nice on LeJOS.
I am trying to port an old example from NXT.

for EV3, how to disable the menu when you execute a jar with jrun in order to not have problems with the LCD?

Juan Antonio
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://ev3dev-lang-java.github.io/#/
https://github.com/jabrena/livingrobots

User avatar
gloomyandy
leJOS Team Member
Posts: 5899
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: NXTCamV5 Support

Postby gloomyandy » Mon Jul 31, 2017 7:02 pm

There is a command in the "System" part of the menu called "suspend menu" which will do that. Or you can just kill the Java process running the menu.
leJOS news https://lejosnews.wordpress.com/

User avatar
esmetaman
Advanced Member
Posts: 358
Joined: Wed Sep 13, 2006 12:16 am
Location: UK, Milton Keynes
Contact:

Re: NXTCamV5 Support

Postby esmetaman » Tue Aug 01, 2017 6:11 pm

Hi Andy,

Many thanks for advice.

I have finished the Driver for NXTCam v5:

Code: Select all

package lejos.hardware.device;

import lejos.hardware.port.I2CPort;
import lejos.hardware.port.Port;
import lejos.hardware.sensor.I2CSensor;
import lejos.robotics.geometry.Rectangle2D;
import lejos.robotics.geometry.RectangleInt32;

/**
 * Mindsensors NXTCamV5.
 * www.mindsensors.com
 *
 * @author Juan Antonio Breña Moral
 *
 */
public class NXTCamV5 extends I2CSensor {

   byte[] buf = new byte[4];

   //MODES

   /**
    * Used by setTrackingMode() to choose object tracking.
    */
   public static final char OBJECT_TRACKING = 'B';

   /**
    * Used by setTrackingMode() to choose face tracking.
    */
   public static final char FACE_TRACKING = 'F';

   /**
    * Used by setTrackingMode() to choose eye tracking.
    */
   public static final char EYE_TRACKING = 'e';

   /**
    * Used by setTrackingMode() to choose line tracking.
    */
   public static final char LINE_TRACKING = 'L';

   //CAPABILITIES

   /**
    * Used to record a short video
    */
   public static final char TAKE_VIDEO = 'M';

   /**
    * Used to take a snapshot
    */
   public static final char TAKE_PHOTO = 'P';

   public NXTCamV5(I2CPort port, int address)
   {
      super(port, address);
   }

   public NXTCamV5(I2CPort port)
   {
      this(port, DEFAULT_I2C_ADDRESS);
   }

    public NXTCamV5(Port port, int address)
    {
        super(port, address, TYPE_LOWSPEED_9V);
    }
   
    public NXTCamV5(Port port)
    {
        this(port, DEFAULT_I2C_ADDRESS);
    }

   /**
    * Get the number of objects being tracked
    *
    * @return number of objects (0 - 8)
    */
   public int getNumberOfObjects() {
      getData(0x42, buf, 1);
      return (0xFF & buf[0]);
   }
   
   /**
    * Choose either object or line tracking mode.
    * @param mode Use either OBJECT_TRACKING or LINE_TRACKING
    */
   public void setTrackingMode(char mode) {
      sendCommand(mode);
   }
   
   /**
    * Get the color number for a tracked object
    *
    * @param id the object number (starting at zero)
    * @return the color of the object (starting at zero)
    */
   public int getObjectColor(int id) {
      getData(0x43 + (id * 5), buf, 1);
      return (0xFF & buf[0]);
   }

   /**
    * Get the rectangle containing a tracked object
    *
    * @param id the object number (starting at zero)
    * @return the rectangle
    */
   public Rectangle2D getRectangle(int id) {
      for(int i=0;i<4;i++) buf[i] = 0;
      getData(0x44 + (id * 5), buf, 4);
      return new RectangleInt32(buf[0] & 0xFF, buf[1] & 0xFF,
            (buf[2] & 0xFF) - (buf[0] & 0xFF),
            (buf[3] & 0xFF) - (buf[1] & 0xFF));
   }
   
   /**
    * Send a single byte command represented by a letter
    * @param cmd the letter that identifies the command
    */
   public void sendCommand(char cmd) {
      sendData(0x41, (byte) cmd);
   }

   /**
    * Create a new video
    */
   public void createVideo(){
      sendCommand(TAKE_VIDEO);
   }

   /**
    * Create a photo
    */
   public void createPhoto(){
      sendCommand(TAKE_PHOTO);
   }
}


I have created several examples about the main features here:
https://github.com/ev3dev-lang-java/lej ... s/nxtcamv5

- Track Objects
- Process Rectangles
- Face Recognition without OpenCV
- Create a Video
- Create a Photo

if you like, Review the class and if the Code Review is Ok, I could commit on Git repo.

Juan Antonio
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://ev3dev-lang-java.github.io/#/
https://github.com/jabrena/livingrobots

User avatar
esmetaman
Advanced Member
Posts: 358
Joined: Wed Sep 13, 2006 12:16 am
Location: UK, Milton Keynes
Contact:

Re: NXTCamV5 Support

Postby esmetaman » Tue Aug 01, 2017 6:13 pm

Now for example, it is not necessary to sort the objects, the Sensor return the objects sorted:

Code: Select all

W: 13.0 H: 2.0 X: 80.0 Y: 52.0
W: 10.0 H: 2.0 X: 73.0 Y: 70.0
W: 9.0 H: 2.0 X: 124.0 Y: 67.0
Iteration: 22
6
W: 10.0 H: 2.0 X: 77.0 Y: 56.0
W: 9.0 H: 2.0 X: 74.0 Y: 72.0
W: 10.0 H: 2.0 X: 85.0 Y: 56.0
W: 9.0 H: 2.0 X: 98.0 Y: 102.0
W: 7.0 H: 2.0 X: 94.0 Y: 102.0
W: 5.0 H: 2.0 X: 138.0 Y: 68.0
Iteration: 23
Juan Antonio Breña Moral
http://www.juanantonio.info/lejos-ebook/
http://ev3dev-lang-java.github.io/#/
https://github.com/jabrena/livingrobots


Return to “EV3 Software”

Who is online

Users browsing this forum: No registered users and 1 guest