element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Robotics
  • Technologies
  • More
Robotics
Forum vision guided robot  using android and arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Robotics to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 11 replies
  • Subscribers 62 subscribers
  • Views 1250 views
  • Users 0 members are here
Related

vision guided robot  using android and arduino

Former Member
Former Member over 13 years ago

i am doing vision gudied robot with arduino and android through bluetooth communication . i have done the image processing part using andriod.But i am facing problems in image processing. The colored image is getting transformed to black and white image. but the code that is written to detect the black tape is not working properly.. Could some one help me to debug.

 

 

public class DrawOnTop extends View

{

          BtConn btcon;

          //Display

          Bitmap mBitmap;

          Paint mPaint;

          int mImageWidth, mImageHeight;

 

          //Frame data

          byte[] mYUVData;

          int[] mRGBData;

          int[] mBWData;

 

          //FPS

                    long lastFrame = System.currentTimeMillis();

 

                    //PID

                    float proportional;

                    float integral;

                    float derivative;

                    float last_proportional;

                    int Kp=1;

                    int Kd=2;

                    int Ki=0;

 

                    //Motor Controls

                    int right_speed=0;

                    int left_speed=0;

                    int max_speed = 255;

 

          //Line Tracking

          static int tracking;

 

          int minPixels = 10;

          int threshold = 60;

          int tapeCenter;

    public DrawOnTop(Context context) {

        super(context);

 

        // Start off PAUSED

        tracking = 0;

 

        mPaint = new Paint();

        mPaint.setStyle(Paint.Style.FILL);

        mPaint.setColor(Color.RED);

        mPaint.setTextSize(25);

 

        mBitmap = null;

        mYUVData = null;

        mRGBData = null;

    }

 

 

    @Override

    protected void onDraw(Canvas canvas) {

        if (mBitmap != null)

        {

                  int canvasWidth = canvas.getWidth();

                  int canvasHeight = canvas.getHeight();                         

 

                  grayscaleToBlackWhite(mRGBData, mYUVData, mImageWidth, mImageHeight,canvas);

                  int tapeCenter=DetectingArea(canvas,mRGBData, mImageWidth, mImageHeight);

 

                  //PID

                        proportional = tapeCenter - mImageHeight/2;

                        integral = integral + proportional;

                        derivative = proportional - last_proportional;

                        last_proportional = proportional;

                        int lineError = (int)(proportional * Kp + integral * Ki + derivative * Kd);

 

                        // Restricting the error value between +/- max_speed.

                        if (lineError< -max_speed)

                        {

                                  lineError = -max_speed;

                        }

                        if (lineError> max_speed)

                        {

                                  lineError = max_speed;

                        }

 

                        // If error_value is less than zero calculate right turn speed values

                        if (lineError> 0)

                        {

                        right_speed = max_speed + lineError;

                        left_speed = max_speed;

 

                        }

                        // If error_value is greater than zero calculate left turn values

                        else

                        {    

                    right_speed = max_speed;

                        left_speed = max_speed - lineError;

 

                        }    

 

 

                        int[] data = new int[3];

                        data[0] = 0; //Forward

                        data[1] = right_speed;

                        data[2] = left_speed;

 

 

                  long curFrame = System.currentTimeMillis();

                  float fps = 1000/(curFrame - lastFrame);

                  lastFrame = curFrame;

 

 

 

 

                  // Draw bitmap

                  mBitmap.setPixels(mRGBData, 0, mImageWidth, 0, 0, mImageWidth, mImageHeight);

                  Rect src = new Rect(0, 0, mImageWidth, mImageHeight);

                  Rect dst = new Rect(0, 0, canvasWidth, canvasHeight);

                  canvas.drawBitmap(mBitmap, src, dst, mPaint);

 

 

 

 

 

                  canvas.rotate(-90, canvasWidth/2, canvasHeight/2);

                  mPaint.setTextSize(25);

                  canvas.drawText(mImageWidth + "x" + mImageHeight, 200, -140, mPaint);

                  canvas.drawText("fps: " + fps, 500, -100, mPaint);

 

 

        }

        super.onDraw(canvas);    

    }

 

 

 

 

    public void grayscaleToBlackWhite(int[] rgb, byte[] yuv420sp, int width, int height, Canvas canvas)

    {

 

              final int frameSize = width * height;

 

              mPaint.setTextSize(25);

 

 

              for (int pix = 0; pix < frameSize; pix++)

              {

                        int pixVal = (0xff & ((int) yuv420sp[pix])) - 16;

                        if (pixVal < threshold)

                        {

                                  pixVal = 0;

                        }

 

 

                        else

                                  pixVal = 255;

                        rgb[pix] = 0xff000000 | (pixVal << 16) | (pixVal << 8) | pixVal;

 

 

              }

             

 

    }

  public int DetectingArea(Canvas canvas,int rgb[],int height, int width)

  {

 

            int start=-1;

            int stop=-1;

            int tmpStart=-1;

            int tmpStop=-1;

          int scanline=-1;

            for(int i=0;i<width;i+=10)

            {

 

                                for(int j=0;j<height;j++)

                                 {

                                          //check for black line only.

                                          //find all black line centres and compare with the centre of the screen

                                          int pixVal = (0xff & (int) rgb[i+j*width]);

 

                                          if (pixVal == 0)

                                                      {

                                                              if(tmpStart==-1)

                                                              {

                                                                        tmpStart=j;

                                                              }

                                                              else

                                                              {

                                                                        tmpStop=j;

                                                                        if(tmpStop-tmpStart>minPixels &&

                                                                                            (Math.abs((tmpStop-tmpStart)/2 - height/2)

                                                                                            <  Math.abs(stop-start)/2 - height/2))

                                                                        {

                                                                                  start=tmpStart;

                                                                                  stop=tmpStop;

                                                                                  scanline=i;

                                                                        }

                                                                        else

                                                                        {

                                                                                  tmpStart=-1;

                                                                                  tmpStop=-1;

                                                                        }

                                                              }

 

                                                      }

                                 }

 

            }

            if (start > -1 && stop > -1 && scanline >-1) {

                        for (int pix = start; pix <= stop; pix++) {

                                        rgb[scanline+pix*width] = 0xff000000 | (0 << 16) | (255 << 8) | 0;

                        }

            }

 

 

            return (start+stop)/2;

 

  }

}

  • Sign in to reply
  • Cancel
Parents
  • Ramu
    Ramu over 13 years ago

    For comunication you can use something like this:
    http://www.ebay.com/itm/HC-07-Wireless-Bluetooth-to-UART-converter-RS232-TTL-COM-serial-port-slave-mode-/261096926176?pt=LH_DefaultDomain_0&hash=item3cca96ebe0

    but for this you will have to make shematic to pover and protect Bluatooth device. Because is uses 3.3V and inputs should be 3.3V or you can use something like this:

    http://www.ebay.com/itm/Bluetooth-Slave-CSR-TTL-Board-for-AVR-Arduino-UNO-R3-Mega-2560-1280-Mini-Pro-/170936257401?pt=LH_DefaultDomain_0&hash=item27cc984b79

     

    There are 3 types of this devices:

    1 - slave - other devices (like PC, phone and other Bluetooth master devices) can connect to it. You can set its name and all over AT commands.

    2 - master - this mode devices connect to other bluetoothe slave devices.

    3 - master/slave - this type devices can be changed from master to slave mode any time you want over AT commands.

     

    I think it is easier to buy slave and use mobile device to connect to the bluetoothe to uart slave device. I neves used it to connect it to mobile device, because I cant make apps for mobile devices, but I have tested it with my laptp. used it on arduino and on atmel devices.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to Ramu

    Thank you

    i got that we need a bluetooth module. But will it support evry android device

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Ramu
    Ramu over 13 years ago in reply to Former Member

    Basicly this devices I have showed you is bluetooth to serial converters, when you connect a pc to this device, it will install serial port or 2 serial ports. and then if your device is in range, you start using this new port as normal serial port and computer connects to BT device it self (if it was pairted and installled all needed drivers). Atleast it was like this for me. Drivers ar auto instald on win7.

    I do not know what about android... never tryed it. But as I know this device is seen with android.

    Maybe someone will tell you more how to use it on android.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Ramu
    Ramu over 13 years ago in reply to Former Member

    Basicly this devices I have showed you is bluetooth to serial converters, when you connect a pc to this device, it will install serial port or 2 serial ports. and then if your device is in range, you start using this new port as normal serial port and computer connects to BT device it self (if it was pairted and installled all needed drivers). Atleast it was like this for me. Drivers ar auto instald on win7.

    I do not know what about android... never tryed it. But as I know this device is seen with android.

    Maybe someone will tell you more how to use it on android.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube