当前位置: 首页>>代码示例>>C++>>正文


C++ USART类代码示例

本文整理汇总了C++中USART的典型用法代码示例。如果您正苦于以下问题:C++ USART类的具体用法?C++ USART怎么用?C++ USART使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了USART类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GetStateOrder

//监听一个端口,返回一个命令
u8 Transmission::GetStateOrder(USART &ListeningCOM)
{
		u8 comand[8]={0};
		u8 ch=0;
		u8 num = ListeningCOM.ReceiveBufferSize();
		if(num>7)   //一帧命令包含8个字节
		{
				ListeningCOM.GetReceivedData(&ch,1);
			if(ch == 0xFF)
			{
				ListeningCOM.GetReceivedData(&ch,1);
				if(ch == 0xDD)
				{
					while(ListeningCOM.ReceiveBufferSize()<6);//等待数据
					comand[0]=0xff;
					comand[1]=0xDD;
					ListeningCOM.GetReceivedData(comand+2,6);
					ListeningCOM.ClearReceiveBuffer();
					return CommandParsing(comand);  //解包
				}
				else return 0;
			}
			else
				return 0;
		}
		else 
			return 0;
}
开发者ID:lissettecarlr,项目名称:HCHO_module,代码行数:29,代码来源:transmission.cpp

示例2: GetWifiNameAndPassword

bool Transmission::GetWifiNameAndPassword(char *name,char *password,USART &ListeningCOM)
{
	u8 ch=0;
	u8 i =0;
	ListeningCOM.GetReceivedData(&ch,1);
		if(ch == 0xFF)
		{
			tskmgr.DelayMs(100);
			ListeningCOM.GetReceivedData(&ch,1);
			if(ch == 0x03)
			{
				ListeningCOM.GetReceivedData(&ch,1);
				while(ch!=0xff){
					*(name+i)=ch;
					i++;
					ListeningCOM.GetReceivedData(&ch,1);
				}
					*(name+i)='\0';
					ListeningCOM.GetReceivedData(&ch,1);
					i=0;
				while(ch!=0xff){
					*(password+i)=ch;
					i++;
					ListeningCOM.GetReceivedData(&ch,1);
				}
					*(password+i)='\0';	
				return 1;
			}
			else return 0;
		}
		else
			return 0;
}
开发者ID:lissettecarlr,项目名称:HCHO_module,代码行数:33,代码来源:transmission.cpp

示例3: Run

    void Run(uint32_t i2cClockSpeed)
    {
        bool dmpReady = false; // set true if DMP init was successful
        uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
        uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
        uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
        uint16_t fifoCount; // count of all bytes currently in FIFO
        uint8_t fifoBuffer[64]; // FIFO storage buffer

        Quaternion q; // [w, x, y, z] quaternion container
        VectorInt16 aa; // [x, y, z] accel sensor measurements
        VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements
        VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements
        VectorFloat gravity; // [x, y, z] gravity vector
        float eu[3]; // [psi, theta, phi] Euler angle container
        float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
        uint16_t y, p, r;
        float yaw_offset;

        I2C1* i2c = GPIO_Helper::SetupI2C1_PB_6_9(i2cClockSpeed);
        i2c->SetErrorHandler(this);
        MPU6050 mpu(i2c);

        //Initialized with highest sensitivities
        mpu.reset();
        RCC_Delay_ms(50);
        mpu.initialize();

#ifdef USE_USART
        uint32_t clockSpeed = 1200000;
        USART* usart = GPIO_Helper::SetupUSART2_PA_2_3(clockSpeed);
#endif        

        devStatus = mpu.dmpInitialize();

        if (devStatus != 0)
        {
            while (1)
                ;
        }

        mpu.setDMPEnabled(true);
        packetSize = mpu.dmpGetFIFOPacketSize();

        while (1)
        {
            // wait for MPU interrupt or extra packet(s) available
            //while (!mpuInterrupt && fifoCount < packetSize) {
            //}

            // reset interrupt flag and get INT_STATUS byte
            mpuIntStatus = mpu.getIntStatus();
            // get current FIFO count
            fifoCount = mpu.getFIFOCount();
            // check for overflow (this should never happen unless our code is too inefficient)
            if (mpuIntStatus & 0x02)
            {
                // wait for correct available data length, should be a VERY short wait
                while (fifoCount < packetSize)
                    fifoCount = mpu.getFIFOCount();
                // read a packet from FIFO
                mpu.getFIFOBytes(fifoBuffer, packetSize);
                // track FIFO count here in case there is > 1 packet available
                // (this lets us immediately read more without waiting for an interrupt)
                fifoCount -= packetSize;

                // display quaternion values in easy matrix form: w x y z
                mpu.dmpGetQuaternion(&q, fifoBuffer);

                mpu.dmpGetEuler(eu, &q);
                eu[0] *= 180. / M_PI;
                eu[1] *= 180. / M_PI;
                eu[2] *= 180. / M_PI;
                mpu.dmpGetGravity(&gravity, &q);

                mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);

                //rad to degrees
                ypr[0] *= 180. / M_PI;
                ypr[1] *= 180. / M_PI;
                ypr[2] *= 180. / M_PI;

                // display real acceleration, adjusted to remove gravity
                mpu.dmpGetAccel(&aa, fifoBuffer);
                mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);

                // display initial world-frame acceleration, adjusted to remove gravity
                // and rotated based on known orientation from quaternion
                mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);

#ifdef USE_USART
                if (usart->IsRXNE())
                {
                    if (usart->Receive() == 23)
                    {
                        usart->SendWord((int16_t)(ypr[0]));
                        usart->SendWord((int16_t) ypr[1]);
                        usart->SendWord((int16_t) ypr[2]);
                    }
                }
//.........这里部分代码省略.........
开发者ID:nihuyaka,项目名称:libarmpit-cortex,代码行数:101,代码来源:main.cpp

示例4: spiMaster

		void spiMaster() {
			// TXEPT is 1 after reset
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0TCTL(), 1));

			m->setByte(v->getP1SEL(), 0x31);
			m->setByte(v->getU0CTL(), 0); // UCSWRST
			// UCTL0 = CHAR + SYNC + MM + SWRST;
			m->setByte(v->getU0CTL(), 23);
			// UTCTL0 = SSEL1 + SSEL0 + STC;
			m->setByte(v->getU0TCTL(), 51);
			m->setByte(v->getUC0IE(), 255);
 			// ME1 |= USPIE0;                            // Enable USART0 SPI mode
 			// UCTL0 &= ~SWRST;                          // Initialize USART state machine
			m->setByte(v->getU0ME(), 255);
			m->setByte(v->getU0CTL(), 22);
			// Set BR
			m->setByte(v->getU0BR0(), 2);

			// nothing should happen until we send character
			CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
			usart->tickRising(); usart->tickFalling();
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);
			// No transmission, TXEPT is 1
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0TCTL(), 1));

			// Set TX IFG just to test it gets cleared by write to TXBUF later
			m->setBit(v->getU0IFG(), 128, true);
			CPPUNIT_ASSERT_EQUAL(true, m->isBitSet(v->getU0IFG(), 128));

			// start transmitting - we will transfer 8 bits
			m->setByte(v->getU0TXBUF(), 55); // 00110111
			CPPUNIT_ASSERT_EQUAL(-1.0, watcher->sclk);

			// Write to TXBUF should clear TX IFG
			CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getU0IFG(), 128));
			// We are transmitting now, so TXEPT should be 0
			CPPUNIT_ASSERT_EQUAL(false, m->isBitSet(v->getU0TCTL(), 1));

			// Disable SWRST
			m->setBit(v->getU0CTL(), 1, false);

		/// BIT 1
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);

			// prepare '1' to be captured
			pinManager->handlePinInput(0, 3.0);

			//  bit captured from SOMI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 2
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 3
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 3.0);

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 4
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sdo);

			// prepare '0' to be captured
			pinManager->handlePinInput(0, 0.0);

			// cnt--, bit captured from SDI
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sclk);

		/// BIT 5
			// First (MSB) bit should be sent and rising clock generated
			usart->tickRising(); usart->tickFalling();
			CPPUNIT_ASSERT_EQUAL(3.0, watcher->sclk);
			CPPUNIT_ASSERT_EQUAL(0.0, watcher->sdo);

//.........这里部分代码省略.........
开发者ID:cybercircuits,项目名称:qsimkit,代码行数:101,代码来源:USART.cpp

示例5:

bool MHZ14::Updata()
{	
	//向模块发送获取数据
	   CO2.SendData(Command_getvalue,9);
	
	//判断是否有数据返回
	  if(CO2.ReceiveBufferSize()<9)
	  {
		  CO2.ClearReceiveBuffer(); //清空接收缓存
		  return false;
	  }
	  else
	  {
		  CO2.GetReceivedData(rev_buffer,9); //取出一帧数据
		   CO2.ClearReceiveBuffer(); //清空接收缓存
		  
		  if(SumCheck(rev_buffer)==false)  //校验和
			  return false;
		  else
		  {
			  DATA_H=rev_buffer[2];
			  DATA_L=rev_buffer[3];
			  CO2_Concentration=rev_buffer[2]*256+rev_buffer[3];  //计算浓度
			  return true;
		  }
	  }
}
开发者ID:lissettecarlr,项目名称:RFID-_MAIN,代码行数:27,代码来源:MHZ14.cpp

示例6: main

int main(int argc, char **argv) {	
	while (true) {
		out.print("Enter some text: ");
		char buf[20];
		out.getline(buf, sizeof(buf));
		out.printf("You typed: %s\n", buf);
		Task::sleep(1000);
	}
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:9,代码来源:usarttest.cpp

示例7: docalibrate

static void docalibrate(const char *type, PID::Config *conf) {
	out.printf("Old %s: %f %f %f\n", type, conf->p, conf->i, conf->d);
	out.printf("New %s PID values:\n", type);
	
	static char buf[100];
	out.getline(buf, sizeof(buf));
	
	sscanf(buf, "%f %f %f", &conf->p, &conf->i, &conf->d);
	out.printf("Got: %f %f %f\n", conf->p, conf->i, conf->d);
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:10,代码来源:motorscontroltest.cpp

示例8: AppInit

void AppInit(void) {
	TouchPanelTask.Run();
	GUITask.Run();
	BlinkTask.Run();
	
	printf("Gib was ein:\r\n");
	Serial.ReadLn(buf, 10);
	printf("Du hast eingegeben: %s", buf);
}	
开发者ID:bonzehan,项目名称:stm32-projects,代码行数:9,代码来源:tasks.cpp

示例9: main

/* ----------------------------------------------------------------------------
 * メイン処理
 * ---------------------------------------------------------------------------- */
int main(void)
{
	setup();
	while(1)
	{
		loop();
		Serial1.getrxd();
	}
}
开发者ID:ngc6589,项目名称:IN-12bNixieClock,代码行数:12,代码来源:IN-12bNixieClock.cpp

示例10: main

int main(int argc, char **argv) {	
	out.print("Begin log test!\n");
	
	const uint8_t writedata[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
	unsigned int i;
	for (i=0;i<20;i++)
		logger.write(writedata, sizeof(writedata));
		
	logger.flush();
	out.print("Done!\n");
	
	uint8_t data[128];
	eeprom.read(EEPROM::pageAddress(0), data, sizeof(data));
	out.printf("EEPROM page 0:\n", data);
	for (i=0; i<sizeof(data); i++) {
		out.printf("%u ", (unsigned int)data[i]);
	}
	out.print("\n");
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:19,代码来源:loggertest.cpp

示例11: main

int main(int argc, char **argv) {
	bool prevsynced=true;
		
	while (true) {
		Task::sleep(5);
		
		if (vex.getSynced()) {
			VexRC::Channels chans = vex.getChannels();
		
			out.printf("%d %d %d %d ", chans.analogs[0], chans.analogs[1], chans.analogs[2], chans.analogs[3]);
			out.printf("%s %s\n", digitalToString(chans.left), digitalToString(chans.right));
			prevsynced = true;
		} else {
			if (prevsynced) {
				buzzer.buzz(100);
				out.print("Not synced\n");
			}
			prevsynced = false;
		}
	}
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:21,代码来源:vexrctest.cpp

示例12: main

int main(void)
{
  char buffer[15];
  setup();
  
  
  
  for(;;){
     ADCSRA |= 1 << ADSC;
     loop_until_bit_is_clear(ADCSRA, ADSC);
     adch = ADC;
     
     //uart.printstr(str);
     itoa(adch, buffer, 10);
     uart.printstr( (const char *)buffer );
     uart.printstr( "\n" );
     _delay_ms(100);
  }

  return 0;
}
开发者ID:dnivanthaka,项目名称:avr-demos,代码行数:21,代码来源:main.cpp

示例13: loop

/* ----------------------------------------------------------------------------
 * メインループ
 * ---------------------------------------------------------------------------- */
void loop() {
	int i;
	int j;
	
	// 1秒毎の処理
	if(interruptCount > 999) {
		// 時計モード
		if(userDataTimerCount == 0) {
			rtc.get();
			// 年月日表示か時刻表示かの判定
			if(displayDateIntervalCount <= displayDateIntervalValue) {
				// 時分秒表示
				// カンマをクリア
				for(int i = 0; i < 8; i++) {
					IN12Com[i] = 0;
				}
				// 6桁フォーマット 999999
				if(dispTimeFormat == 0) {
					IN12Num[0] = 0x0F;
					if(hour12_24format == 1) {
						IN12Num[1] = rtc.hourHigh;
						IN12Num[2] = rtc.hourLow;
					} else {
						IN12Num[1] = rtc.hourHigh12;
						IN12Num[2] = rtc.hourLow12;
					}
					IN12Num[3] = rtc.minutesHigh;
					IN12Num[4] = rtc.minutesLow;
					IN12Num[5] = rtc.secondsHigh;
					IN12Num[6] = rtc.secondsLow;
					IN12Num[7] = 0x0F;
				}
				// 8桁フォーマット 99, 99, 99
				if(dispTimeFormat == 1) {
					if(hour12_24format == 1) {
						IN12Num[0] = rtc.hourHigh;
						IN12Num[1] = rtc.hourLow;
					} else {
						IN12Num[0] = rtc.hourHigh12;
						IN12Num[1] = rtc.hourLow12;
					}
					IN12Num[2] = 0x0F;
					IN12Num[3] = rtc.minutesHigh;
					IN12Num[4] = rtc.minutesLow;
					IN12Num[5] = 0x0F;
					IN12Num[6] = rtc.secondsHigh;
					IN12Num[7] = rtc.secondsLow;
					IN12Com[2] = 1;
					IN12Com[5] = 1;
				}
			} else {
				// 年月日表示
				// カンマクリア
				for(int i = 0; i < 8; i++) {
					IN12Com[i] = 0;
				}
				IN12Num[0] = 2;
				IN12Num[1] = 0;
				IN12Num[2] = rtc.yearHigh;
				IN12Num[3] = rtc.yearLow;
				IN12Num[4] = rtc.monthHigh;
				IN12Num[5] = rtc.monthLow;
				IN12Num[6] = rtc.dayHigh;
				IN12Num[7] = rtc.dayLow;
				if(displayDateIntervalCount >= ( displayDateIntervalValue + displayDateSecondsValue)) {
					displayDateIntervalCount = 0;
				}
			}
			displayDateIntervalCount++;
		}
		// ユーザーデータ表示中
		if(userDataTimerCount > 0) {
			userDataTimerCount--;
		}
		// LED 点滅
		if(led == false) {
			led = true;
			PORTC |= (1<<LED);
		} else {
			led = false;
			PORTC &= ~(1<<LED);
		}
		interruptCount = 0;
	}
	
	// シリアル1 受信処理
	while(Serial1.available()) {
		char ch = Serial1.getch();
		serial0String[serial0StringIdx] = ch;
		Serial1.putch(ch);
		if(serial0String[serial0StringIdx] == '\r') {
			Serial1.putch('\n');
			serial0String[serial0StringIdx] = 0;
			serial0StringComplete = true;
		}
		serial0StringIdx++;
		if(serial0StringIdx >= SERIALBUF_LEN) {
//.........这里部分代码省略.........
开发者ID:ngc6589,项目名称:IN-12bNixieClock,代码行数:101,代码来源:IN-12bNixieClock.cpp

示例14: main

int main()
{
	u8 command[6];
	u8 datatemp[18];//数据暂存
	u8 tagInfo[18];
	u8 sensor[16];//保存传感器型号
	u8 basic_information[6];//基础信息
	u8 version[16];//版本
	
	tskmgr.DelayMs(1000);
	tskmgr.DelayMs(1000);
	
	
	//设置模式
	//设置名字密码
	//设置IP地址
	//复位
	WIFI.SendData(CLOSS,6);  //关闭回显
	tskmgr.DelayMs(1000);
	WIFI.SendData(Command1,13);  //开启多路连接
	tskmgr.DelayMs(1000);
	WIFI.SendData(Command2,21); //开启服务器模式
	tskmgr.DelayMs(1000);
	
	
	  equipment[0]=2;//测试用 将设备二加入
//	  DATA_COM.SendData(c,8);  //连续发送命令
	
	
    while(1)
	{
	  //接收从模块数据
	 if(DATA_COM.ReceiveBufferSize()>=40) //如果接收到了一帧数据
	 {
		 u32 check=10,moduleNo;
		 u8 sum=0;
		 u8 FFAA=0;
		 DATA_COM.GetReceivedData(&FFAA,1); //找包头
		 if(FFAA==0xff)
		{
		  DATA_COM.GetReceivedData(&FFAA,1); //找包头
		  if(FFAA==0xcc)
		{
		 DATA_COM.GetReceivedData(datatemp,18);
		 moduleNo=datatemp[0]+datatemp[1]+datatemp[2]+datatemp[3];
		 for(u8 i=0;i<10;i++) //查询是否有这个设备
		  {
			if(moduleNo==equipment[i])
				check=0;//有这个设备
		  }
		  for(u8 i=0;i<16;i++)
		  {
			sum+=datatemp[i];  //j校验和
		  }
		  sum=sum+0XCB;  //加上包头
		  if(sum==datatemp[17])
			  check=check+1;
		  
		  //使用WIFI发送数据给上位机
		  if(check==1)
		  {
		    WIFI.SendData(Command3,17);
	        tskmgr.DelayMs(100);
			WIFI.ClearSendBuffer();
			WIFI.SendData(packgroup.MAINToUser(datatemp[5],datatemp[6],datatemp[7],moduleNo,datatemp[4]),20);
			tskmgr.DelayMs(100); 
			  
			WIFI.ClearReceiveBuffer();//清除接收缓存
			WIFI.ClearSendBuffer();  //清除发送缓存
		  }
	  }
	  }
	 }
	
//从上位机得到命令()
		if(WIFI.ReceiveBufferSize()>40)
		{
			u8 ch=0;
			u8 temp_cmd;
			 u32 temp;
			//test
		
			while(WIFI.ReceiveBufferSize()>8)
			{
				WIFI.GetReceivedData(&ch,1);
				if(ch==0xff)//判断包头
				{
					WIFI.GetReceivedData(&ch,1);
					if(ch==0xdd)//判断包头
					{
					  //得到指令
					   WIFI.GetReceivedData(command,6);
					   WIFI.ClearReceiveBuffer();
						
					   temp_cmd=command[4];  //得到命令位				
					   temp=command[0]+command[1]+command[2]+command[3];//得到设备号
						//命令处理
						if(temp_cmd==0XAA)//如果命令是注册
						{
							//读取RFID 将结果给上位机*********************************************
//.........这里部分代码省略.........
开发者ID:lissettecarlr,项目名称:RFID-_MAIN,代码行数:101,代码来源:main.cpp

示例15: main

int main(int argc, char **argv) {
	imu.start();

	out.printf("Battery: %f cell\n", batmon.getCellVoltage());
	out.print("Waiting for remote signal\n");
	while (!vex.getSynced()) { Task::sleep(100); }

	out.print("Arming\n");
	motors.arm();

	float heading = imu.getYaw();
	buzzer.buzz(300);

	while (true) {
		control.start();
		Logger logger(eeprom, 0);
		bool logging = false;
		
		while (true) {
			bool up = false;
			if (!vex.getSynced()) {
				control.stop();
				motors.off();
				while (!vex.getSynced()) { Task::sleep(100); }
				control.start();
				sensors.centerGyros();
				heading = imu.getYaw();
				buzzer.buzz(300);
			}
		
			VexRC::Channels chans = vex.getChannels();
	
			if (chans.right != VexRC::NONE)
				break;
			if (chans.left == VexRC::UP)
				logging = true;
			else if (chans.left == VexRC::DOWN)
				logging = false;
	
			float throttle = chans.analogs[1] / 50.0;
			if (throttle < 0)
				throttle = 0;
			float rollsetpoint = (-chans.analogs[3] / 50.0) * 0.3;
			float pitchsetpoint = (-chans.analogs[2] / 50.0) * 0.3;
			heading += (chans.analogs[0] / 50.0) * (M_PI / 4) * .005;
			
			control.setControlPoints(throttle, rollsetpoint, pitchsetpoint, heading);
			if (!up) {
				if (throttle > 0.4)
					up = true;
				else
					control.clearIntegrals();
			}
			
			if (logging) {
				LogEntry entry = { sensors.getReadings(), imu.getState(), throttle };
				logger.write((uint8_t *)&entry, sizeof(entry));
			}
			
			IMU::State state = imu.getState();
			IMU::State velstate = imu.getVelocityState();
			out.printf("%f %f\n", control.getRollCorrection(), control.getPitchCorrection());
			Task::sleep(25);
		}
		
		control.stop();
		motors.off();
		out.print("Push enter\n");
		while (out.getch() != '\r') { }
		
		out.print("Press y to dump log");
		if (out.getch() == 'y') {
			out.print("\nLog dump:");
			LogReader reader(eeprom, 0);
			struct LogEntry entry;
			while (reader.read((uint8_t *)&entry, sizeof(entry)) == sizeof(entry)) {
				int i;
				for (i=0;i<6;i++) {
					out.printf("%.3f ", entry.analogs.array[i]);
				}
				out.printf("%.3f %.3f %.3f ", entry.state.roll, entry.state.pitch, entry.state.yaw);
				out.printf("%.3f\n", entry.throttle);
			}
		}
		docalibrate("Roll", &controlconfig.roll_config);
		docalibrate("Pitch", &controlconfig.pitch_config);
		docalibrate("Yaw", &controlconfig.yaw_config);
		
		out.printf("Current stick values: %f %f\n", controlconfig.rollpitch_stickfactor, controlconfig.yaw_stickfactor);
		out.printf("Stick: ");
		static char buf[50];
		out.getline(buf, sizeof(buf));
		sscanf(buf, "%f %f", &controlconfig.rollpitch_stickfactor, &controlconfig.yaw_stickfactor);
	}
}
开发者ID:matthewbot,项目名称:Quadcopter,代码行数:95,代码来源:motorscontroltest.cpp


注:本文中的USART类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。