Exemplo n.º 1
0
PWM& PWM::operator=(bool state)
{
	if(state)
		setDutyCycle(1.0);
	else
		setDutyCycle(0.0);
	return *this;
}
Exemplo n.º 2
0
//translate omega1,2,3,4 to pwm1,2,3,4 and actuate motors accordingly
unsigned int controlled_speed(void)
{
    unsigned int t1;
    unsigned int t2;
    unsigned int t3;
    unsigned int t4;
    if (controller_param->FCS == FCS_MOTOR_TEST) {
        setDutyCycle(test_speed[0], 1);
        setDutyCycle(test_speed[1], 2);
        setDutyCycle(test_speed[2], 3);
        setDutyCycle(test_speed[3], 4);
    } else {
        //actuate the motors
        if (motor_on) {
            t1 = normalize_speed(ctrl_data->omega1square);
            t2 = normalize_speed(ctrl_data->omega2square);
            t3 = normalize_speed(ctrl_data->omega3square);
            t4 = normalize_speed(ctrl_data->omega4square);
            //setDutyCycle(ZERO_SPEED_THROTTLE+normalize_speed(ctrl_data->omega1square), 1);
            //setDutyCycle(ZERO_SPEED_THROTTLE+normalize_speed(ctrl_data->omega2square), 2);
            //setDutyCycle(ZERO_SPEED_THROTTLE+normalize_speed(ctrl_data->omega3square), 3);
            //setDutyCycle(ZERO_SPEED_THROTTLE+normalize_speed(ctrl_data->omega4square), 4);
            if (speed_report_count == SPEED_REPORT_RATE) {
                printf("T1: %u, T2: %u, T3: %u, T4: %u.\n\r", t1, t2, t3, t4);
                 //print the motor speeds
                printf("M1: ");
                printFloat(ctrl_data->omega1square);
                printf(", M2: ");
                printFloat(ctrl_data->omega2square);
                printf(", M3: ");
                printFloat(ctrl_data->omega3square);
                printf(", M4: ");
                printFloat(ctrl_data->omega4square);
                printf(".\n\r");
               
                printf("e_roll: ");
                printFloat(kinetic_errs->roll_error);
                printf("e_pitch: ");
                printFloat(kinetic_errs->pitch_error);
                printf(", e_yaw: ");
                printFloat(kinetic_errs->yaw_error);
                printf(", e_alt: ");
                printFloat(kinetic_errs->altitude_error);
                printf(".\n\r");
                printf(".\n\r");

                speed_report_count = 0;
            } else {
                speed_report_count++;
            }

        } else {
            // gives zero throttle to all
            setDutyCycle(6, 0);
        }
    }
}
Exemplo n.º 3
0
void start_scheduler(void) {
    setDutyCycle (50, 50);      // dutyCycle = 50%, frequency = 50Hz
    while (1) {
//  OpenEPWM1(0xff);
//  SetDCEPWM1(0);
//  SetOutputEPWM1(FULL_OUT_FWD, PWM_MODE_1);
//  CloseEPWM1();
        
        //timer interrupt
        if (sampling_flag == 1) {
            timer_rst();
            if (curr_channel < high) {
                PORTBbits.RB0 = 1;
                PORTBbits.RB1 = 1;
                PORTBbits.RB2 = 0;
                PORTBbits.RB3 = 0;
            } else if (curr_channel >= high){
                PORTBbits.RB0 = 0;
                PORTBbits.RB1 = 0;
                PORTBbits.RB2 = 1;
                PORTBbits.RB3 = 1;
            } else if (curr_channel == totalTicks){
                update_status(SYSTEM_UART);
                done = uart_task();
            }
            //update status if a task terminate
        } else {
            if ((check_status() == SYSTEM_UART) && done && TXSTAbits.TRMT) {
               update_status(SYSTEM_IDLE);
               done = 0;
            }
        }
    }
}
Exemplo n.º 4
0
void motors_init(void)
{
    // enable timer0,1,3,5 for motor control
    T0CONbits.T08BIT = 0;   // set timer0 in 16-bit mode
    T0CONbits.T0CS = 0;     // set timer0 clk source as instruction cycle
    T0CONbits.PSA  = 0;     // enable timer0 pre-scale
    T0CONbits.T0SE = 0;     // increment on low to high transition
    T0CONbits.T0PS = 0b001; // choose a pre-scale of 4
    // turn on Timer0
    T0CONbits.TMR0ON = 0;

    // enable timer1
    T1CONbits.TMR1CS = 0b00; // CLK src FOSC/4
    T1CONbits.T1CKPS = MOTOR_TIMER_PRESCALE;
    T1CONbits.T1SOSCEN = 0; // disable secondary osc
    T1CONbits.T1RD16 = 1;   // sing 16-bit-read/write operation enable
    T1CONbits.TMR1ON = 0;   // enable tmr1

    // enable timer3
    T3CONbits.TMR3CS = 0b00; // CLK src FOSC/4
    T3CONbits.T3CKPS = MOTOR_TIMER_PRESCALE;
    T3CONbits.T3SOSCEN = 0; // disable secondary osc
    T3CONbits.T3RD16 = 1;   // sing 16-bit-read/write operation enable
    T3CONbits.TMR3ON = 0;   // enable tmr3

    // enable timer5
    T5CONbits.TMR5CS = 0b00; // CLK src FOSC/4
    T5CONbits.T5CKPS = MOTOR_TIMER_PRESCALE;
    T5CONbits.T5SOSCEN = 0; // disable secondary osc
    T5CONbits.T5RD16 = 1;   // sing 16-bit-read/write operation enable
    T5CONbits.TMR5ON = 1;   // enable tmr5

    motor_on = 0;
    setDutyCycle (6, 1);      // dutyCycle = 10%, frequency = 50Hz
    setDutyCycle (6, 2);      // dutyCycle = 10%, frequency = 50Hz
    setDutyCycle (6, 3);      // dutyCycle = 10%, frequency = 50Hz
    setDutyCycle (6, 4);      // dutyCycle = 10%, frequency = 50Hz

    PORTBbits.RB0 = 1;
    PORTBbits.RB1 = 1;
    PORTBbits.RB2 = 1;
    PORTBbits.RB3 = 1;
    speed_report_count = 1;
}
Exemplo n.º 5
0
PIRInfraredLED::PIRInfraredLED(
  unsigned int frequency,
  unsigned int dutyCycle)
  : fileDescriptor(-1),
    index(0)
{
  openLircDevice();
  setCarrierFrequency(frequency);
  setDutyCycle(dutyCycle);
}
Exemplo n.º 6
0
float WCMA::do_all_the_magic()
{
	if ( current_slice == static_cast<unsigned int>( adaptive_slices - 1 ) )
	{
		calculateAdaptiveSlices();
		setDutyCycle();
		current_slice = 0;

		return energy_current_slot;
	}
	else
	{
		DriverInterface::debug.printLine( "current_slice: ", false );
		DriverInterface::debug.printFloat( current_slice, 3, true );

		++current_slice;
		setDutyCycle();

		return Algorithms::getLuminance();
	}
}
Exemplo n.º 7
0
ProtonProtocol::ProtonProtocol(
  QObject *guiObject,
  unsigned int index)
  : SpaceProtocol(
      guiObject, index,
      500, 500,
      500, 1500,
      8000, 4000,
      500,
      63000, true)
{
  setDutyCycle(50);
}
Exemplo n.º 8
0
//Function to control DOF1
void control_dof1(unsigned int setpoint_dof1)
{
	position_dof1 = ADC0Read(1);
	if(setpoint_dof1 > position_dof1)
	{
		IOCLR0 = (1<<19);
		IOSET0 = (1<<18);
		//setDutyCycle(2,(setpoint_dof1 - position_dof1)*100/1024);
	}
	if(position_dof1 > setpoint_dof1)
	{
		IOCLR0 = (1<<18);
		IOSET0 = (1<<19);
		//setDutyCycle(2,(position_dof1 - setpoint_dof1)*100/1024);
	}
	setDutyCycle(2,85);
	//iprintf("Position: %d     Setpoint: %d\r\n",position_dof1, setpoint_dof1);
}
Exemplo n.º 9
0
void BitHistory::write(BitHistoryProto::Builder& proto) const
{
    proto.setId(id_.c_str());

    auto statsList = proto.initStats(stats_.size());
    UInt i = 0;
    for (const auto & elem : stats_)
    {
        auto stat = statsList[i];
        stat.setIndex(elem.first);
        stat.setDutyCycle(elem.second);
        i++;
    }

    proto.setLastTotalUpdate(lastTotalUpdate_);
    proto.setLearnIteration(learnIteration_);
    proto.setAlpha(alpha_);
    proto.setVerbosity(verbosity_);
}
Exemplo n.º 10
0
void PWM::off()
{
	setDutyCycle(0.0);
}
Exemplo n.º 11
0
void PWM::on()
{
	setDutyCycle(1.0);
}