Loading...
Logo
Processing Forum
xenophage's Profile
4 Posts
6 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    Hi everyone! I've begun writing a crude AI for my robot now. My robot scans the room with sonar and an Arduino sends the data back up to a computer on the robot and it slowly builds a map of the room. The sonar window starts as a blank white screen, and when it receives a distance measurement from a sonar, it draws an arc filled green with a red stroke. Below is my AI so far, but I'm running it only in a "simulated" environment until I get it more complete. Left clicking in the sonar window will draw a large green ellipse, and right clicking will draw a small red ellipse. My problem: The scanner isn't finding the green pixels, but if I set the background to solid green (background(0, 255, 0);), the scanner works. My thoughts are somehow the green ellipse is drawing green on another layer, and the scanner is still only scanning the white background, for those of you who might have worked a little with Photoshop. Do I need to be using PImage? The scanner will eventually be looking for green areas for the robot to safely move to, while staying at least 6 to 12 inches away from any red area. It will do this by giving each pixel (1 pixel = 1 square inch in real world) a rank or grade from 0 to 255 based on if the robot can move there or not. After it makes it's full scan, it will tell the robot to move to the pixel with the highest rank. I've been working on this robot for a little over a year now and has been lots of fun. I'm open to any tips too! Appreciate any answer someone can give as to why the scanner isn't finding the green pixels when I draw them.

    1. int [][][] myArray = new int [600][600][2];
    2. int drawgray;
    3. int SPx, SPy, SPrad;
    4. int AIscanx, AIscany;
    5. boolean SPscanreset, SPradreset;
    6. AIWindow aiWindow;
    7. int SPstartrad, SPendrad;
    8. float SPang, SPatan;
    9. int scloc;
    10. float scr, scg, scb;
    11. int rank;

    12. //variables already initialized by outside
    13. float r, g, b;
    14. float ardposx, ardposy, ardheading, ardcompass, ardheaddraw, ardheaddraw2;
    15. int mpl; //remove other mpl when merging to main System
    16. //end outside variables



    17. void setup () {
    18.   
    19.   //variables set by outside of AI
    20.   ardposx = 0;
    21.   ardposy = 0;
    22.   size(600, 600);
    23.   background(255, 255, 255);
    24.   //end outside variables
    25.   
    26.   SPstartrad = 2;//inner start radius for scanning in inches
    27.   SPendrad = 300;//how far out in inches to scan
    28.   SPrad = SPstartrad;
    29.   aiWindow = new AIWindow();
    30.   
    31.   SPscanreset = false;
    32.   SPradreset = false;
    33.   
    34.   translate(300,300);
    35.   loadPixels();
    36. }

    37. void draw () {
    38.   translate(300,300);
    39.   mpl = millis();//remove when merging
    40.   println("start");
    41.   
    42.   if (SPscanreset == true){
    43.     for (int i = 0; i < 600; i++) {
    44.       for (int j = 0; j < 600; j++) {
    45.         myArray[i][j][1] = 0;
    46.       }
    47.     }
    48.     SPscanreset = false;
    49.   }
    50.   
    51.   if (mousePressed && mouseButton == LEFT) {
    52.     stroke(0,255,0,63); fill(0,255,0,63);
    53.     ellipse(mouseX - 300, mouseY - 300, 50, 50);
    54.     //loadPixels();
    55.   }
    56.   if (mousePressed && mouseButton == RIGHT) {
    57.     stroke(255,0,0,63); fill(255,0,0,63);
    58.     ellipse(mouseX - 300, mouseY - 300, 3, 3);
    59.     //loadPixels();
    60.   }
    61.   
    62.   //start main spiral scan
    63.   SPrad++;//increment through radius
    64.   if (SPrad >= SPendrad) {
    65.     SPrad = SPstartrad;
    66.     loadPixels();
    67.     SPradreset = true;
    68.   }
    69.   SPatan = atan2(1, SPrad);
    70.   for (SPang = 0; SPang < TWO_PI; SPang = SPang + SPatan) {//increment through angle
    71.     
    72.     SPx = int(cos(SPang) * SPrad + ardposx);
    73.     SPy = int(sin(SPang) * SPrad + ardposy);
    74.     
    75.     if (SPx < 300 && SPx > -300 && SPy < 300 && SPy > -300) {
    76.       if (myArray[SPx + 300][SPy + 300][1] == 0) {
    77.         AIscan();
    78.         
    79.       }
    80.       myArray[SPx + 300][SPy + 300][1] = 1;
    81.     }
    82.   }
    83.   
    84.   
    85.   
    86.   println("MPL: " + (millis() - mpl));//remove when merging
    87.   println("SPrad: " + SPrad);
    88.   println("scr: " + scr);
    89.   println("scg: " + scg);
    90.   println("scb: " + scb);
    91.   println("rank: " + rank);
    92.   println("end");
    93. }//end sonar draw


    94. void AIscan() {
    95.   scloc = SPx + (SPy * 600);
    96.   scloc = constrain(scloc,0,359999);
    97.   scr = red(pixels[scloc]);
    98.   scg = green(pixels[scloc]);
    99.   scb = blue(pixels[scloc]);
    100.   
    101.   //decide rank value for this location
    102.   rank = int(scg - scr);
    103.   
    104.   if (scr == 255 && scg == 255 && scb == 255) rank = 0;
    105.   
    106.   //record rank
    107.   myArray[SPx + 300][SPy + 300][0] = rank;
    108. }


    109. public class AIWindow extends PApplet {
    110.   Frame frame;
    111.   int width = 600;
    112.   int height = 600;
    113.   //data applet init
    114.   
    115.   
    116.   AIWindow () {
    117.     width = 600;
    118.     height = 600;
    119.     frame = new Frame();
    120.     frame.setBounds(0, 0, 600, 600);
    121.     
    122.     frame.add(this);
    123.     this.init();
    124.     frame.show();
    125.     frameRate(30);
    126.     frame.pack();
    127.   }
    128.   
    129.   void setup() {
    130.     
    131.     size(600, 600);
    132.     //frameRate(30);
    133.     frame.setTitle("AI");
    134.     background(255, 255, 255);
    135.     smooth();
    136.   }
    137.   
    138.   void draw() {
    139.     //if (SPradreset = true) {
    140.       for (int i = 0; i < 600; i++) {
    141.         for (int j = 0; j < 600; j++) {
    142.           drawgray = int(255 - myArray[i][j][0]);
    143.           stroke(drawgray,drawgray,drawgray);
    144.           point(i,j);
    145.         }
    146.       }
    147.     //}
    148.     SPradreset = false;
    149.   }//end AI draw
    150.   
    151. }//end AI window
    Hello folks, I have a fairly simple problem here. I have a robot project and I'll simplify a bit but basically the communication syntax between robot and computer looks a bit like this "<0.1234JX>". I realize now that its not the best way but it worked well when the robot was in its infant stages, and rather than rewrite every location where they communicate, i really just need to pull out the 0.1234 from that string. the < and > will always be at the beginning and end. Im looking at numbers in about the range of 1000 down to 0.0001, and including negatives. The Arduino on the robot can parse this out easily with the atof(str) function, but i can't seem to find a processing equivalent. I dont want to use a for() loop for parsing, if I can avoid it. I have tried using Float.parseFloat(trim(clientindata)); and similar, but I get either a NaN or a communication error. Any ideas? Greatly appreciated!

    Here is a section of the code:

    1.   try {
    2.   if (thisClient != null) {
    3.     String clientindata = thisClient.readStringUntil('\n');
    4.     if (clientindata != null) {
    5.       
    6.       //system can read data coming from client here
    7.       indata = Float.parseFloat(trim(clientindata));
    8.       
    9.       if (match(clientindata, "JZ") != null){
    10.         camHjoyset = indata;
    11.         println("joyyz=" + indata);
    12.       }
    13.       if (match(clientindata, "JS") != null){
    14.         camVjoyset = indata;
    15.         println("joyys=" + indata);
    16.       }
    17.       
    18.       
    19.       
    20.       com4.write(trim(clientindata));//forward client data to Arduino
    21.       println(thisClient.ip() + " : " + clientindata);
    22.     } 
    23.   }
    24. }catch(Exception e) {
    25. println("Client port error");
    I trying to get Processing to send serial commands to a USB 16 port servo controller. The model number of this controller is the ZX_SERVO16U. I'm following the syntax for the serial commands as close as I can but the unit isn't responding. I have the port configured at 2400 baud in the device properties too. I realize that the highbyte  and lowbyte are actually commands in arduino that pull the first or last 8 bits of a 16 bit word, but I couldn't find a Processing equivalent. When I turn it on, the servo's center, so don't think it's a hardware issue. The pdf that came with the servo controller is here. Its written in PBASIC I think, and I'm having difficulties translating it. I have tried a serial port terminal program to send the code, but I'm pretty sure my formatting is wrong. If anyone has some sample code to a similar servo controller that would really help too. Any help is really appreciated! Thanks!
    1. import processing.serial.*;
    2. Serial com2;
    3. Byte servoCh, servoRa, lowByte, highByte;
    4. String SC;
    5. String D;
    6. void setup(){
    7.   SC = "!SC";
    8.   D = "\n";
    9.   println(Serial.list());
    10.   com2 = new Serial(this, "COM2", 2400);
    11.   servoCh = 0;
    12.   servoRa = 7;
    13.   lowByte = 0;
    14.   highByte = 2;
    15.   //com2.write(SC + servoCh + servoRa + lowByte + highByte + D);
    16. }

    17. void draw() {
    18.   lowByte = 50;
    19.   highByte = 2;
    20.   println("High");
    21.   com2.write(SC + servoCh + servoRa + lowByte + highByte + D);
    22.   println(SC + servoCh + servoRa + lowByte + highByte + D);
    23.   delay(500);
    24.   lowByte = 50;
    25.   highByte = 1;
    26.   println("Low");
    27.   com2.write(SC + servoCh + servoRa + lowByte + highByte + D);
    28.   println(SC + servoCh + servoRa + lowByte + highByte + D);
    29.   delay(500);
    30.   servoCh = byte(servoCh + 1);
    31.   if (servoCh >= 16) servoCh = 0;
    32.   println("Servo:" + servoCh);
    33. }
    Hi everyone! I'm working on a robot project, and I'm having trouble with the processing code running on the computer on the robot. It communicates with the micro-controller through com4, a gps on com5, and with a client program running on my laptop through a VPN port. I'm trying to add a window that reads the camera and does some basic red color object detection. The code in the PApplet was originally a separate program, and was working fine, I am trying to migrate it into the main program running on the robot. Run it and see where it error's out. It seems it's confused about which window to read pixels from. You only need a USB (or built in) camera hooked up to run this (and work eventually hopefully). Can someone explain how to choose which window to read the pixel from? Also, I intend on adding a 3rd window displaying a grey scale of ratings of where the robot plans to move, and a 4th window which will be the main control window (pulling the text info out of the sonar window). If it helps I can post the working object detection code separately. Much appreciated!

    1. import processing.serial.*; //serial port read library
    2. import processing.net.*;
    3. UIWindow uiWindow;
    4. Server myServer;
    5. int serverport = 1234;//port used to communicate with clients over Hamachi
    6. Serial com5;
    7. Serial com4;
    8. String dataincom4, dataoutcom4, dataincom5;
    9. Float Latitude1 = 0.0, Latitude2 = 0.0;
    10. String Latitude;
    11. String NorSindicator;
    12. Float Longitude1 = 0.0, Longitude2 = 0.0;
    13. String Longitude;
    14. String EorWindicator;
    15. String Satellites;
    16. String  Altitude;
    17. String gpsdata, gpsdata2;
    18. Float Speed1 = 0.0, Heading1 = 0.0;
    19. String Speed, Heading, Lock;
    20. int Lock1 = 0, Satellites1 = 0;
    21. Float firstLat = 0.0, firstLon = 0.0;
    22. int px = 0, py = 0;
    23. int[] keys = new int[256];
    24. String dataCode1, dataCode2;
    25. Float indata;
    26. Float ardposx, ardposy, ardheading, ardcompass, ardheaddraw, ardheaddraw2;
    27. int sonarinchL1, sonarinchR1, sonarinchL2, sonarinchR2;
    28. Float sx, sy, sxp, syp;
    29. int mpltimer;
    30. float beamwidth = 0.08;

    31.  import processing.video.*;
    32.  Capture myCapture;

    33. void setup(){
    34.   frame.setTitle("Sonar Map");

    35.   myServer = new Server(this, serverport);
    36.   size(800,600); //window size
    37.   //frameRate(10);
    38.   PFont myFont = createFont(PFont.list()[2],16); // font type
    39.   textFont(myFont);
    40.   background(255, 255, 255);
    41.   stroke(0,0,0);
    42.   //smooth();
    43.   println(Serial.list()); // displays port numbers for program
    44.   com5 = new Serial(this, "COM5", 9600); // serial read setup
    45.   com5.bufferUntil('\r'); // library buffer
    46.   com4 = new Serial(this, "COM4", 9600); // serial read setup
    47.   com4.bufferUntil(10); // library buffer
    48.   
    49.   ardheaddraw = 0.0;
    50.   ardheaddraw2 = 0.0;
    51.   ardposx = 0.0; ardposy = 0.0;
    52.   com4.write("<0.0I0>");//request x and y position
    53.   mpltimer = millis();
    54.   
    55.   uiWindow = new UIWindow();
    56. }

    57. void draw(){
    58.  fill(255, 255, 255);
    59.  rect(0, 0, 200, 600);//clear left text area for new text
    60.  fill(0, 0, 0);
    61.  stroke(0,0,0);
    62.  //window display
    63.  textAlign(LEFT);
    64.  text(" Latitude: " + Latitude, 10, 10);
    65.  text(" Longitude: " + Longitude, 10,30);
    66.  text(" Position: " + NorSindicator + "   " + EorWindicator, 10,50);
    67.  text(" Positive Lock:  " + Lock, 10,70);
    68.  text(" Satellites Used:  " + Satellites, 10,90);
    69.  text(" Altitude: " + Altitude + " Meters", 10,110);
    70.  text(" Speed: " + Speed, 10, 130);
    71.  text(" Heading: " + Heading1, 10, 150);
    72.  
    73.  text(" Data from Arduino", 10, 310);
    74.  text(" PosX: " + ardposx, 10, 330);
    75.  text(" PosY: " + ardposy, 10, 350);
    76.  text(" Sonar L2: " + sonarinchL2, 10, 370);
    77.  text(" Sonar L1: " + sonarinchL1, 10, 390);
    78.  text(" Sonar R1: " + sonarinchR1, 10, 410);
    79.  text(" Sonar R2: " + sonarinchR2, 10, 430);
    80.  text(" Heading: " + ardheading, 10, 450);
    81.  text(" Compass: " + ardcompass, 10, 470);
    82.  line(160, 430, 160, 430 - sonarinchL2);
    83.  line(170, 430, 170, 430 - sonarinchL1);
    84.  line(180, 430, 180, 430 - sonarinchR1);
    85.  line(190, 430, 190, 430 - sonarinchR2);
    86.  
    87.  fill(255,255,255);
    88.  ellipse(180, 450, 30, 30);
    89.  fill(0,0,0);
    90.  //arc(180, 450, 30, 30, ardheaddraw2 + 0.5, ardheaddraw2 - 0.5);
    91.  line(180, 450, cos(ardheaddraw2) * 15 + 180, sin(ardheaddraw2) * 15 + 450);

    92.  //text(" GPS unparsed: " + gpsdata, 20,170);
    93.  //text(" GPS unparsed: " + gpsdata2, 20,190);
    94.  
    95.  // draw points where sonars detect objects
    96.  //fill(255, 0, 0);
    97.  //point((ardposx + 500)
    98.  
    99.  if (mousePressed && mouseButton == LEFT){
    100.     point(mouseX, mouseY);
    101.   }
    102.  if (firstLat == 0.0 && firstLon == 0.0){
    103.    if (Latitude1 != 0.0 && Longitude1 != 0.0){
    104.      if (Satellites1 >= 3 && Lock1 >= 1){
    105.        firstLat = Latitude1 * 1000000.0;
    106.        firstLon = Longitude1 * 1000000.0;
    107.      }
    108.    }
    109.  }
    110.  if (firstLat != 0.0 && firstLon != 0.0){
    111.    py = int((firstLat - (Latitude1 * 1000000.0)) + (width / 2.0));
    112.    px = int((firstLon - (Longitude1 * 1000000.0)) + (width / 2.0));
    113.    //ellipse(px, py, 2, 2);
    114.  }
    115.   
    116.   //Get the next available client
    117.   Client thisClient = myServer.available();
    118.   //If the client is not null, and says something, display what it said
    119.   try {
    120.   if (thisClient != null) {
    121.     String clientindata = thisClient.readStringUntil('\n');
    122.     if (clientindata != null) {
    123.       com4.write(trim(clientindata));//forward client data to Arduino
    124.       println(thisClient.ip() + " : " + clientindata);
    125.     } 
    126.   }
    127. }catch(Exception e) {
    128. println("Client port error");
    129. //decide what to do here for the error
    130.   }
    131. print("MPL:"); println(millis() - mpltimer);
    132. mpltimer = millis();
    133. }

    134. //camera object detection applet
    135. public class UIWindow extends PApplet {
    136.  Frame frame;
    137.  int width = 320;
    138.  int height = 240;
    139.  
    140.  //camera object detect applet init
    141.  import processing.video.*;
    142.  Capture myCapture;
    143.  PImage img;
    144.  int w = 80, pixdetect = 0;
    145.  int objx1, objx2, objy1, objy2;

    146.  UIWindow ()
    147.  {
    148.    width = 320;
    149.    height = 240;
    150.    frame = new Frame();
    151.    frame.setBounds(0, 0, width, height);
    152.    
    153.    frame.add(this);
    154.    this.init();
    155.    frame.show();
    156.    frameRate(30);
    157.  }
    158.  
    159. void setup() {
    160.   size(320, 240);
    161.   frameRate(30);
    162.   
    163.   myCapture = new Capture(this, 320, 240, 1);
    164.   myCapture.frameRate(30);
    165.   frame.setTitle("Camera object detect");
    166. }

    167. void draw() {
    168.   int[][] obj = new int[320][240];
    169.   
    170.   if(myCapture.available()) { 
    171.     myCapture.read();  
    172.     image(myCapture, 0, 0);
    173.     img = myCapture;
    174.   }
    175.   objx1 = 160; objx2 = 160; objy1 = 120; objy2 = 120;
    176.   loadPixels();
    177.   // Begin loop for every pixel
    178.   for (int x = 1; x < width; x++) {
    179.     for (int y = 1; y < height; y++ ) {
    180.       color c = detection(x,y,img);
    181.       int loc = x + y*320;
    182.       pixels[loc] = c;
    183.       obj[x][y] = pixdetect;
    184.     }
    185.   }
    186.   updatePixels();
    187.   //Begin search for objects
    188.   for (int x = 2; x < 320 - 1; x++) {
    189.     for (int y = 2; y < 240 - 1; y++ ) {
    190.       if (obj[x][y] == 1 && obj[x+1][y] == 1 && obj[x-1][y] == 1 && obj[x][y+1] == 1 && obj[x][y-1] == 1) {
    191.         if (x > objx1 && objx1 == int(width/2)) objx1 = x;
    192.         if (x < objx2 && objx2 == int(width/2)) objx2 = x;
    193.         if (x > objy1 && objy1 == int(height/2)) objy1 = y;
    194.         if (x > objy2 && objy2 == int(height/2)) objy2 = y;
    195.     
    196.         if (x < objx1) objx1 = x;
    197.         if (x > objx2) objx2 = x;
    198.         if (y < objy1) objy1 = y;
    199.         if (y > objy2) objy2 = y;
    200.       }
    201.       
    202.     }
    203.   }
    204.   stroke(255,0,0);
    205.   rect(objx1, objy1, objx2 - objx1, objy2 - objy1);
    206.   
    207.   stroke(0);
    208.   noFill();
    209.   //rect(xstart,ystart,w,w);
    210. }

    211. color detection(int x, int y, PImage img) {
    212.   // What pixel are we testing
    213.   
    214.   int loc = x + 320*y;
    215.   // Make sure we have not walked off the edge of the pixel array
    216.   loc = constrain(loc,1,76799);
    217.   float r = red(pixels[loc]);
    218.   float g = green(pixels[loc]);
    219.   float b = blue(pixels[loc]);
    220.   float br = brightness(pixels[loc]);
    221.   float sa = saturation(pixels[loc]);
    222.   if (br + sa > 255.0 && r > 70.0 && r > g + 40.0 && r > b + 40.0 && g - b < 30.0 && g - b > -30.0) {
    223.     r = 255.0; g = 0.0; b = 0.0;
    224.     pixdetect = 1;

    225.   }else {
    226.     pixdetect = 0;
    227.     //r = 0.0; g = 0.0; b = 0.0;
    228.   }
    229.   
    230.   // Return the resulting color
    231.   return color(r,g,b);
    232. }

    233. }
    234. //end camera object detect applet

    235. // function reads the gps or Arduino data and sends it to the parsing function
    236. void serialEvent(Serial thisPort) {
    237.   try {
    238.   if (thisPort == com5){
    239.     String dataincom5 = com5.readStringUntil('\n');
    240.     if (dataincom5 != null) {
    241.       //println("com5:");
    242.       //println(dataincom5);
    243.       myServer.write(trim(dataincom5) + ", com5\n");//forward data to client
    244.       parseStringcom5(dataincom5);
    245.     }
    246.   }
    247.   if (thisPort == com4){
    248.     String dataincom4 = com4.readStringUntil('\n');
    249.     if (dataincom4 != null) {
    250.       //println("com4:");
    251.       //println(dataincom4);
    252.       myServer.write(trim(dataincom4) + ", com4\n");//forward data to client
    253.       parseStringcom4(dataincom4);
    254.     }
    255.   }
    256. }catch(Exception e) {
    257. println("Com port error");
    258. //decide what to do here for the error
    259.   }
    260. }

    261. //parse com4 Arduino
    262. void parseStringcom4 (String serialString) {
    263.   String[] list = split(serialString, ',');
    264.   indata = float(list[0]);
    265.   dataCode1 = list[1];
    266.   dataCode2 = list[2];
    267.   //println(indata);
    268.   //println(dataCode1);
    269.   //println(dataCode2);
    270.   
    271.   if (dataCode1.equals("L") && dataCode2.contains("1")){
    272.     sonarinchL1 = int(indata);
    273.     sx = (500 + ardposx) + (cos(ardheaddraw + 0.5) * 15.0);
    274.     sy = (300 - ardposy) - (sin(ardheaddraw + 0.5) * 15.0);
    275.     sxp = sx + (cos(ardheaddraw) * sonarinchL1);
    276.     syp = sy - (sin(ardheaddraw) * sonarinchL1);
    277.     stroke(200,255,255,63); fill(200,255,255,63);
    278.     line(sx, sy, sxp, syp);
    279.     stroke(200,0,0,63);
    280.     if (sonarinchL1 > 240) stroke(200,255,255,63);
    281.     arc(sx, sy, sonarinchL1 * 2.0, sonarinchL1 * 2.0, (ardheaddraw2 - beamwidth), (ardheaddraw2 + beamwidth));
    282.   }
    283.   if (dataCode1.equals("L") && dataCode2.contains("2")){
    284.     sonarinchL2 = int(indata);
    285.     sx = (500 + ardposx) + (cos(ardheaddraw + 0.6) * 8.0);
    286.     sy = (300 - ardposy) - (sin(ardheaddraw + 0.6) * 8.0);
    287.     sxp = sx + (cos(ardheaddraw + QUARTER_PI) * sonarinchL2);
    288.     syp = sy - (sin(ardheaddraw + QUARTER_PI) * sonarinchL2);
    289.     stroke(200,255,255,63); fill(200,255,255,63);
    290.     line(sx, sy, sxp, syp);
    291.     stroke(200,0,0,63);
    292.     if (sonarinchL2 > 240) stroke(200,255,255,63);
    293.     arc(sx, sy, sonarinchL2 * 2.0, sonarinchL2 * 2.0, ((ardheaddraw2 - QUARTER_PI) - beamwidth), ((ardheaddraw2 - QUARTER_PI) + beamwidth));
    294.   }
    295.   if (dataCode1.equals("R") && dataCode2.contains("1")){
    296.     sonarinchR1 = int(indata);
    297.     sx = (500 + ardposx) + (cos(ardheaddraw - 0.5) * 15.0);
    298.     sy = (300 - ardposy) - (sin(ardheaddraw - 0.5) * 15.0);
    299.     sxp = sx + (cos(ardheaddraw) * sonarinchR1);
    300.     syp = sy - (sin(ardheaddraw) * sonarinchR1);
    301.     stroke(200,255,255,63); fill(200,255,255,63);
    302.     line(sx, sy, sxp, syp);
    303.     stroke(200,0,0,63);
    304.     if (sonarinchR1 > 240) stroke(200,255,255,63);
    305.     arc(sx, sy, sonarinchR1 * 2.0, sonarinchR1 * 2.0, (ardheaddraw2 - beamwidth), (ardheaddraw2 + beamwidth));
    306.   }
    307.   if (dataCode1.equals("R") && dataCode2.contains("2")){
    308.     sonarinchR2 = int(indata);
    309.     sx = (500 + ardposx) + (cos(ardheaddraw - 0.6) * 8.0);
    310.     sy = (300 - ardposy) - (sin(ardheaddraw - 0.6) * 8.0);
    311.     sxp = sx + (cos(ardheaddraw - QUARTER_PI) * sonarinchR2);
    312.     syp = sy - (sin(ardheaddraw - QUARTER_PI) * sonarinchR2);
    313.     stroke(200,255,255,63); fill(200,255,255,63);
    314.     line(sx, sy, sxp, syp);
    315.     stroke(200,0,0,63);
    316.     if (sonarinchR2 > 240) stroke(200,255,255,63);
    317.     arc(sx, sy, sonarinchR2 * 2.0, sonarinchR2 * 2.0, ((ardheaddraw2 + QUARTER_PI) - beamwidth), ((ardheaddraw2 + QUARTER_PI) + beamwidth));
    318.   }
    319.   
    320.   stroke(200,0,0,127);
    321.   point(sxp,syp);
    322.   
    323.   if (dataCode1.equals("P") && dataCode2.contains("X")){
    324.     ardposx = indata;
    325.   }
    326.   if (dataCode1.equals("P") && dataCode2.contains("Y")){
    327.     ardposy = indata;
    328.     stroke(200,255,255, 63); fill(200,255,255, 63);
    329.     ellipse(ardposx + 500, -ardposy + 300, 20, 20);
    330.     stroke(0,0,0);
    331.     point(ardposx + 500, -ardposy + 300);
    332.   }
    333.   if (dataCode1.equals("H") && dataCode2.contains("0")){
    334.     ardheading = indata;
    335.     ardheaddraw = indata + HALF_PI;
    336.     ardheaddraw2 = (-indata) - HALF_PI;
    337.   }
    338.   if (dataCode1.equals("H") && dataCode2.contains("1")){
    339.     ardcompass = indata;
    340.   }
    341.   stroke(0,0,0);
    342.   fill(0,0,0);
    343. }
    344.  //parse com5 GPS
    345. void parseStringcom5 (String serialString) {
    346.   //sets up an array and splits the gps info by comma
    347.   String items[] = split(serialString,','); 
    348.   if(items[0].equals("$GPGGA")) {  //looks for the GPGGA info
    349.     getGGA(items);
    350.   }
    351.   if(items[0].equals("$GPRMC")) {  //looks for the GPRMC info
    352.     getRMC(items);
    353.   }
    354.   
    355.   //Convert data for Arduino
    356.   Heading1 = int(-Heading1 * (PI / 180.0) * 1000.0) / 1000.0;//0-360 to 0 - -2PI
    357.   if (Heading1 < -PI) Heading1 = Heading1 + TWO_PI;//0-2PI to -PI - PI
    358.   
    359.   //begin transmitting data to Arduino
    360.   com4.write("<" + Satellites1 + "S0>");
    361.   com4.write("<" + Heading1 + "H0>");
    362.   //end transmission
    363. }

    364. //this function assigns the variables 
    365. //to array elements that have been parsed
    366. void getGGA(String[] gpsinfo){
    367.   //if (gpsinfo[1].equals("A")){
    368.   Latitude1 = float(gpsinfo[2])/100.0;//DD.MM.MMMM
    369.   Latitude2 = Latitude1 - int(Latitude1);//00.MMMMMM
    370.   Latitude2 = (Latitude2 * 100.0) / 60.0;//00.DDDD
    371.   Latitude1 = int(Latitude1) + Latitude2;//DD.DDDD
    372.   Latitude = nfs(Latitude1, 3,7);
    373.   NorSindicator = gpsinfo[3];
    374.   Longitude1 = float( gpsinfo[4])/100.0;//DDD.MM.MMMM
    375.   Longitude2 = Longitude1 - int(Longitude1);//00.MMMMMM
    376.   Longitude2 = (Longitude2 * 100.0) / 60.0;//00.DDDD
    377.   Longitude1 = int(Longitude1) + Longitude2;//DD.DDDD
    378.   Longitude = nfs(Longitude1, 3,7);
    379.   EorWindicator = gpsinfo[5];
    380.   Lock1 = int(gpsinfo[6]);
    381.   Lock = nfs(Lock1, 1, 0);
    382.   Satellites1 = int(gpsinfo[7]);
    383.   Satellites = nfs(Satellites1, 2, 0);
    384.   Altitude = gpsinfo[9];
    385.   gpsdata = join(gpsinfo,",");
    386.  }
    387.  
    388.  void getRMC(String[] gpsinfo){
    389.   //if (gpsinfo[1].equals("A")){
    390.   Speed1 = float(gpsinfo[7]);
    391.   Speed = nfs(Speed1, 3,2);
    392.   Heading1 = float( gpsinfo[8]);
    393.   Heading = nfs(Heading1, 3,2);
    394.   gpsdata2 = join(gpsinfo,",");
    395.  }

    396. //check for keys being pressed, and send them to arduino
    397. void keyPressed() {
    398.   if (keys[keyCode] == 0){
    399.     com4.write("<" + keyCode + "K1>");
    400.     keys[keyCode] = 1;
    401.   }
    402. }
    403. void keyReleased() {
    404.   if (keys[keyCode] == 1){
    405.     com4.write("<" + keyCode + "K0>");
    406.     keys[keyCode] = 0;
    407.   }
    408. }