Пример #1
0
void ASimModeWorldBase::BeginPlay()
{
    Super::BeginPlay();

    setupClock();

    manual_pose_controller = NewObject<UManualPoseController>();
    setupInputBindings();

    //call virtual method in derived class
    createVehicles(vehicles_);

    physics_world_.reset(new msr::airlib::PhysicsWorld(
        createPhysicsEngine(), toUpdatableObjects(vehicles_), 
        getPhysicsLoopPeriod()));

    if (usage_scenario == kUsageScenarioComputerVision) {
        if (default_vehicle_config != "SimpleFlight")
            UAirBlueprintLib::LogMessageString("settings.json is not using simple_flight in ComputerVision mode."
                "This can lead to unpredictable behaviour!",  
                "", LogDebugLevel::Failure);


        manual_pose_controller->initializeForPlay();
        manual_pose_controller->setActor(getFpvVehiclePawnWrapper()->getPawn());
    }
}
Пример #2
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  const uint32_t maxPeriod =
      captureUnitConfig.frequency / pwmUnitConfig.frequency + 1;
  const uint32_t minPeriod =
      captureUnitConfig.frequency / pwmUnitConfig.frequency - 1;

  setupClock();

  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct GpTimerPwmUnit * const pwmUnit = init(GpTimerPwmUnit,
      &pwmUnitConfig);
  assert(pwmUnit);

  struct Pwm * const pwm = gpTimerPwmCreate(pwmUnit, OUTPUT_PIN);
  assert(pwm);
  pwmSetEdges(pwm, 0, pwmGetResolution(pwm) / 2);

  struct GpTimerCaptureUnit * const captureUnit = init(GpTimerCaptureUnit,
      &captureUnitConfig);
  assert(pwmUnit);

  struct Capture * const capture = gpTimerCaptureCreate(captureUnit, INPUT_PIN,
      PIN_RISING, PIN_PULLDOWN);
  assert(capture);

  uint32_t previousTime = 0;
  bool event = false;

  captureSetCallback(capture, onCaptureEvent, &event);
  captureEnable(capture);
  pwmEnable(pwm);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    const uint32_t currentTime = captureGetValue(capture);
    const uint32_t period = currentTime - previousTime;

    if (period >= minPeriod && period <= maxPeriod)
      pinReset(led);
    else
      pinSet(led);

    previousTime = currentTime;
  }

  return 0;
}
Пример #3
0
void Clock::readDateTime(DateTime& result)
{
    setupClock();
    wire.requestFrom(CLOCK_ADDR, 0x07);

    result.seconds = fromBcd(wire.read() & SECONDS_REGISTER_MASK);
    result.minutes = fromBcd(wire.read());
    result.hours = fromBcd(wire.read());
    result.wday = wire.read();
    result.day = fromBcd(wire.read());
    result.month = fromBcd(wire.read());
    result.year = fromBcd(wire.read()) + 2000;
}
Пример #4
0
void main(void)
{
  volatile unsigned int i;
 
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
  setupClock();

  PMAPPWD = 0x02D52;                        // Get write-access to port mapping regs  
  P2MAP6 = PM_UCB0SDA;                      // Map UCB0SDA output to P2.6 
  P2MAP7 = PM_UCB0SCL;                      // Map UCB0SCL output to P2.7 
  PMAPPWD = 0;                              // Lock port mapping registers 


  P2SEL |= BIT6 + BIT7;                     // Select P2.6 & P2.7 to I2C function
  #ifdef INTERNAL_PULLUP
  //DIR = 0 REN = 1: pullup/down enabled. OUT=1: up OUT=0: down
  P2DIR &= ~(BIT6 + BIT7);
  P2OUT |= (BIT6 + BIT7);
  P2REN |= (BIT6 + BIT7);
  #endif
    
  UCB0CTL1 |= UCSWRST;                      // Enable SW reset
  UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;     // I2C Master, synchronous mode
  UCB0CTL1 = UCSSEL_2 + UCSWRST;            // Use SMCLK, keep SW reset
  UCB0BR0 = I2C_DIV & 0xff;                             
  UCB0BR1 = I2C_DIV >> 8;
  UCB0I2CSA = 0x48;                         // Slave Address is 048h
  UCB0CTL1 &= ~UCSWRST;                     // Clear SW reset, resume operation
  UCB0IE |= UCTXIE;                         // Enable TX interrupt
//  UCB0IE |= UCNACKIE;                       // Enable NACK interrupt

  TXData = 0x01;                            // Holds TX data
  i = 50000;  //delay (for when slave powered on at the same time as master
  do (i--);
  while (i!= 0);

  while (1)
  {
    TXByteCtr = 1;                          // Load TX byte counter

    while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
    UCB0CTL1 |= UCTR + UCTXSTT;             // I2C TX, start condition
   
    __bis_SR_register(LPM0_bits + GIE);     // Enter LPM0 w/ interrupts
    __no_operation();                       // Remain in LPM0 until all data
                                            // is TX'd
                                              
    TXData++;                               // Increment data byte
  }
}
Пример #5
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  setupClock();

  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, false);

  struct Interface * const adc = init(AdcDma, &adcConfig);
  assert(adc);
  ifSetCallback(adc, onConversionCompleted, adc);

  struct Timer * const conversionTimer = init(GpTimer, &timerConfig);
  assert(conversionTimer);
  /*
   * The overflow frequency of the timer should be two times higher
   * than that of the hardware events for ADC.
   */
  timerSetOverflow(conversionTimer, timerConfig.frequency / (ADC_RATE * 2));

  unsigned int iteration = 0;
  size_t count;

  /* Enqueue buffers */
  while (ifGetParam(adc, IF_AVAILABLE, &count) == E_OK && count > 0)
  {
    const size_t index = iteration++ % BUFFER_COUNT;
    ifRead(adc, buffers[index], sizeof(buffers[index]));
  }

  /* Start conversion */
  timerEnable(conversionTimer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    pinSet(led);
    while (ifGetParam(adc, IF_AVAILABLE, &count) == E_OK && count > 0)
    {
      const size_t index = iteration++ % BUFFER_COUNT;
      ifRead(adc, buffers[index], sizeof(buffers[index]));
    }
    pinReset(led);
  }

  return 0;
}
Пример #6
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  setupClock();

  const struct Pin led = pinInit(LED_PIN);
  pinOutput(led, true);

  struct GpTimerPwmUnit * const pwmUnit = init(GpTimerPwmUnit, &pwmUnitConfig);
  assert(pwmUnit);
  struct Pwm * const pwmOutput = gpTimerPwmCreate(pwmUnit, OUTPUT_PIN);
  assert(pwmOutput);
  pwmSetDuration(pwmOutput, pwmGetResolution(pwmOutput) / 2);

  struct Timer * const counter = init(GpTimerCounter, &counterConfig);
  assert(counter);

  struct Timer * const timer = init(GpTimer, &timerConfig);
  assert(timer);
  timerSetOverflow(timer, 1000);

  bool event = false;
  timerSetCallback(timer, onTimerOverflow, &event);

  timerEnable(counter);
  pwmEnable(pwmOutput);
  timerEnable(timer);

  while (1)
  {
    while (!event)
      barrier();
    event = false;

    const uint32_t period = timerGetValue(counter);
    timerSetValue(counter, 0);

    if (period >= 999 && period <= 1001)
      pinReset(led);
    else
      pinSet(led);
  }

  return 0;
}
Пример #7
0
/**
 * @brief	Main entry point
 * @return	Nothing
 */
int main(void) {
	SystemCoreClockUpdate();
	Board_Init();
	setupClock();
	SystemCoreClockUpdate();

	On = true;
	enableOut = false;
	controlFlag = false;

	Board_LED_Set(0, On);
	DEBUGOUT("Starting\n");
	/* Initialize RITimer */
	Chip_RIT_Init(LPC_RITIMER);

	LPC_IOCON->PINSEL[4] |= 0x00000555; //Change this after you know which pwm outputs are needed.
	LPC_IOCON->PINMODE[3] |= (3 << 6);
	LPC_IOCON->PINMODE[3] |= (3 << 12);

	LPC_IOCON->PINSEL[1] |= (1 << 14);
	LPC_IOCON->PINSEL[1] |= (1 << 16);
	LPC_IOCON->PINSEL[1] |= (1 << 18);
	LPC_IOCON->PINSEL[1] |= (1 << 20);
	LPC_IOCON->PINMODE[1] |= (2 << 14);
	LPC_IOCON->PINMODE[1] |= (2 << 16);
	LPC_IOCON->PINMODE[1] |= (2 << 18);
	LPC_IOCON->PINMODE[1] |= (2 << 20);

	LPC_SYSCTL->PCLKSEL[0] |= (1 << 12); //PCLK_PWM1 = CCLK
	LPC_IOCON->PINMODE[4] |= (3 << 26);
	LPC_SYSCTL->PCONP |= (1 << 17); //Enable clock
	LPC_SYSCTL->PCLKSEL[1] |= (1 << 30); //PCLKMPWM = CCLK
	LPC_SYSCTL->PCLKSEL[0] |= (1 << 24);

	Chip_PWM_Init(LPC_PWM1);
	LPC_PWM1->PR = 0;
	Chip_PWM_SetMatch(LPC_PWM1, 0, 3000);
	Chip_PWM_SetMatch(LPC_PWM1, 1, 1500);
	Chip_PWM_SetMatch(LPC_PWM1, 2, 1500);
	Chip_PWM_SetMatch(LPC_PWM1, 3, 1500);

	Chip_PWM_ResetOnMatchEnable(LPC_PWM1, 0);
	Chip_PWM_SetCountClockSrc(LPC_PWM1, PWM_CAPSRC_RISING_PCLK, 0);
	Chip_PWM_SetControlMode(LPC_PWM1, 0, PWM_SINGLE_EDGE_CONTROL_MODE, PWM_OUT_ENABLED);
	Chip_PWM_SetControlMode(LPC_PWM1, 1, PWM_SINGLE_EDGE_CONTROL_MODE, PWM_OUT_ENABLED);
	Chip_PWM_SetControlMode(LPC_PWM1, 2, PWM_SINGLE_EDGE_CONTROL_MODE, PWM_OUT_ENABLED);

	Chip_PWM_LatchEnable(LPC_PWM1, 0, PWM_OUT_ENABLED);
	Chip_PWM_LatchEnable(LPC_PWM1, 1, PWM_OUT_ENABLED);
	Chip_PWM_LatchEnable(LPC_PWM1, 2, PWM_OUT_ENABLED);
	Chip_PWM_LatchEnable(LPC_PWM1, 3, PWM_OUT_ENABLED);

	Chip_PWM_Enable(LPC_PWM1);
	Chip_PWM_Reset(LPC_PWM1);

	Chip_GPIO_Init(LPC_GPIO);

	LPC_MCPWM->CON_SET |= (1 <<3);
	DCACSetFreq(1074);
	LPC_MCPWM->DT = 12;
	LPC_MCPWM->INTEN_SET |= 1;
	LPC_MCPWM->INTF_SET |= 1;
	LPC_MCPWM->CON_SET |= 1;
	freq = 1074;
	NVIC_EnableIRQ(RITIMER_IRQn);

	Chip_ADC_Init(LPC_ADC, &ADCSetup);
	Chip_ADC_SetBurstCmd(LPC_ADC, DISABLE);

	/* Configure RIT for a 1s interrupt tick rate */
	Chip_RIT_SetTimerInterval(LPC_RITIMER, TIME_INTERVAL);


	/* LED is toggled in interrupt handler */
	vout = 0;
	voutOldest = 0;
	voutOld = 0;
	while (1) {
		if(controlFlag) {
			bool emergency = !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency |= !Chip_GPIO_GetPinState(LPC_GPIO,2,13);
			emergency = !emergency;
			if(emergency) {
				enableOut = false;
				vout = 0;
			} else {
			#ifdef enableLoad
				enableOut = Chip_GPIO_GetPinState(LPC_GPIO,0,28);
			#else
				enableOut = true;
			#endif
			}
			Board_LED_Set(0, enableOut);
			DCDCControl();
			DCACControl();
			Vmeasure += readADC(VIN_PIN);
			Imeasure += readADC(CURRENT_PIN);
			times++;
			if(times >= delayFactor && enableOut) {
				DEBUGOUT("%d %d %d %d\n",readADC(VIN_PIN), readADC(VOUT_PIN), readADC(CURRENT_PIN), vout);
				times = 0;
				cycles++;
				if(cycles < ncycles) {
					#ifdef enableMPPT
						MPPT(Vmeasure/delayFactor, Imeasure/delayFactor);
					#endif
					Vmeasure = 0;
					Imeasure = 0;
				} else {
					cycles = 0;
				}
			}
			if(enablePrev != enableOut) {
				DEBUGOUT("TOGGLING %d\n",enableOut);
			}
			enablePrev = enableOut;
			controlFlag = false;
			if(emergency) return 0;
		}
	}
}
Пример #8
0
void Clock::init()
{
    setupClock();
}