View unanswered posts | View active topics It is currently Sat Oct 25, 2014 8:08 am






Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
help to set a tracking ball with NXTCam please!!! 
Author Message
Rookie

Joined: Sat Mar 30, 2013 2:42 pm
Posts: 9
Post help to set a tracking ball with NXTCam please!!!
morning every body. after studied the robotc now I am using xander work to finish my project. I want my robot follow only one color so I use the merge of blob
now I modify his mindsensor-nxtcam-test1.c programme to display the difference between the center of blob and the center of camera but the programme dont work. you can see the programme under these lines. Iwant to notify this programme compile very fine no error but it not running
I need your help to continous my project tuesday at school
thank's for your help and excuse me for my fake english.


#pragma config(Sensor, S1, cam, sensorI2CCustomFastSkipStates)

#include "mindsensors-nxtcam.h"

task main () {
blob_array _blobs;
memset(_blobs, 0, sizeof(_blobs)); // initialise the blobs
// combine all colliding blobs into one
bool _condensed = true;

//blob_array _blobs;
int _l, _t, _r, _b;
int _nblobs=0;
float x_center=0; // to get the center
float error=0; // to get the error
_l=0; _t=0; _r=0; _b=0;
eraseDisplay();

// Initialise the camera
NXTCAMinit(cam);
while(true) {
eraseDisplay();
// Fetch all the blobs, have the driver combine all
// the colliding blobs.

_nblobs = NXTCAMgetBlobs(cam, _blobs, _condensed);
for (int i = 0; i < _nblobs; i++) {
_l = (_blobs[i].x1);
_t = (_blobs[i].y1);
_r = (_blobs[i].x2);
_b = (_blobs[i].y2);

}
x_center = SIDE_CENTER (_l,_r); //get the center of blobs
error= x_center - 88; // get difference between center of blobs and camera

nxtDisplayTextLine(3, "the error is %f", error );

}
}


Sat Mar 30, 2013 3:36 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: help to set a tracking ball with NXTCam please!!!
This question was also asked on my blog and has been answered. I will paste it below.

Please only ask your question in one single thread. I have removed the other post.

Quote:
Hey Alain,

I’ve modified your program to look only at the first blob that it sees and to give a warning if no blob has been detected. Basically, only the first blob is interesting due to the fact that it’s the biggest one (they’re sorted according to size).

Hopefully this will work for you.


Code:
#pragma config(Sensor, S1,     cam,                 sensorI2CCustomFastSkipStates)

#include "mindsensors-nxtcam.h"

task main () {
  blob_array _blobs;
  memset(_blobs, 0, sizeof(_blobs)); // initialise the blobs
  // combine all colliding blobs into one
  bool _condensed = true;

  //blob_array _blobs;
  int _l, _t, _r, _b;
  int _nblobs=0;
  float x_center=0; // to get the center
  float error=0; // to get the error
  _l=0; _t=0; _r=0; _b=0;
  eraseDisplay();

  // Initialise the camera
  NXTCAMinit(cam);
  while(true) {
    eraseDisplay();
    // Fetch all the blobs, have the driver combine all
    // the colliding blobs.
    _nblobs = NXTCAMgetBlobs(cam, _blobs, _condensed);

    // we only care about the first blob, this is the biggest one and most likely the one we're
    // interested in
    if (_nblobs > 0)
    {
      _l = (_blobs[0].x1);
      _t = (_blobs[0].y1);
      _r = (_blobs[0].x2);
      _b = (_blobs[0].y2);
      x_center = SIDE_CENTER (_l,_r); //get the center of blobs
      error= x_center - 88; // get difference between center of blobs and camera

      nxtDisplayTextLine(3, "the error is %f", error );
    }
    else
    {
      // do whatever you do when nothing is detected
      writeDebugStreamLine("nothing detected");
    }
  }
}

_________________
| 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 31, 2013 3:23 pm
Profile WWW
Rookie

Joined: Sat Mar 30, 2013 2:42 pm
Posts: 9
Post Re: help to set a tracking ball with NXTCam please!!!
ok thank's for your help and advice the next time I will only post here to have a good visibility more large.


Mon Apr 01, 2013 7:35 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: help to set a tracking ball with NXTCam please!!!
No problem and that sounds like a good idea :) Maybe this will help someone else at some point in the future.

= 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 Apr 01, 2013 8:00 am
Profile WWW
Rookie

Joined: Sat Mar 30, 2013 2:42 pm
Posts: 9
Post Re: help to set a tracking ball with NXTCam please!!!
Good morning every body Now Mr Xander help me to advance in my project I can already see my object and take the difference between the object and the center of my camera. The next stage is to take this difference and turn the robot until the two centers are egal. but I don't have idea to start because evidry thing I do was not walk.
here you can see my main goal, some thing like that :?

http://www.education.rec.ri.cmu.edu/pro ... XTCam.html

please I need your help and if you have one code of that please I need it.
I show you where I am in this code below


Attachments:
public one.c [1.27 KiB]
Downloaded 248 times
Tue Apr 02, 2013 3:13 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: help to set a tracking ball with NXTCam please!!!
Your camera is working and tracking things when you use it through the NXTCamView program, is it? You can download that here: http://nxtcamview.sourceforge.net/
You need to make sure it's setup correctly through that with the correct colour map. Your ROBOTC program will not work unless you make this part work first.

= 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]


Wed Apr 03, 2013 12:57 am
Profile WWW
Rookie

Joined: Sat Mar 30, 2013 2:42 pm
Posts: 9
Post Re: help to set a tracking ball with NXTCam please!!!
I've been on this site in the beginning. I already set my camera to recognize the colors red, I even already done a white environment where there are the robot and the ball. with the following program it can recognize colors and give to me the position of the center of the object that I compare the center of the camera to see if the robot is facing. the second phase of my problem is that I would like to use this error to rotate the robot and it stops when the camera is in face the object.


#pragma config(Sensor, S1, cam, sensorI2CCustomFastSkipStates)

#include "mindsensors-nxtcam.h"

task main () {
blob_array _blobs;
memset(_blobs, 0, sizeof(_blobs)); // initialise the blobs
// combine all colliding blobs into one
bool _condensed = true;

//blob_array _blobs;
int _l, _t, _r, _b;
int _nblobs=0;
float x_center=0; // to get the center
float error=0; // to get the error
_l=0; _t=0; _r=0; _b=0;
eraseDisplay();

// Initialise the camera
NXTCAMinit(cam);
while(true) {
eraseDisplay();
// Fetch all the blobs, have the driver combine all

_nblobs = NXTCAMgetBlobs(cam, _blobs, _condensed);
for (int i = 0; i < _nblobs; i++) {

_l = (_blobs[i].x1);
_t = (_blobs[i].y1);
_r = (_blobs[i].x2);
_b = (_blobs[i].y2);

}
x_center = SIDE_CENTER (_l,_r); //get the center of blobs
error= x_center - 88; // get difference between center of blobs and camera
if(_nblobs == 0) {

nxtDisplayTextLine(3, "no object" );
}
else {
nxtDisplayTextLine(3, "the error is %f", error );
}
wait1Msec(1000);

}
}

/*
* $Id: mindsensors-nxtcam-test1.c 133 2013-03-10 15:15:38Z xander $
*/


Wed Apr 03, 2013 3:23 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: help to set a tracking ball with NXTCam please!!!
What you're looking for is a simple PID regulator, with just the P factor.

This what I have in my own code of one of my robots:
Code:
  // use 0.2 for REMbot for NXT
  // use 0.5 for Mammalbot
  float kP = 0.5;
  float currentHeading = SensorValue[COMPASS] % 3600;
  float error = requiredHeading * 10.0 - currentHeading;
  float powerR = aBehavior[winner].power - error * kP;
  float powerL = aBehavior[winner].power + error * kP;

  motor[M_LEFT] = round(powerL);
  motor[M_RIGHT] = round(powerR);


So basically, you need to figure out what you need to modify to make that work with your own robot.

= 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]


Wed Apr 03, 2013 5:49 am
Profile WWW
Rookie

Joined: Sat Mar 30, 2013 2:42 pm
Posts: 9
Post Re: help to set a tracking ball with NXTCam please!!!
I guess kp is the proportional gain but how did you do to get this value the same when you called REMbot 0.2 or Mamalbot 0.5.
perhaps I will disappoint you but can you explain to me line by line this little code, it become interescent because variables are in English and I feel not well understood.
Finally I do not even choice between the pid, p or pi what could do you recommend to me??


Wed Apr 03, 2013 8:11 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: help to set a tracking ball with NXTCam please!!!
alain wrote:
I guess kp is the proportional gain but how did you do to get this value the same when you called REMbot 0.2 or Mamalbot 0.5.
perhaps I will disappoint you but can you explain to me line by line this little code, it become interescent because variables are in English and I feel not well understood.
Finally I do not even choice between the pid, p or pi what could do you recommend to me??

I just copied those code verbatim from my own code, so the choices between the two values of Kp are just for me. I left them there as an illustration to show that Kp can have different values. What Kp is for your robot depends on many things and only through experimentation, will you find out what it is.

Code:
  float kP = 0.5;  // you need to change this for your robot
  int power = 30;        // you need to change this for your robot
  // this is the error
  float error = x_center - 88;

  // now calculate the amount of power to send to the motor
  // one motor always moves in the opposite direction.  You may
  // need to switch this around for your robot
  float powerR = power - error * kP;
  float powerL = power + error * kP;

  // now you must assign this power to your robot's motors
  motor[M_LEFT] = round(powerL);
  motor[M_RIGHT] = round(powerR);

I trust you will be able to clean up this code.

= 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]


Wed Apr 03, 2013 10:20 am
Profile WWW
Rookie

Joined: Sat Mar 30, 2013 2:42 pm
Posts: 9
Post Re: help to set a tracking ball with NXTCam please!!!
Thank you for this part of code I will test it tomorrow at school.
I begin to understand a little bit. today earlier in Class I had an idea for the parameters I need:
I have 2 options either I make a test on the surface of the object perceived by the camera for imagine the distance between the robot and the object so I can have the angle of rotation and hence its become easier thanks to your book (encodertarget) . second I can give a power and take the time and some angle rotations. if I'm not mistaken is that is what I done to have the value like kp??


Wed Apr 03, 2013 1:59 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: help to set a tracking ball with NXTCam please!!!
I am not sure I understand what your question is. Can you try explaining it again?

= 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]


Wed Apr 03, 2013 2:38 pm
Profile WWW
Rookie

Joined: Sat Mar 30, 2013 2:42 pm
Posts: 9
Post Re: help to set a tracking ball with NXTCam please!!!
symply in the mindsensor-nxtcam-test3 please could you remember which kind of test did you do to get p_x=0.5, i_x=0.05, d_x=1.8
if I know what kind of test did you do to get those gain I can adap to do some test to get my own value I have 13 hours left at school to finish the second part of my project


Wed Apr 03, 2013 4:35 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3227
Location: Rotterdam, The Netherlands
Post Re: help to set a tracking ball with NXTCam please!!!
Please ask the questions in place only.

Like I said on my blog, I just fiddled with the settings until it was working for me. If it moves too slowly, you increase P, if it's too fast, reduce it. You can forget about using I and D for now, they're not important.

= 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]


Wed Apr 03, 2013 5:01 pm
Profile WWW
Rookie

Joined: Sat Mar 30, 2013 2:42 pm
Posts: 9
Post Re: help to set a tracking ball with NXTCam please!!!
Morning every body with the Xander advice this is the first essay we need first to do robot found the ball after this we will do that it will move to track the balle.

http://www.youtube.com/watch?v=oZvv4Z3-hhQ

with the error we use the proportional gain to make some comand.

error=x_center - 88;
powerR = error*kp;
powerL = error*kp*(-1);
motor[left] = round(powerL);
motor[right] = round(powerR);

Mr Xander thank you for your time and your help you are the best. Next week, I think we will be able to do some thing very fine and post it with explanation for some one else. :D


Fri Apr 05, 2013 5:35 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page 1, 2  Next

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.