View unanswered posts | View active topics It is currently Sat Nov 25, 2017 12:01 am






Reply to topic  [ 10 posts ] 
NXTCam V4 - Always read same blobs 
Author Message
Rookie

Joined: Thu Jan 15, 2015 10:57 am
Posts: 9
Location: Italy
Post NXTCam V4 - Always read same blobs
Hi everybody,
I have a problem with my NXTCam V4 and my EV3... (ROBOTC 4.29 + Xanders Drivers)
After testing drivers examples I wrote this simple program but while running my NXTCam seems to read always the same blobs... (same size, same x1, x2 ecc...)
In other words the dynamic array _blobs seems not to change after NXTCAMgetBlobs calling...

I tryed using global array definition, local array definition, passing array as parameter (as pointer), but the problem persists!

Any ideas???

Here's my code

Code:
#pragma config(Sensor, S4,     cam,            sensorEV3_GenericI2C)
#pragma config(Motor,  motorA,          MOTOR_SX,      tmotorEV3_Large, PIDControl, reversed, driveRight, encoder)
#pragma config(Motor,  motorB,          MOTOR_DX,      tmotorEV3_Large, PIDControl, reversed, driveLeft, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "mindsensors-nxtcam.h"
#define MyColorMap 0


// ################################################
// Routines
// ################################################

void SearchObject()
{
   bool _found = false;
   float _l, _r, i;
   float error = 0;
   _l = 0; _r = 0;

   blob_array _blobs;
   int _nblobs = 0;

   while(!_found)
   {
      _nblobs = NXTCAMgetBlobs(cam, _blobs, true);
      writeDebugStreamLine("get %d blobs", _nblobs);

      i = 0;
      while ((i < _nblobs) && (!_found))
      {
         _l = (_blobs[i].x1);
         _r = (_blobs[i].x2);
         _found = ( _blobs[i].colour == MyColorMap );
         writeDebugStreamLine("BLOB idx %d ", i);
         writeDebugStreamLine("BLOB COLOR %d ", _blobs[i].colour);
         writeDebugStreamLine("BLOB SIZE %d ", _blobs[i].size);
         writeDebugStreamLine("BLOB COLOR %d ", MyColorMap);
         i++;
      }

      error = (SIDE_CENTER (_l, _r) - 88);

      if (!_found) {
        //========================
         //NO Objects found !!!
         //========================
         
         setMotorSpeed(MOTOR_DX, -5);
         setMotorSpeed(MOTOR_SX, 5);
         wait1Msec(50);
      }
      else {
         //========================
         //Some Objects found !!!
         //========================
         
         if  ((error >= -30) && (error <= 30)) {
            setMotorSpeed(MOTOR_DX, 0);
            setMotorSpeed(MOTOR_SX, 0);
         }
         else {
            if (error > 30) {
               setMotorSpeed(MOTOR_DX, -5);
               setMotorSpeed(MOTOR_SX, 5);
            }
            else {
               setMotorSpeed(MOTOR_DX, 5);
               setMotorSpeed(MOTOR_SX, -5);
            }
            wait1Msec(50);
         }
      }
   }
}


/*
=========================================================
TCam
-------------
this task do preventive positioning by reading sensors
and moving motors and then call SearchObject
to activate NXTCam
========================================================
*/

task TCam()
{
   while (true)
   {
   // do something
   // ....
   SearchObject();
   //....
   // do something else
   //....
   }
}


/*
=========================================================
TMain
-------------
Display  System informations
========================================================
*/

task main()
{
   NXTCAMinit(cam); sleep(500);
   
   startTask(TCam);
   
   while (true)
   {
   eraseDisplay();
   displayCenteredBigTextLine(1, "SysTime: %d" , nSysTime);
   displayCenteredBigTextLine(3, "PgmTime: %d" , nPgmTime);
   displayCenteredBigTextLine(5, "Firmware Version: %d", version);
   wait1Msec(100);
   }
}

_________________
for my blog I use the best hosting wordpress


Thu Feb 26, 2015 6:30 pm
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: NXTCam V4 - Always read same blobs
Hey Giuseppe,

I don't own a V4, but I do have a V3. I'll add this to my todo list of things to check and possibly fix :) I'll keep you posted.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Feb 27, 2015 1:22 am
Profile WWW
Rookie

Joined: Thu Jan 15, 2015 10:57 am
Posts: 9
Location: Italy
Post Re: NXTCam V4 - Always read same blobs
add informations...
looking my debug stream, often NXTCAMgetBlobs returns -1 and NXTCam led continue blonking also after stopalltask

Code:
#pragma config(Sensor, S4,     cam,            sensorEV3_GenericI2C)
#pragma config(Motor,  motorA,          MOTOR_SX,      tmotorEV3_Large, PIDControl, reversed, driveRight, encoder)
#pragma config(Motor,  motorB,          MOTOR_DX,      tmotorEV3_Large, PIDControl, reversed, driveLeft, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "mindsensors-nxtcam.h"
#define MyColorMap 0


blob_array _blobs;
int _nblobs = 0;
float size = 0;
float error = 0;
bool _found = false;

/*
====================
TStopButton
====================
*/

task TStopButton()
{
   setBlockBackButton(true);
   while(true)
   {
      if (getButtonPress(buttonBack))stopAllTasks();
      wait1Msec(100);
   }
}

/*
====================
TCam
====================
*/

task TCam()
{
   float _l, _r, i;
   _l = 0; _r = 0; i = 0;
   memset(_blobs, 0, sizeof(blob_array));

   while (true)
   {
      _nblobs = NXTCAMgetBlobs(cam, _blobs, true);
      i = 0;
      while ((i < _nblobs) && (!_found))
      {
         _l = (_blobs[i].x1);
         _r = (_blobs[i].x2);
         size = _blobs[i].size;
         _found = ( _blobs[i].colour == MyColorMap );
         writeDebugStreamLine("BLOB idx %d ", i);
         writeDebugStreamLine("BLOB COLOR %d ", _blobs[i].colour);
         writeDebugStreamLine("BLOB SIZE %d ", size);
         i++;
      }

      error = (SIDE_CENTER (_l, _r) - 88);

      if (!_found) {
         //========================
         //NO Objects found !!!
         //========================

         setMotorSpeed(MOTOR_DX, -5);
         setMotorSpeed(MOTOR_SX, 5);
         wait1Msec(50);
      }
      else {
         //========================
         //Some Objects found !!!
         //========================

         if  ((error >= -30) && (error <= 30)) {
            setMotorSpeed(MOTOR_DX, 0);
            setMotorSpeed(MOTOR_SX, 0);
         }
         else {
            if (error > 30) {
               setMotorSpeed(MOTOR_DX, -5);
               setMotorSpeed(MOTOR_SX, 5);
            }
            else {
               setMotorSpeed(MOTOR_DX, 5);
               setMotorSpeed(MOTOR_SX, -5);
            }
         }   
         wait1Msec(50);
      }
   }
}

/*
=========================================================
TMain
-------------
Display  System informations
========================================================
*/

task main()
{

   NXTCAMinit(cam); sleep(500);

   startTask(TStopButton);
   startTask(TCam);

   while (true)
   {
      eraseDisplay();
      displayCenteredBigTextLine(1, "Error: %d" , error);
      displayCenteredBigTextLine(3, "Size: %d" , size);
      displayCenteredBigTextLine(5, "tot %d blobs", _nblobs);
      wait1Msec(100);
   }
}

_________________
for my blog I use the best hosting wordpress


Fri Feb 27, 2015 7:55 am
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: NXTCam V4 - Always read same blobs
I am afraid I cannot reproduce your issue with my NXTCam V3. I've attached a picture so you can see it working. Did you try it with mindsensors-nxtcam-test1.c, which is shipped with the driver suite?
Attachment:
2015-03-01 17.57.35.jpg
2015-03-01 17.57.35.jpg [ 1.06 MiB | Viewed 3895 times ]

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Mar 01, 2015 1:00 pm
Profile WWW
Rookie

Joined: Thu Jan 15, 2015 10:57 am
Posts: 9
Location: Italy
Post Re: NXTCam V4 - Always read same blobs
yes, I tried it and it works fine, but I need to integrate it in a more complex program.
I created a function to call when I need to detect an object and when call that function the array returned by NXTCAMgetBlobs seems not to be changed...
I think it could depend on RobotC's inability to pass an array through functions

---

by the way, according to NXTCam-v4-UserGuide.pdf, the difference between V3 and V4 is the tracking buffer lock function to use before reading cam registers.
"J" command is used to lock tracking buffer (after this command allow 25ms for any update in progress)
"K" command is used to unlock tracking buffer

_________________
for my blog I use the best hosting wordpress


Mon Mar 02, 2015 8:35 am
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: NXTCam V4 - Always read same blobs
That might explain some of the issues you're seeing.
Try putting this in your code:
Code:
_camera_cmd(cam, 'J', NXTCAM_I2C_ADDR);  // lock buffer
sleep(25)
_nblobs = NXTCAMgetBlobs(cam, _blobs, true);
_camera_cmd(cam, 'K', NXTCAM_I2C_ADDR); // unlock buffer

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Mar 02, 2015 8:45 am
Profile WWW
Rookie

Joined: Thu Jan 15, 2015 10:57 am
Posts: 9
Location: Italy
Post Re: NXTCam V4 - Always read same blobs
same problem...
I also modified your NXTCAMgetBlobs function, inserting writeDebugStreamLine to check array values changes

Code:
short NXTCAMgetBlobs(tSensors link, blob_array &blobs, ubyte address) {
  short _nblobs = 0;

  // clear the array used for the blobs
  memset(blobs, 0, sizeof(blob_array));

  // Request number of blobs from the count register
  NXTCAM_I2CRequest[0] = 2;                 // Message size
  NXTCAM_I2CRequest[1] = address;           // I2C Address
  NXTCAM_I2CRequest[2] = NXTCAM_COUNT_REG;  // Register used to hold number of blobs detected

  if (!writeI2C(link, NXTCAM_I2CRequest, NXTCAM_I2CReply, 1))
    return -1;

  _nblobs = NXTCAM_I2CReply[0];
  if (_nblobs > MAX_BLOBS) {
    return -1;
  }

  // Get nblobs of blob data from the camera
  for (short _i = 0; _i < _nblobs; _i++) {

    // Request blob data
    NXTCAM_I2CRequest[0] = 2;                         // Message size
    NXTCAM_I2CRequest[1] = address;           // I2C Address
    NXTCAM_I2CRequest[2] = NXTCAM_DATA_REG + _i * 5;  // Register containing data pertaining to blob

    if (!writeI2C(link, NXTCAM_I2CRequest, NXTCAM_I2CReply, 5))
      return -1;

    // Put the I2C data into the blob
    blobs[_i].colour    = (short)NXTCAM_I2CReply[0];
    blobs[_i].x1        = (short)NXTCAM_I2CReply[1];
    blobs[_i].y1        = (short)NXTCAM_I2CReply[2];
    blobs[_i].x2        = (short)NXTCAM_I2CReply[3];
    blobs[_i].y2        = (short)NXTCAM_I2CReply[4];
    blobs[_i].size      = abs(blobs[_i].x2 - blobs[_i].x1) * abs(blobs[_i].y2 - blobs[_i].y1);
    writeDebugStreamLine("DRV (%d): blob[%d].size: %d ", nPgmTime,_i , blobs[_i].size);
  }
  writeDebugStreamLine("DRV (%d): _nblobs: %d ", nPgmTime, _nblobs);
  return _nblobs;
}


and calling this function from various parts in my program it seems the array doesn't change...
I tried declaring locally or globally "blob_array _blobs;" without results.

The only different thing from you examples is that I call NXTCAMgetBlobs inside a function called in a task.

Code:
DRV (866031): blob[0].size: 5920
DRV (866046): blob[1].size: 396
DRV (866046): _nblobs: 2
DRV (869601): blob[0].size: 5920
DRV (869618): blob[1].size: 396
DRV (869618): _nblobs: 2

_________________
for my blog I use the best hosting wordpress


Tue Mar 03, 2015 6:22 am
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: NXTCam V4 - Always read same blobs
Do my sample programs work for you at all? (provided you add those commands, of course)

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Mar 03, 2015 6:39 am
Profile WWW
Rookie

Joined: Thu Jan 15, 2015 10:57 am
Posts: 9
Location: Italy
Post Re: NXTCam V4 - Always read same blobs
yes, changing sensor type to sensorEV3_GenericI2C

Code:
DRV (233194): blob[0].size: 551
DRV (233208): blob[1].size: 310
DRV (233208): _nblobs: 2
DRV (233332): blob[0].size: 276
DRV (233348): blob[1].size: 266
DRV (233348): _nblobs: 2
DRV (233472): blob[0].size: 322
DRV (233485): blob[1].size: 266
DRV (233485): _nblobs: 2
DRV (233610): blob[0].size: 372
DRV (233624): blob[1].size: 285
DRV (233624): _nblobs: 2
DRV (233748): blob[0].size: 665
DRV (233762): blob[1].size: 372
DRV (233776): blob[2].size: 253
DRV (233776): _nblobs: 3

I think the problem is to search in passing array variable through functions... With blob array as global variable and calling a function that calls NXTCAMgetBlobs passing this array, for some reason after first elaboration it values inside it freeze

_________________
for my blog I use the best hosting wordpress


Tue Mar 03, 2015 8:15 am
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: NXTCam V4 - Always read same blobs
I'll take a look at the array issue, but for now use a local variable and copy it out to a global variable with memcpy() or something.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Mar 03, 2015 9:10 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 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.