View unanswered posts | View active topics It is currently Wed Sep 03, 2014 4:06 am






Reply to topic  [ 9 posts ] 
NXTCAMgetAverageCenter 
Author Message
Novice

Joined: Sun Feb 24, 2008 6:15 pm
Posts: 50
Post NXTCAMgetAverageCenter
Hi,

What is the max X and Y value for the NXTCAMgetAverageCenter function? i got X = 248 is a normal value?

Thanks

_________________
My Eurobot team website :
http://blog.mlrobotic.com/


My MOCs :
http://nxtgen.6mablog.com


Mon Jun 20, 2011 3:49 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3211
Location: Rotterdam, The Netherlands
Post Re: NXTCAMgetAverageCenter
No, that doesn't seem very normal. Can I see your entire program?

- 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 Jun 20, 2011 4:10 pm
Profile WWW
Novice

Joined: Sun Feb 24, 2008 6:15 pm
Posts: 50
Post Re: NXTCAMgetAverageCenter
yes sure :

Code:

int contactPressed;
int distLeft;
int distRight;
int dirToSeek;
tSensors touch;
tSensors cam;
tSensors usLeft;
tSensors usRight;
blob_array _blobs, _blobs_temp;
int nbBlobs;

void initSensors(tSensors _cam,tSensors _touch,tSensors _left,tSensors _right)
{
 touch = _touch;
 cam = _cam;
 usLeft = _left;
 usRight = _right;
 USreset(usLeft);
 USreset(usRight);
// USsetSingleMode(usLeft);
 //USsetSingleMode(usRight);
 NXTCAMinit(_cam);

}

task readSensors()
{
  USsetOff(usLeft);
  USsetOff(usRight);


  memset(_blobs, 0, sizeof(blob_array));
  memset(_blobs_temp, 0, sizeof(blob_array));

  while(1)
  {
    contactPressed = SensorValue[touch];

    USsetSingleMode(LeftUS);
    distLeft = USreadDist(LeftUS);
    wait1Msec(50);
    USsetOff(LeftUS);

    USsetSingleMode(RightUS);
    distRight = USreadDist(RightUS);
    wait1Msec(50);
    USsetOff(RightUS);

    nbBlobs = NXTCAMgetBlobs(cam, _blobs, true);//retourne le nombre de blob trouve
    _blobs = _blobs_temp;

  }
}

task main()
{
  initSensors(NXTcam, BallContact, LeftUS, RightUS);
  StartTask(readSensors);

  int _x, _y;
  motor[LeftMotor] = 0;
  motor[RightMotor] = 0;
  while(1)
  {
    if(nbBlobs <= 0)
    {
 
      motor[LeftMotor] = 0;
      motor[RightMotor] = 0;
    }
    else
    {
          writeDebugStreamLine("Blob : %d",nbBlobs);
        if(nbBlobs !=0 )
        {
           NXTCAMgetAverageCenter(_blobs, nbBlobs,0, _x, _y);
           writeDebugStreamLine("x:%d; y:%d",_x,_y);
          
           if(_x != 0 && _y!= 0)
           {
              if(_x > ((88) +5))
              {
                motor[LeftMotor] =  - (_x - 88)/5;
                motor[RightMotor] = (_x-88)/5;
                writeDebugStreamLine("On my Right!!!");
              }
              else if(_x <((88) - 5))
              {
                motor[LeftMotor] = (88 - _x)/5;
                motor[RightMotor] = -(88 - _x)/5;
                          writeDebugStreamLine("On my Left!!!");

              }else
              {
                motor[LeftMotor] = 0;
                motor[RightMotor] = 0;
              }
           }
        }

    }
    EndTimeSlice();
    wait1Msec(100);
  }

}


sometimes this kind of value appears.

_________________
My Eurobot team website :
http://blog.mlrobotic.com/


My MOCs :
http://nxtgen.6mablog.com


Mon Jun 20, 2011 4:52 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3211
Location: Rotterdam, The Netherlands
Post Re: NXTCAMgetAverageCenter
I'll take a look in the morning, it's a bit late now :)

- 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 Jun 20, 2011 5:20 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3211
Location: Rotterdam, The Netherlands
Post Re: NXTCAMgetAverageCenter
Your program is not complete. Where are the sensor configuration pragmas?

- 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 Jun 21, 2011 3:41 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3211
Location: Rotterdam, The Netherlands
Post Re: NXTCAMgetAverageCenter
I modified your program to make it more readable. You should use consistent sensor naming. ALWAYS use the Motor and Sensor configuration UI. Consider getting rid of the sensor reading task, it serves no real purpose.

Code:
#pragma config(Sensor, S1,     NXTCAM,              sensorI2CCustomFastSkipStates9V)
#pragma config(Sensor, S2,     TOUCH,               sensorTouch)
#pragma config(Sensor, S3,     USRIGHT,             sensorI2CCustom9V)
#pragma config(Sensor, S4,     USLEFT,              sensorI2CCustom9V)
#pragma config(Motor,  motorA,          MRIGHT,        tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          MLEFT,         tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "drivers/LEGOUS-driver.h"
#include "drivers/NXTCam-driver.h"

int contactPressed;
int distLeft;
int distRight;
int dirToSeek;
blob_array _blobs, _blobs_temp;
int nbBlobs;


task readSensors()
{
  USsetOff(USLEFT);
  USsetOff(USRIGHT);


  memset(_blobs, 0, sizeof(blob_array));
  memset(_blobs_temp, 0, sizeof(blob_array));

  while(1)
  {
/*
    contactPressed = SensorValue[TOUCH];

    USsetSingleMode(USRIGHT);
    distLeft = USreadDist(USLEFT);
    wait1Msec(50);
    USsetOff(USLEFT);

    USsetSingleMode(USRIGHT);
    distRight = USreadDist(USRIGHT);
    wait1Msec(50);
    USsetOff(USRIGHT);
*/
    nbBlobs = NXTCAMgetBlobs(NXTCAM, _blobs, true);   //retourne le nombre de blob trouve

    // This part should not be interrupted.
    hogCPU();
    memcpy(_blobs, _blobs_temp, sizeof(_blobs_temp);
    releaseCPU();
  }
}

task main()
{
  // Initialise the sensors.
  USreset(USLEFT);
  USreset(USRIGHT);
  // USsetSingleMode(USLEFT);
  //USsetSingleMode(USRIGHT);
  NXTCAMinit(NXTCAM);
 
  StartTask(readSensors);
 
  int _x, _y;
  motor[MLEFT] = 0;
  motor[MRIGHT] = 0;
  while(1)
  {
    if(nbBlobs <= 0)
    {
      motor[MLEFT] = 0;
      motor[MRIGHT] = 0;
    }
    else
    {
      writeDebugStreamLine("Blob : %d",nbBlobs);
      if(nbBlobs !=0 )
      {
        NXTCAMgetAverageCenter(_blobs, nbBlobs,0, _x, _y);
        writeDebugStreamLine("x:%d; y:%d",_x,_y);
       
        if(_x != 0 && _y!= 0)
        {
          if(_x > ((88) +5))
          {
            motor[MLEFT] =  - (_x - 88)/5;
            motor[MRIGHT] = (_x-88)/5;
            writeDebugStreamLine("On my MRIGHT!!!");
          }
          else if(_x <((88) - 5))
          {
            motor[MLEFT] = (88 - _x)/5;
            motor[MRIGHT] = -(88 - _x)/5;
            writeDebugStreamLine("On my MLEFT!!!");
          }
          else
          {
            motor[MLEFT] = 0;
            motor[MRIGHT] = 0;
          }
        }
      }
    }
    wait1Msec(100);
  }
}


- 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 Jun 21, 2011 4:07 am
Profile WWW
Novice

Joined: Sun Feb 24, 2008 6:15 pm
Posts: 50
Post Re: NXTCAMgetAverageCenter
sorry the copy paste is not complete :) i will post the complement later

_________________
My Eurobot team website :
http://blog.mlrobotic.com/


My MOCs :
http://nxtgen.6mablog.com


Tue Jun 21, 2011 4:08 am
Profile WWW
Novice

Joined: Sun Feb 24, 2008 6:15 pm
Posts: 50
Post Re: NXTCAMgetAverageCenter
thanks for your answer, i'm using non consistent sensor naming because my sensor task reading was in a different file . You think it's because i'm not using consistent naming that i find some errors? or because i don't hog the CPU?

_________________
My Eurobot team website :
http://blog.mlrobotic.com/


My MOCs :
http://nxtgen.6mablog.com


Tue Jun 21, 2011 4:14 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3211
Location: Rotterdam, The Netherlands
Post Re: NXTCAMgetAverageCenter
You were not copying the array from one to the other, merely assigning another variable to the same block of memory. That is why I am doing a proper memcpy() call. To make sure that it isn't being read while the copying is happening, I block the CPU.

- 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 Jun 21, 2011 4:35 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.