/** * Constructor for this robot subclass. * Create an instance of a RobotDrive with left and right motors * plugged into PWM ports 1 and 2 on the first digital module. The two * servos are PWM ports 3 and 4. */ VisionServoDemo(void) { ds = DriverStation::GetInstance(); myRobot = new RobotDrive(1, 2, 0.5); // robot will use PWM 1-2 for drive motors rightStick = new Joystick(1); // create the joysticks leftStick = new Joystick(2); horizontalServo = new Servo(3); // create horizontal servo verticalServo = new Servo(4); // create vertical servo servoDeadband = 0.01; // move if > this amount sinStart = 0.0; // control whether to start panning up or down m_pDashboard = &(m_ds->GetDashboardPacker()); /* set up debug output: * DEBUG_OFF, DEBUG_MOSTLY_OFF, DEBUG_SCREEN_ONLY, * DEBUG_FILE_ONLY, DEBUG_SCREEN_AND_FILE */ SetDebugFlag(DEBUG_FILE_ONLY); /* start the CameraTask */ if (StartCameraTask(20, 0, k160x120, ROT_180) == -1) { DPRINTF(LOG_ERROR, "Failed to spawn camera task; exiting. Error code %s", GetVisionErrorText(GetLastVisionError())); } m_pVideoServer = new PCVideoServer; /* allow writing to vxWorks target */ Priv_SetWriteFileAllowed(1); /* stop the watchdog if debugging */ GetWatchdog().SetEnabled(false); }
/** * Internal method that actually writes the table to a file. * This is called in its own thread when {@link Preferences#Save() Save()} is called. */ void Preferences::WriteTaskRun() { Synchronized sync(m_tableLock); semGive(m_fileOpStarted); FILE *file = NULL; Priv_SetWriteFileAllowed(1); file = fopen(kFileName, "w"); fputs("[Preferences]\n", file); std::vector<std::string>::iterator it = m_keys.begin(); for (; it != m_keys.end(); it++) { std::string key = *it; std::string value = m_values[key]; std::string comment = m_comments[key]; if (!comment.empty()) fputs(comment.c_str(), file); fputs(key.c_str(), file); fputs(kValuePrefix, file); fputs(value.c_str(), file); fputs(kValueSuffix, file); } if (!m_endComment.empty()) fputs(m_endComment.c_str(), file); if (file != NULL) fclose(file); NetworkTable::GetTable(kTableName)->PutBoolean(kSaveField, false); }
/** * Constructor for this robot subclass. * Create an instance of a RobotDrive with left and right motors plugged into PWM * ports 1 and 2 on the first digital module. The two servos are PWM ports 3 and 4. * Tested with camera settings White Balance: Flurorescent1, Brightness 40, Exposure Auto */ TwoColorDemo(void) { ds = DriverStation::GetInstance(); myRobot = new RobotDrive(1, 2, 0.5); // robot will use PWM 1-2 for drive motors rightStick = new Joystick(1); // create the joysticks leftStick = new Joystick(2); // remember to use jumpers on the sidecar for the Servo PWMs horizontalServo = new Servo(9); // create horizontal servo on PWM 9 verticalServo = new Servo(10); // create vertical servo on PWM 10 servoDeadband = 0.01; // move if > this amount framesPerSecond = 15; // number of camera frames to get per second sinStart = 0.0; // control where to start the sine wave for pan memset(&par, 0, sizeof(par)); // initialize particle analysis report /* image data for tracking - override default parameters if needed */ /* recommend making PINK the first color because GREEN is more * subsceptible to hue variations due to lighting type so may * result in false positives */ // PINK sprintf(td1.name, "PINK"); td1.hue.minValue = 220; td1.hue.maxValue = 255; td1.saturation.minValue = 75; td1.saturation.maxValue = 255; td1.luminance.minValue = 85; td1.luminance.maxValue = 255; // GREEN sprintf(td2.name, "GREEN"); td2.hue.minValue = 55; td2.hue.maxValue = 125; td2.saturation.minValue = 58; td2.saturation.maxValue = 255; td2.luminance.minValue = 92; td2.luminance.maxValue = 255; /* set up debug output: * DEBUG_OFF, DEBUG_MOSTLY_OFF, DEBUG_SCREEN_ONLY, DEBUG_FILE_ONLY, DEBUG_SCREEN_AND_FILE */ SetDebugFlag(DEBUG_SCREEN_ONLY); /* start the CameraTask */ if (StartCameraTask(framesPerSecond, 0, k320x240, ROT_0) == -1) { DPRINTF(LOG_ERROR, "Failed to spawn camera task; exiting. Error code %s", GetVisionErrorText(GetLastVisionError())); } /* allow writing to vxWorks target */ Priv_SetWriteFileAllowed(1); /* stop the watchdog if debugging */ GetWatchdog().SetExpiration(0.5); GetWatchdog().SetEnabled(false); }
/** * Write a binary image to flash. * Writes the binary image to flash on the cRIO for later inspection. * @param fileName the name of the image file written to the flash. */ void BinaryImage::Write(const char *fileName) { RGBValue colorTable[256]; Priv_SetWriteFileAllowed(1); memset(colorTable, 0, sizeof(colorTable)); colorTable[0].R = 0; colorTable[1].R = 255; colorTable[0].G = colorTable[1].G = 0; colorTable[0].B = colorTable[1].B = 0; colorTable[0].alpha = colorTable[1].alpha = 0; imaqWriteFile(m_imaqImage, fileName, colorTable); }
TargetDetector::TargetDetector(void) { ds = DriverStation::GetInstance(); framesPerSecond = 15; // number of camera frames to get per second cameraRotation = ROT_0; // input parameter for camera orientation memset(&par,0,sizeof(par)); // initialize particle analysis report /* image data for tracking - override default parameters if needed */ /* recommend making PINK the first color because GREEN is more * subsceptible to hue variations due to lighting type so may * result in false positives */ // PINK sprintf (td1.name, "PINK"); td1.hue.minValue = 220; td1.hue.maxValue = 255; td1.saturation.minValue = 75; td1.saturation.maxValue = 255; td1.luminance.minValue = 85; td1.luminance.maxValue = 255; // GREEN sprintf (td2.name, "GREEN"); td2.hue.minValue = 55; td2.hue.maxValue = 125; td2.saturation.minValue = 58; td2.saturation.maxValue = 255; td2.luminance.minValue = 92; td2.luminance.maxValue = 255; /* set up debug output: * DEBUG_OFF, DEBUG_MOSTLY_OFF, DEBUG_SCREEN_ONLY, DEBUG_FILE_ONLY, DEBUG_SCREEN_AND_FILE */ SetDebugFlag(DEBUG_SCREEN_ONLY); /* start the CameraTask */ if (StartCameraTask(framesPerSecond, 0, k320x240, ROT_180) == -1) { DPRINTF( LOG_ERROR,"Failed to spawn camera task; exiting. Error code %s", GetVisionErrorText(GetLastVisionError()) ); } Wait(1.0); StartImageAcquisition(); /* allow writing to vxWorks target */ Priv_SetWriteFileAllowed(1); savedImageTimestamp = 0.0; }
/** * Writes an image to a file with the given filename. * Write the image to a file in the flash on the cRIO. * @param fileName The name of the file to write */ void ImageBase::Write(const char *fileName) { Priv_SetWriteFileAllowed(1); int success = imaqWriteFile(m_imaqImage, fileName, NULL); wpi_setImaqErrorWithContext(success, "Imaq Image writeFile error"); }
/** * @brief Sets the directory in which to save the logfile. * @param directory The directory to save logs in. * * @author Arthur Lockman */ void LogSystem::SetDirectory(const char* directory) { strcpy(m_logDirectory, directory); Priv_SetWriteFileAllowed(1); }