int SpeciesDataManager::readRegulators(const char* aFName) { ifstream inFile(aFName); char buffer[1024]; while(inFile.good()) { inFile.getline(buffer,1023); if(strlen(buffer)<=0) { continue; } string regulator(buffer); regulatorSet[regulator]=0; } inFile.close(); return 0; }
/* Main ----------------------------------------------------------------------*/ int main(void){ inits( ); //while(1){;;} while(1){ // Runs in 1000Hz. if(runRegulator){ runRegulator = false; regulator( ); } // Reset if line is lost. /* if(stopTimer >= 3000){ stopTimer = 0; isFindingLine = false; runState = false; drive_total_stop( ); }*/ // Runs when all ADC are read, to calculate speed. if(adcDMA){ adcDMA = false; spokesCounter( ); } // Runs when data has been received. if(handleUsart){ handleUsart = false; usartHandler( ); } // Runs when data has been requested. if(usartRequested){ usartRequested = false; sendUART( ); } } }
void EzxHardware::chargeUpdated() { int charge_raw = batteryRaw(); int charge_percent = batteryPercent(charge_raw); vsoEzxHardware.setAttribute("Battery/Raw", charge_raw); qLog(Hardware) << "Charge: raw =" << charge_raw << "; percent =" << charge_percent; bool cablePlugged = cable(); if (cablePlugged) charger.setAvailability(QPowerSource::Available); else charger.setAvailability(QPowerSource::NotAvailable); battery.setCharge(charge_percent); battery.setCharging(cablePlugged && regulator() ); vsoEzxHardware.setAttribute("Cable/Connected", cablePlugged ); btimer->start(3000); }
int main(void) { //Sväng inte turn = 0; //Initiera spi, pwm och display spi_init(); pwm_init(); init_display(); update(); claw_out(); _delay_ms(500); claw_in(); //Aktivera global interrupts sei(); //Initiera regulator clear_pid(); init_pid(80, -80); //update_k_values(40, 12, 22); update_k_values(40, 170, 20); // Pekare till aktuell position i bufferten tmp_sensor_buffer_p = 0x00; // Flagga som avgör huruvida vi är i början av meddelande sensor_start = 1; // Anger aktuell längd av meddelandet tmp_sensor_buffer_len = 0x00; //Initiera standardsträng på display init_default_printf_string(); clear_screen(); update(); while(1) { uint8_t has_comm_data, has_sensor_data, comm_data, sensor_data; do_spi(&has_comm_data, &has_sensor_data, &comm_data, &sensor_data); //Undersök och hantera meddelanden från slavarna if(has_comm_data) decode_comm(comm_data); if(has_sensor_data) decode_sensor(sensor_data); //Vid manuell sväng eller 180 grader måste make_turn anropas if(!autonomous || turning_180) { if(turn_dir) { make_turn_flag = 1; make_turn(turn_dir); if(!make_turn_flag) { turn_dir = 0; stop_motors(); } } } //Kör regulatorn if (regulator_enable) { regulator(sensor_buffer[IR_RIGHT_FRONT] - sensor_buffer[IR_RIGHT_BACK], sensor_buffer[IR_LEFT_FRONT] - sensor_buffer[IR_LEFT_BACK], sensor_buffer[IR_RIGHT_FRONT] - sensor_buffer[IR_LEFT_FRONT], sensor_buffer[IR_RIGHT_BACK] - sensor_buffer[IR_LEFT_BACK]); regulator_enable = 0; } } }
//////////////////////////////////////////////////////////////////////////////// // Program main //////////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { po::options_description desc("mephitis options"); desc.add_options() ("help", "this help") ("archive,a", po::value<std::string>(), "archive file") ("device,D", po::value<unsigned>(), "device") ("frames,f", po::value<unsigned>(), "number frames to display") ("voxelsize,s", po::value<float>(), "size of voxels (in centimeters)") ("no-processing,n", "display only, no processing") ("verbose,v", "verbose") ("debug,d", "debug") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << "\n"; exit(0); } std::string archivefile = vm.count("archive") ? vm["archive"].as<std::string>() : "ARCHIVE_NOT_SPECIFIED"; int device = vm.count("device") ? vm["device"].as<unsigned>() : 0; voxelsize = vm.count("voxelsize") ? vm["voxelsize"].as<float>() : 1.0; no_processing = vm.count("no-processing"); if (vm.count("frames")) nframes = vm["frames"].as<unsigned>(); ms::verbose = vm.count("verbose"); ms::debug = vm.count("debug"); ms::regulator<ms::coalesced_points<ms::host> > regulator(queue, 3); ms::archive_source<ms::coalesced_points<ms::host> > source(archivefile, boost::ref(regulator), 5); boost::thread popperthread(boost::bind(&ms::archive_source<ms::coalesced_points<ms::host> >::run, boost::ref(source))); std::cout << "bag popper thread running, sleeping 1 second\n"; boost::this_thread::sleep(boost::posix_time::seconds(1)); std::cout << "done sleeping\n"; // First initialize OpenGL context, so we can properly set the GL for CUDA. // This is necessary in order to achieve optimal performance with OpenGL/CUDA interop. if (CUTFalse == initGL(&argc, argv)) { return CUTFalse; } mephitis::set_device(device, true); monitor.run(5); // register callbacks glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); glutMotionFunc(motion); atexit(cleanup); // start rendering mainloop glutMainLoop(); cudaThreadExit(); cutilExit(argc, argv); }
int codingTest(){ struct timeval startTime, endTime; encoderstate* encState = encoderStateInit(); decoderstate* decState = decoderStateInit(); uint8_t inputBuffer[INPUT_LENGTH], buf1[2 * PACKETSIZE], buf2[2 * PACKETSIZE], type; int totalBytesSent = 0, totalBytesReceived = 0, totalAckSent = 0, totalAckReceived = 0, totalDataPacketReceived = 0, totalDataPacketSent = 0, nDataPacketSent = 0; int i, j, buf1Len, buf2Len; muxstate mState; mState.sport = 10; mState.dport = 10; mState.remote_ip = 10; int nRounds = CLEAR_PACKETS, sendSize; float timeElapsed; matrix* randomMatrix = getRandomMatrix(1, INPUT_LENGTH); memcpy(inputBuffer, randomMatrix->data[0], INPUT_LENGTH); mFree(randomMatrix); gettimeofday(&startTime, NULL); for(i = 0; i<nRounds; i++){ //if(regulator()){ //printf("\n~~~~Starting round %d~~~~~\n", i); //encoderStatePrint(*encState); //decoderStatePrint(*decState); //printf("~~~~~~~~~\n"); //} //sendSize = (int)(((0.8 + 0.2 *random())/RAND_MAX) * INPUT_LENGTH); sendSize = PACKETSIZE - 20; //printf("Adding %d to the encoder\n", sendSize); handleInClear(encState, inputBuffer, sendSize); totalBytesReceived += sendSize; // Send ACKs for(j = 0; j < decState->nAckToSend; j++){ bufferToMuxed(decState->ackToSend[j], buf1, decState->ackToSendSize[j], &buf1Len, mState, TYPE_ACK); muxedToBuffer(buf1, buf2, buf1Len, &buf2Len, &mState, &type); totalAckSent++; if(((1.0 * random())/RAND_MAX) > LOSS){ onAck(encState, buf2, buf2Len); //printf("Sent an ACK\n"); totalAckReceived++; } else { //printf("Lost an ACK\n"); } } // Free for(j = 0; j< decState->nAckToSend;j++){ free(decState->ackToSend[j]); } free(decState->ackToSend); decState->ackToSend = 0; free(decState->ackToSendSize); decState->ackToSendSize = 0; decState->nAckToSend = 0; // Send coded data packets from the encoder for(j = 0; j < encState->nDataToSend; j++){ bufferToMuxed(encState->dataToSend[j], buf1, encState->dataToSendSize[j], &buf1Len, mState, TYPE_DATA); muxedToBuffer(buf1, buf2, buf1Len, &buf2Len, &mState, &type); totalDataPacketSent += buf2Len; nDataPacketSent++; if(((1.0 * random())/RAND_MAX) > LOSS){ handleInCoded(decState, buf2, buf2Len); //printf("Sent a DATA packet from buf1:%d to buf2:%d\n", buf1Len, buf2Len); totalDataPacketReceived += buf2Len; } else { //printf("Lost a data packet\n"); } } // Free for(j = 0; j< encState->nDataToSend;j++){ free(encState->dataToSend[j]); } free(encState->dataToSend); encState->dataToSend=0; free(encState->dataToSendSize); encState->dataToSendSize = 0; encState->nDataToSend = 0; if(decState->nDataToSend > 0){ //printf("Sent %d decoded bytes to the application\n", decState->nDataToSend); totalBytesSent += decState->nDataToSend; free(decState->dataToSend); decState->dataToSend = 0; decState->nDataToSend = 0; } if(regulator()){ printf("\n~~~~End of round %d~~~~~\n", i); encoderStatePrint(*encState); decoderStatePrint(*decState); printf("~~~~~~~~~\n"); } //usleep(10000 + (1.0 * random() /RAND_MAX) * 1000); } gettimeofday(&endTime, NULL); timeElapsed = 1.0 * (endTime.tv_sec - startTime.tv_sec) + ((endTime.tv_usec - startTime.tv_usec) / 1000000.0); encoderStatePrint(*encState); decoderStatePrint(*decState); printf("During the %d rounds and %f s, %d bytes has been received by the encoder ; %d has been sent to the application.\n%d bytes of Data Packets has been sent, %d received.\n%d Ack has been sent, %d received.\n Simulated loss rate = %f %%. Transmission efficiency = %f %%. Transmission speed = %f MB/s. Data packet per Rounds = %f\n", nRounds, timeElapsed, totalBytesReceived, totalBytesSent, totalDataPacketSent, totalDataPacketReceived, totalAckSent, totalAckReceived, LOSS, 1.0 * totalBytesSent / totalDataPacketReceived, totalBytesSent / (1024 * 1024 * timeElapsed), 1.0 * nDataPacketSent / nRounds); encoderStateFree(encState); decoderStateFree(decState); return true; }