go_away

Author Topic: Cmucam4+arduino+servo  (Read 1595 times)

0 Members and 1 Guest are viewing this topic.

Offline farukk!Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Cmucam4+arduino+servo
« on: December 20, 2012, 01:49:52 PM »
Hi,i am working on a robot that tracks a red ball with cmucam4+arduino+servo.I do have a question. I can reach data.mx(it is between 0-159 the mid mass x value) in cam.getTypeTDataPacket(&data) structure(the tracking packet),the question is can i map it like in code to control the continuous rotation servo without using instead of analogRead() ? Code is not done yet,but i wanted to know if i was doing correct.

i am asking about this line: myservo.write(map(average, 91,159, 130, 179));

Thanks.
Code: [Select]
#include <CMUcam4.h>
#include <CMUcom4.h>
#include <Servo.h>
 
 
#define RED_MIN 120
#define RED_MAX 200
#define GREEN_MIN 60
#define GREEN_MAX 80
#define BLUE_MIN 50
#define BLUE_MAX 70
#define LED_BLINK 5 // 5 Hz
#define WAIT_TIME 5000 // 5 seconds
#define LED_DELAY 10
#define DELAY_TIME 5000
CMUcam4 cam(CMUCOM4_SERIAL);
Servo myservo;  // create servo object to control a servo
void setup()
{
  cam.begin();
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  // Wait for auto gain and auto white balance to run.

  cam.LEDOn(LED_BLINK);
  delay(WAIT_TIME);

  // Turn auto gain and auto white balance off.
  cam.autoGainControl(true);
  cam.autoWhiteBalance(true);
  cam.LEDOn(LED_DELAY);
  delay(DELAY_TIME);
  cam.autoGainControl(false);
  cam.autoWhiteBalance(false);
  cam.noiseFilter(5);
  cam.LEDOn(CMUCAM4_LED_ON);
}

void loop()
{
  CMUcam4_tracking_data_t data;

  cam.trackColor(RED_MIN, RED_MAX, GREEN_MIN, GREEN_MAX, BLUE_MIN, BLUE_MAX);
int average;
int learning_rate = 50; // Try different values for this... between 0 and 100.
 
 
average = ((((100 - learning_rate) * data.mx) + (learning_rate * data.mx)) / 100);

  for(;;)
  {
   
    cam.getTypeTDataPacket(&data); // Get a tracking packet.
 
   if(average>>90)
    {
 
   myservo.write(map(average, 91,159, 130, 179));             
    }
    else if(average<<90 && average >> 70)
   
    {
       myservo.write(map(average, 70,90, 130,130));
    }

Offline farukk!Topic starter

  • Beginner
  • *
  • Posts: 2
  • Helpful? 0
Re: Cmucam4+arduino+servo
« Reply #1 on: December 21, 2012, 07:41:47 AM »
I am supposing noone understood what i asked ,anyway. Thanks.

 


Get Your Ad Here

data_list