Example #1
0
string ofxPTZControl::sendCommand(string command){
         
    string cmd = "http://" + ip + ":" + ofToString(port) + "/cgi-bin/aw_ptz?cmd=%23" + command + "&res=1";
    
    float currentTime = ofGetElapsedTimeMillis();
    
    if (currentTime - lastCMDTime > 120){
        // dont spam the same command
        response = sendRawCommand(cmd);
        lastcmd = cmd;
        lastCMDTime = currentTime;
    } else if (lastcmd != cmd) {
        // if it is a new command wait untill 120 ms since the last command send, then send it
        ofSleepMillis(120 - (currentTime - lastCMDTime));
        response = sendRawCommand(cmd);
        lastcmd = cmd;
        lastCMDTime = currentTime;
    }
    
    return response.data;
}
void MotorController::sendCommandByVision (int visionCommand)
{
    switch (visionCommand)
    {
    case ImageProcessor::TENNISBALL_FRONT:
        sendRawCommand(MotorController::MOVE_FORWARD);
        break;
    case ImageProcessor::TENNISBALL_LEFT:
        sendRawCommand(MotorController::POINTTURN_LEFT);
        break;
    case ImageProcessor::TENNISBALL_RIGHT:
        sendRawCommand(MotorController::POINTTURN_RIGHT);
        break;
    case ImageProcessor::TENNISBALL_NOTFOUND:
        sendRawCommand(MotorController::NOTFOUND_PATROL);
        break;
    default:
        //SP->WriteData("S",dataLength);
        break;
    }
}