title: Problems with my Drawing Arm System
body: <p>I am currently building a project that allows the user to input an image, and then draw it using an arm made of servos. The language used is C#. The way the program works, is that the user uploads a picture, then the picture is processed using the Sobel Edge Detection Algorithm  and it prints the new picture on a picture box. I have managed to get the values of X and Y from the picture, and making each servo in the arm to move along those points, thus drawing the picture on a blank paper, but The way Sobel works, its nearly impossible to draw an image without using a Z axis to know when to push the pen on the paper to draw and when not to. Here is the code I am using. I would like to know if there is something smoother like sketching and to draw it all in one round not having to move the pen up and down as the Z axis.</p>
  
  <pre><code>int oldi = 0;
  int oldj=0;
  private void sobel()
  {   
  
  
  
        Bitmap  originalImage = new Bitmap(ResizeImage(pictureBox1.Image, 70, 70));   
      Bitmap sobelImage = new Bitmap(originalImage);
      int width = originalImage.Width;
      int height = originalImage.Height;
  
      int[,] gx = new int[,] { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } };
      int[,] gy = new int[,] { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } };
  
      int[,] allPixR = new int[width, height];
      int[,] allPixG = new int[width, height];
      int[,] allPixB = new int[width, height];
  
      int limit = 150 * 150;
  
  
          for (int i = 0; i &lt; width; i++)
          {
              for (int j = 0; j &lt; height; j++)
              {
                  allPixR[i, j] = originalImage.GetPixel(i, j).R;
                  allPixG[i, j] = originalImage.GetPixel(i, j).G;
                  allPixB[i, j] = originalImage.GetPixel(i, j).B;
              }
          }
  
          int new_rx = 0, new_ry = 0;
          int new_gx = 0, new_gy = 0;
          int new_bx = 0, new_by = 0;
          int rc, gc, bc;
          for (int i = 1; i &lt; originalImage.Width - 1; i++)
          {
              for (int j = 1; j &lt; originalImage.Height - 1; j++)
              {
                  new_rx = 0;
                  new_ry = 0;
                  new_gx = 0;
  
  
           new_gy = 0;
                      new_bx = 0;
                      new_by = 0;
                      rc = 0;
                      gc = 0;
                      bc = 0;
  
                      for (int wi = -1; wi &lt; 2; wi++)
                      {
                          for (int hw = -1; hw &lt; 2; hw++)
                          {
                              rc = allPixR[i + hw, j + wi];
                              new_rx += gx[wi + 1, hw + 1] * rc;
                              new_ry += gy[wi + 1, hw + 1] * rc;
  
                              gc = allPixG[i + hw, j + wi];
                              new_gx += gx[wi + 1, hw + 1] * gc;
                              new_gy += gy[wi + 1, hw + 1] * gc;
  
                              bc = allPixB[i + hw, j + wi];
                              new_bx += gx[wi + 1, hw + 1] * bc;
                              new_by += gy[wi + 1, hw + 1] * bc;
                          }
                      }
  
                      if (new_rx * new_rx + new_ry * new_ry &gt; limit || new_gx * new_gx + new_gy *                    new_gy &gt; limit || new_bx * new_bx + new_by * new_by &gt; limit)
                      {
      // Draws the edges of the picture on picture box 2                 
  
         sobelImage.SetPixel(i, j, Color.Black);
  
  
  
  
  
                                  if (oldi != i)
                                  {
                                      oldi = i;
  
      // move along the X axis   
  
                            ezB_Connect1.EZB.Servo.SetServoPosition(EZ_B.Servo.ServoPortEnum.D0, i);
                                       Thread.Sleep(500);
  
  
                                  }
  
  
  
  
                                      if (oldj != j)
                                      {
                                         // move along the Y axis 
  </code></pre>
  
  <p>ezB_Connect1.EZB.Servo.SetServoPosition(EZ_B.Servo.ServoPortEnum.D1, j);</p>
  
  <pre><code>                                        oldj = j;
  
  
  
                                      }
  
  
  
                              }
  
                                 pictureBox2.Image = sobelImage;
                              }
  
  
  
  
                          else
                          {
      // draws white "fills the insides of edges" 
                                sobelImage.SetPixel(i, j, Color.White);
  
  
  
                          }
  
  
  
                  }
  
              }
  </code></pre>