Read to serial port while the CMUcam4 is tracking color

Added by Piero Cabassa about 2 years ago

Hello! This is my situation, I've connected the CMUcam4 to an ArduinoUNO, the ArduinoUNO is connected with a software serial port to a Romeo V2 (Arduino Leonardo).
With a program on mu PC written in C#, I send command to the Romeo V2, and it send a request to the ArduinoUNO.
The ArduinoUNO/CMUcam4 begin to track color (red), no problem. But I can't to stop the tracking.

This is the situation:

PC -> begin tracking -> Romeo -> begin tracking -> ArduinoUNO/CMUcam4 = no problem!

PC -> stop tracking -> Romeo -> stop tracking -> ArduinoUNO/CMUcam4 = no effect

This is the sketch on the ArduinoUNO/CMUcam4:

@#include <SoftwareSerial.h>
#include <CMUcam4.h>
#include <CMUcom4.h>

// Definizione dei pin utilizzati per la seriale di comunicazione alla Romeo
#define rxPin 6
#define txPin 7

// Definizione dei parametri per il riconoscimento del colore rosso
#define RED_MIN 110
#define RED_MAX 255
#define GREEN_MIN 0
#define GREEN_MAX 60
#define BLUE_MIN 0
#define BLUE_MAX 60
#define LED_BLINK 5 // 5 Hz
#define WAIT_TIME 5000 // 5 secondi

// Dichiarazione della porta seriale utilizzata per la comunicazione con la Romeo
SoftwareSerial SerialeUNO(rxPin, txPin); // RX, TX

// Dichiarazione della variabile per l'utilizzo della CMUcam4
CMUcam4 cam(CMUCOM4_SERIAL);

void setup()
{  
  // Settaggio della CMUcam4
  cam.begin();  
  cam.LEDOn(LED_BLINK);
  delay(WAIT_TIME);
  cam.autoGainControl(false);
  cam.autoWhiteBalance(false);
  cam.LEDOn(CMUCAM4_LED_ON);

  // Settaggio servi pan e tilt
  cam.setServoPosition(0, 1, 1500);
  cam.setServoPosition(1, 1, 1500);

  // Impostazione dei pin di ricezione e trasmissione
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT); 

  // Apertura della porta seriale
  SerialeUNO.begin(9600); 
}

void loop()
{
  if (SerialeUNO.available()) // Se ci sono dati in lettura
  {
    int car = SerialeUNO.read(); // Leggo il dato
    switch (car)
    {
     case '1':           
              // Avvio il riconoscimento del colore rosso
              CMUcam4_tracking_data_t data;
              cam.trackColor(RED_MIN, RED_MAX, GREEN_MIN, GREEN_MAX, BLUE_MIN, BLUE_MAX);
              while (car != '2') 
              {                
                car = SerialeUNO.read();
                cam.getTypeTDataPacket(&data); 
                cam.automaticPan(true, false);
                cam.automaticTilt(true, false);                
              }        

     break;
    }        
  }
  //SerialeUNO.flush(); // Pulisco il buffer della porta seriale
}@

The value "2" is for to stop the tracking.
Thanks for help!

Replies (1)

RE: Read to serial port while the CMUcam4 is tracking color - Added by Kwabena Agyeman about 2 years ago

You don't have any logic in the code to stop tracking. The best thing todo is to set the tracking colors to all zero. Or just disable the servo output.

Sorry about responding so late, the automatic email system for the forums appears to no longer work. So, I have no idea when anyone posts.

(1-1/1)