コード例 #1
0
ファイル: vbat_publisher.cpp プロジェクト: djtrance/ardrone
int main(int argc, char **argv)
{
  ros::init(argc, argv, "vbat_publisher");
  ros::NodeHandle n;

  vbat_struct vbat;

  if(vbat_init(&vbat)) return 1;

  ros::Publisher batter_pub = n.advertise<std_msgs::Float32>("battery_voltage", 1000);

  ros::Rate loop_rate(1.0);

  while (ros::ok())
  {
    std_msgs::Float32 msg;
  
    vbat_read(&vbat);
    msg.data=vbat.vbat;
  
    batter_pub.publish(msg);
    printf("VBAT is %f\n",vbat.vbat);


    ros::spinOnce();

    loop_rate.sleep();
  }

  return 0;
}
コード例 #2
0
ファイル: rtc32.c プロジェクト: InSoonPark/asf
/**
 * \brief Initialize the 32kHz oscillator and RTC32
 *
 * Starts up the 32kHz oscillator in the backup system and initializes the
 * RTC32.
 *
 * \note When the backup system is used, the function \ref
 * rtc_vbat_system_check should be called to determine if a re-initialization
 * must be done.
 */
void rtc_init(void)
{
	sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
	// Set up VBAT system and start oscillator
	vbat_init();

	// Disable the RTC32 module before setting it up
	RTC32.CTRL = 0;

	while (rtc_is_busy());

	// Set up maximum period and start at 0
	RTC32.PER = 0xffffffff;
	RTC32.CNT = 0;

	while (rtc_is_busy());

	RTC32.INTCTRL = 0;
	RTC32.CTRL = RTC32_ENABLE_bm;

	// Make sure it's sync'ed before return
	while (rtc_is_busy());
}
コード例 #3
0
ファイル: rtc32_example1.c プロジェクト: LaneTee/xmega-intro
int main(void)
{
	uint8_t vbat_status;

	chip_init();
	vbat_status = vbat_system_check(true);
	
	/* 
	* Depending on the VBAT system check appropriate actions need to 
	* be taken.
	* In this example we re-initialize the VBAT system in all
	* error cases.
	*/
	switch (vbat_status)
	{
	case VBAT_STATUS_OK:
		// Interrupts must be re-enabled
		RTC32_SetCompareIntLevel(RTC32_COMPINTLVL_LO_gc);
		break;
	case VBAT_STATUS_NO_POWER: // fall through
	case VBAT_STATUS_BBPOR: // fall through
	case VBAT_STATUS_BBBOD: // fall through
	case VBAT_STATUS_XOSCFAIL: // fall through
	default:
		vbat_init();
		break;
	}

	sei();
	
	while (true) {
        	RTC32_SetAlarm(2);
        	PORTA.OUTTGL = 0x02;
		SLEEP.CTRL = SLEEP_SMODE_PSAVE_gc | SLEEP_SEN_bm;
		cpu_sleep();
	}
}