[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.8

controlling a robot arm problem

Asked by Besbous in C Programming Language

Tags: copy_image, lamda, yhome

Ok this is my first time ! Hi there !
I ve got a problem, I m working now on a experement of controlling Robot arm using image source(camera) that orders to the robert to move when it s sees an object, using the image signal processing. My problem is in the labeling phase, also I have written a program to calculate and draw the center of inertia just of 1 object, but i don t know how to do it for infinite numbers of objects.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

#include "robot.h"
#include "img.h"

#define MODE 4
/********************/

extern BYTE *img_work2;
extern BYTE *img_work3;

/********************/
/*********************************************************************************

**********************************************************************************/
void disp_image_while_kbhit(BYTE *img, HDC *hDC); /*(&#12469;&#12531;&#12503;&#12523;)*/
void gray2(BYTE *img_src, HDC *hDC);
void get_rid_of_noise(BYTE *img_src, BYTE *img_tmp, HDC *hDC);
double scan_angle(BYTE *img, int g_x, int g_y);
void straight_line(BYTE *img, int g_x, int g_y, double theta, HDC *hDC);
double sqrt( double x );
double atan2( double x,double y);
double tan( double x);

void myfunc(BYTE *img_src , BYTE *img_tmp , HDC *hDC){
  char motor;
  int  count;
  int  x1, y1, z1, x2, y2, z2 ;
  int i, j, s=0;
  int g_x, g_y, x_sum, y_sum, all_sum, threshold;
  double theta;

  switch(MODE){
  /*-- rotate_long&#12398;&#21205;&#20316;&#30906;&#35469;(1) ----------------------------------------*/
  case 1:
    printf("rotate_long&#12398;movement check(1)\n");
    printf(" motor? ");
    scanf("%c", &motor);

    printf(" count? ");
    scanf("%d", &count);

    rotate_long( motor, count );
    break;
  /*-- rotate_long movement check(2) ----------------------------------------*/
  case 2:
    count = 120;
    motor = 'B';
    printf("rotate_long\n");
    printf("&#12514;&#12540;&#12479;&#12540;%c&#12434;%d&#12384;&#12369;&#22238;&#36578;&#12375;&#12414;&#12377;&#12290;\n",motor,count);
    rotate_long( motor, count );
    getchar();
    printf("&#12514;&#12540;&#12479;&#12540;%c&#12434;%d&#12384;&#12369;&#22238;&#36578;&#12375;&#12414;&#12377;&#12290;",motor,-count);
    printf("&#20803;&#12395;&#25147;&#12428;&#12400;&#12289;&#27491;&#12375;&#12367;&#21205;&#20316;&#12375;&#12390;&#12356;&#12414;&#12377;&#12290;\n",motor,-count);
    rotate_long( motor, -count );
    getchar();
    break;
  /*-- move, move3 check-------------------------------------------*/
  /*    &#33258;&#20316;&#12375;&#12390;&#12367;&#12384;&#12373;&#12356;   */
  case 3:
    /* (1)coordonates*/
      printf("x1=\n"); scanf("%d",&x1);
      printf("x2=\n"); scanf("%d",&x2);
      printf("y1=\n"); scanf("%d",&y1);
      printf("y2=\n"); scanf("%d",&y2);
      printf("z1=\n"); scanf("%d",&z1);
      printf("z2=\n"); scanf("%d",&z2);
     
    /* (2)move the arm from Home vision to position1,oepn and close the grip */
      move(XHOME, YHOME, ZHOME, x1, y1, z1);
      grip();
      ungrip();
    /* (3)move the arm from cposition1 to position 2 */
      move(x1, y1, z1, x2, y2, z2);
      grip();
      ungrip();
    /* (4)move the arm back to home vision from position 2&#12289;and close back the grip */
      move(x2, y2, z2, XHOME, YHOME, ZHOME);
      home('A');
    /* (5)stop motors */
      stop_all();
    break;
  /*-- move, move3 -------------------------------------------*/

  case 4:
    /*display the image*/
       disp_image_while_kbhit(img_src, hDC);
    /*call the image source*/
        get_image(img_src);
      /*gray the image*/
         copy_image(img_src,img_tmp);
           gray2(img_tmp,hDC);
      /*kill the noise*/
        disp_gray_image(img_tmp,hDC);
         get_rid_of_noise(img_tmp,img_work2,hDC);
          copy_image(img_work2,img_tmp);
       
                show_monitor();
          disp_image(img_tmp,hDC);
        getchar();
      
            /*labeling*/
     
    /* the center of inertia */
      /*Caluculation the Surface :white color = object*/
       for(i=0;i<WIDTH;i++){
            for(j=0;j<HEIGHT;j++){
                   if(gray(img_tmp,j,i)==255){
                   s++;
                   }
             }
      }
    /*get the coordonates of the center of inertia */
     x_sum=0;
     y_sum=0;
     for(i=0;i<WIDTH;i++){
        for(j=0;j<HEIGHT;j++){
            if(gray(img_tmp,j,i)==255){
             x_sum+=i;
             y_sum+=j;
            }
      }
  }
  g_x=x_sum/s;
  g_y=y_sum/s;
  printf(" gx= %d, gy= %d\n", g_x, g_y);
      /*(draw)*/
  for(i=0;i<480;i++){
      rgb(img_tmp,i,g_x,R)=255;
    rgb(img_tmp,i,g_x,G)=0;
      rgb(img_tmp,i,g_x,B)=0;
  }
  for(j=0;j<640;j++){
      rgb(img_tmp,g_y,j,R)=255;
      rgb(img_tmp,g_y,j,G)=0;
      rgb(img_tmp,g_y,j,B)=0;
  }
  show_monitor();
   disp_image(img_tmp,hDC);
    getchar();
   /* get the angle */
  theta = scan_angle(img_tmp, g_x, g_y);
   printf("Angle=(%lf)\n",theta);
    straight_line(img_tmp, g_x, g_y, theta, hDC);
      show_monitor();
     disp_image(img_tmp,hDC);
   getchar();
  /*-------------------------------------------------------------------*/
    break;

  default:
    printf("MODE=%d&#12399;&#26377;&#21177;&#12391;&#12399;&#12354;&#12426;&#12414;&#12379;&#12435;&#12290;\n",MODE);
  }
}



/*++  &#12461;&#12540;&#12508;&#12540;&#12489;&#20837;&#21147;&#12364;&#12354;&#12427;&#12414;&#12391;&#12459;&#12513;&#12521;&#12398;&#26144;&#20687;&#12434;&#34920;&#31034;&#12377;&#12427;(&#12469;&#12531;&#12503;&#12523;) ++*/
void disp_image_while_kbhit(BYTE *img, HDC *hDC){
  show_monitor();        
  while(!_kbhit()){      
    get_image(img);      
    disp_image(img,hDC);  
  }
  _getch();              
}
 
void gray2(BYTE *img_src, HDC *hDC){
       
        int threshold;
         to_gray(img_src);
            from_gray(img_src);
              disp_image(img_src,hDC);
          show_monitor();
          disp_histgram(img_src,hDC);
        printf("Threshold Range =\n");
        scanf("%d", &threshold);
        binarize(img_src,threshold);
}

void get_rid_of_noise(BYTE *img_src, BYTE *img_tmp, HDC *hDC){
      int k,l;
printf("Enter Dilation EffectNum\n");
        scanf("%d",&k);
        printf("Enter Erosion EffectNum\n");
        scanf("%d",&l);
        copy_image(img_src,img_tmp);      
      erosion(img_tmp,k);
      dilation(img_tmp,l);
      dilation(img_tmp,l);
      erosion(img_tmp,k);
        show_monitor();
        disp_image(img_tmp,hDC);
        getchar();
}

double scan_angle(BYTE *img, int g_x, int g_y){
  double theta, lamda, s11=0, s12=0, s22=0;
   int x, y;
     for(x=0;x<WIDTH;x++){
        for(y=0;y<HEIGHT;y++){
              if(gray(img_work2, y, x)>100){
         s11=(x-g_x)*(x-g_x);
         s12=(x-g_x)*(y-g_y);
         s22=(y-g_y)*(y-g_y);
            }
        }
       }
        lamda=(s11+s22+sqrt(s11*s11+s22*s22-2*s11*s22+4*s12*s12))/2;
            theta=atan2(lamda-s11,s12);
        return theta;
}

void straight_line(BYTE *img_tmp, int g_x, int g_y, double theta, HDC *hDC){
  int x, y;
   for(x=0;x<WIDTH;x++){
              y=(double)(x-g_x)*tan(theta)+g_y;
       if(0>=y && y<HEIGHT){
    rgb(img_tmp,y,x,R)=255;
      rgb(img_tmp,y,x,G)=0;
      rgb(img_tmp,y,x,B)=0;
         }
   }
}
/*********************************************************************************
  *********************************************************************************/
#define LIMIT 90

void rotate_long( char motor, int count ) {

  int  margin, dir;


   if(count>0){
     dir = 1;
   }else{
     dir = -1;
     count =-count;
  }

  while( count > 0 ) {
    /* (2) &#12418;&#12375; motor &#12364;&#12473;&#12488;&#12540;&#12523;&#12375;&#12390;&#12356;&#12383;&#12425;, &#12522;&#12479;&#12540;&#12531;&#12377;&#12427; */
        if(stalled(motor)==1){
        return;
       }

        margin = LIMIT-distance(motor);
   
      if(count<margin){
      rotate(motor,dir*count);
      count=LIMIT;
      return;
     }
    /* (5) margin &#12364;&#27491;&#12398;&#22580;&#21512;&#12395;&#12398;&#12415;&#27425;&#12398;&#12424;&#12358;&#12394;&#20966;&#29702;&#12434;&#34892;&#12358;:
            margin &#12398;&#20516;&#12384;&#12369;&#31227;&#21205;&#12434;&#25351;&#20196;&#12375;, count &#12434; margin &#12384;&#12369;&#28187;&#12425;&#12377; */
       if(margin>0){
       rotate(motor,dir*margin);
       count=count-margin;
    }
  }
 
}


void      wait_DEF( void ) {
  /* &#12514;&#12540;&#12479; D, E, F &#12398;&#21205;&#20316;&#32066;&#20102;&#24453;&#12385;&#12523;&#12540;&#12481;&#12531;
   (D, E, F &#12398;&#12456;&#12521;&#12540;&#12524;&#12472;&#12473;&#12479;&#12398;&#12356;&#12378;&#12428;&#12363;&#12364;&#27491;&#12391;&#12354;&#12427;&#38291;&#65292;
   while &#12523;&#12540;&#12503;&#12434;&#22238;&#12426;&#32154;&#12369;&#12427;) */
    while(distance('D')>0 || distance('E')>0 || distance('F')>0){
    }
}

void       move(int x1, int y1, int z1, int x2, int y2, int z2) {

  double    a[3],forward[3];

  /* &#25163;&#20808;&#12434;(x1, y1, z1) &#12363;&#12425; (x2, y2, z2) &#12408;&#31227;&#21205;&#12373;&#12379;&#12424;&#65294; */

  /* (1)move from (x1, y1, z1) to (x2, y2, z2) */
      angle(x1,y1,z1,x2,y2,z2,a);
  /* (2)&#37197;&#21015; a &#12395;&#27714;&#12417;&#12383;&#22238;&#36578;&#35282;&#12434;&#12473;&#12486;&#12483;&#12503;&#25968;&#12395;&#22793;&#25563;&#12375;,
      &#12381;&#12428;&#12382;&#12428;&#37197;&#21015; forward &#12395;&#21454;&#12417;&#12427; */
       forward[MOTOR_D]=a[MOTOR_D]/STEP_D;
       forward[MOTOR_E]=a[MOTOR_E]/STEP_E;
       forward[MOTOR_F]=a[MOTOR_F]/STEP_F;
  /* (3)&#21508;&#38306;&#31680;&#12434;&#22238;&#36578;&#12373;&#12379;&#12427; */
       rotate_long('D',forward[MOTOR_D]);
       rotate_long('E',forward[MOTOR_E]);
       rotate_long('F',forward[MOTOR_F]);
  /* (4)&#21205;&#20316;&#12364;&#32066;&#20102;&#12377;&#12427;&#12414;&#12391;&#24453;&#12388; */
       while(distance('D')>0 || distance('E')>0 || distance('F')>0) {
    }


}


void       move3(int x1, int y1, int z1, int x2, int y2, int z2) {
  /* this part i want to move all the motors in the same time. so I wrote this following, not sure wether it s compatible or not */
int delta_x, delta_y, delta_z, dMAX;
  delta_x = x2-x1;
  delta_y = y2-y1;
  delta_z = z2-z2;
  dMAX = abs(delta_x);
  if (dMAX<abs(delta_y) && dMAX>abs(delta_z))
  dMAX = abs(delta_y);
  if(dMAX<abs(delta_z) && dMAX>abs(delta_y))
  dMAX = abs(delta_z);
  if(dMAX<abs(delta_y) && dMAX<abs(delta_z) && abs(delta_z)<abs(delta_y))
  dMAX = abs(delta_y);
  if(dMAX<abs(delta_y) && dMAX<abs(delta_z) && abs(delta_y)<abs(delta_z))
  dMAX = abs(delta_z);
  move(x1, y1, z1, dMAX + x1,  dMAX + y1, dMAX + z1);

}
/****************************************************************************************/

 actually what i want from this program is to display something like the following :
http://www.convict.lu/Jeunes/5%20DOF%20Robot-arm.htm (Get_object_positionsRAC.vi.). so I want my program to display howmany objects r there, and their coordonates of center of inetia, the angle ...!
 ah I think I want too much ! but man I have headach becoz of this program!

[+][-]11/26/03 01:11 AM, ID: 9823285Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C Programming Language
Tags: copy_image, lamda, yhome
Sign Up Now!
Solution Provided By: sunnycoder
Participating Experts: 1
Solution Grade: A
 
[+][-]11/04/03 06:39 AM, ID: 9678821Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/03 06:48 AM, ID: 9678892Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/03 06:50 AM, ID: 9678915Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/03 06:59 AM, ID: 9678969Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/03 08:11 AM, ID: 9679489Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/03 08:14 AM, ID: 9679514Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/03 08:31 AM, ID: 9679643Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/03 08:40 AM, ID: 9679721Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/03 08:48 AM, ID: 9679774Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/03 06:35 PM, ID: 9683894Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/03 09:22 PM, ID: 9684426Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/03 11:31 PM, ID: 9684939Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/03 11:34 PM, ID: 9684954Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/03 01:03 AM, ID: 9685270Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/03 08:27 AM, ID: 9687898Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/03 09:50 PM, ID: 9692254Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/03 05:39 AM, ID: 9693831Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/03 10:32 PM, ID: 9699325Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/03 11:36 PM, ID: 9699500Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/03 12:10 AM, ID: 9699608Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/03 12:11 AM, ID: 9699615Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/03 12:58 AM, ID: 9699801Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/03 04:22 AM, ID: 9706663Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/08/03 05:58 AM, ID: 9706843Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/09/03 08:57 AM, ID: 9710372Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/09/03 10:13 PM, ID: 9712563Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/03 03:20 AM, ID: 9714213Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/11/03 06:42 AM, ID: 9722448Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/15/03 12:39 AM, ID: 9753341Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/15/03 12:45 AM, ID: 9753356Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/18/03 06:28 PM, ID: 9775900Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/26/03 01:08 AM, ID: 9823279Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/27/03 05:02 PM, ID: 9834452Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12/02/03 08:00 AM, ID: 9859168Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92