Wednesday, October 1, 2014

Robot Auto Recov Snippet

time_t currtime = time(NULL); // CURRENT TIME
struct tm beg; //WHEN IT ALL BEGAN
 beg = *localtime(&now);
if(BUTT_1=LOW){//PRESSING DOWN
 for((double seconds = difftime(currtime, mktime(&beg)<20){ //JUST SUBTRACT THE TWO TIMES
  time_t currtime = time(NULL); // CURRENT TIME
ORANGE_MTR_SPEED=GREEN_MTR_SPEED= //STANDARD HIGH SPEED
UPP=ORANGE_2=BROWN_2=_BLUE_2=GREEN_2;
ORANGE_1|= FWD1;
GREEN_1|=REV1;
BLUE_1=FWD1;
BROWN_1=REV1;
UPP=UP1; //UPWARD THRUST IN CASE ON BOTTOM OF POOL
delay(100);
ORANGE_MTR_SPEED=GREEN_MTR_SPEED= // LOW SPEED
UPP=DWN1;// BRING THE BOT DOWN TO ORIGNAL POSTION, OUGHT TO TAKE 10 SECONDS=100 MILLISECONDS
delay(100);
}

**************************************************
Quick Cam fix
  
import processing.video.*;
int a=0;
int b=0;
Capture img;
float[][] kernel = {{ -1, -1, -1}, 
                    { -1,  9, -1}, 
                    { -1, -1, -1}};
void setup() {
  size(1280, 720);

  String[] cameras = Capture.list();
  
  if (cameras.length == 0) {
    println("There are no cameras available for capture.");
    exit();
  } else {
    println("Available cameras:");
    for (int i = 0; i < cameras.length; i++) {
      println(cameras[i]);
    }
    
    // The camera can be initialized directly using an 
    // element from the array returned by list():
    img = new Capture(this, cameras[3]);
    img.start();     
  }      
}

void draw() {
  if (img.available() == true) {
    img.read();
  }


 img.loadPixels();
  // Create an opaque image of the same size as the original
  PImage edgeImg = createImage(img.width, img.height, RGB);
  // Loop through every pixel in the image.
  for (int y = 1; y < img.height-1; y++) { // Skip top and bottom edges
    for (int x = 1; x < img.width-1; x++) { // Skip left and right edges
      float sum = 0; // Kernel sum for this pixel
      for (int ky = -1; ky <= 1; ky++) {
        for (int kx = -1; kx <= 1; kx++) {
          // Calculate the adjacent pixel for this kernel point
          int pos = (y + ky)*img.width + (x + kx);
          // Image is grayscale, red/green/blue are identical
          float val = red(img.pixels[pos]);
          // Multiply adjacent pixels based on the kernel values
          sum += kernel[ky+1][kx+1] * val;
        }
      }
      // For this pixel in the new image, set the gray value
      // based on the sum from the kernel
      edgeImg.pixels[y*img.width + x] = color(sum, sum, sum);
    }
  }
  // State that there are changes to edgeImg.pixels[]
  edgeImg.updatePixels();
  // Draw the new image
   translate(width/1.2, height/1.2);
   rotate(radians(180));
  image(edgeImg, 20, 0);
noFill();
strokeWeight(2);
stroke(204, 102, 0);
 line(230, 225, 460, 225);
 line(200, 180, 490, 180);
 line(150, 100, 540, 100);
 a= a+1;
 b=b+1;
 if(a==100){
  save(b+".jpg");
  a=0;
 }
}


No comments:

Post a Comment