Exemplo n.º 1
0
// update table Head !!
void HeadedTable::setSortedCol(int col)
{
    {
        int old_sorted = sorted_col;
        sorted_col = col;
        //		printf("old_sorted=%d\n",old_sorted);
        //		printf("sorted_col=%d\n",sorted_col);
        if (old_sorted != -1 && old_sorted < ncols) // ncols bug
            updateHeading(old_sorted);
        if (col != -1 && col < ncols)
            updateHeading(col);
    }
}
Exemplo n.º 2
0
// repaint cells that have been changed from previous generation
void Pstable::repaint_changed()
{
    int rows = procview->procs.size();
    int cols = procview->cats.size();
    int left = leftCell(), right = lastColVisible();
    int top = topCell(), bottom = lastRowVisible();
    if(right >= cols) right = cols - 1;
    if(bottom >= rows) bottom = rows - 1;
    int far_right = right;
    if(leftmostchanged != -1 && right >= leftmostchanged)
	right = leftmostchanged - 1;
    for(int c = right + 1; c <= far_right; c++)
	updateHeading(c);
    for(int r = top; r <= bottom; r++) {
	for(int c = left; c <= right; c++) {
	    Category *cat = procview->cats[c];
	    Procinfo *p = procview->procs[r], *op = 0;
	    if(r >= procview->old_procs.size()
	       || (op = procview->old_procs[r], cat->compare(p, op) != 0)
	       || p->selected != op->selected) {
		updateCell(r, c);
	    }
	}
	// update all cells that have moved or changed width
	for(int c = right + 1; c <= far_right; c++)
	    updateCell(r, c);
    }
    if(leftmostchanged != -1)
	clearRight();
}
Exemplo n.º 3
0
task gyroTask() {
	initGyro();
	while(true) {
		updateHeading();
		angle2 = angle;
	}
}
Exemplo n.º 4
0
void MSTableColumn::heading(const MSStringVector& heading_) 
{ 
  if (heading()!=heading_)
   {
     _heading=heading_;
     updateHeading(); 
   }
}
Exemplo n.º 5
0
void MSTableColumn::headingFont(Font fid_) 
{ 
  if (headingFont()!=fid_)
   {
     _headingFont=fid_;
     updateHeading();
   }
}
Exemplo n.º 6
0
QmvItem * QmvList::itemCopy()
{
    if ( !editor->shuttleClass())
        return(0);
    
    QmvItem *ci;
    if (currentItem())
        ci = (QmvItem *)currentItem();
    else
        ci = 0;
    
    QmvItem *item = 0;
    QmvClass *cls = editor->shuttleClass();
    QString key  = cls->userKey();
    QmvTuple * oldtuple = ci->shuttleTuple();
        
        // Add tuples in current set to the list,
        // using primary key and descriptive label

    int newrow = cls->newTuple();
    if (newrow < 0)
        return(0);
    QmvTuple * newtuple = cls->tupleAt(newrow);
    
        // Close the current item to reduce confusion
    if (ci && ci->isOpen())
        ci->setOpen(FALSE);

        // Copy the editable attributes from the tuple of the current item
    QmvAttList atlist = cls->edit_attlist();
    for (QmvAttribute * at_ptr = atlist.first(); at_ptr != 0; at_ptr = atlist.next())
        newtuple->update( *at_ptr->find("mtat_name"),
                          oldtuple->attributeValue(*at_ptr->find("mtat_name")));

        // Create a new item with the newtuple.
    item = new QmvItem(this, ci, newtuple, newtuple->userkeyValue());
    
    item->setText( 0, newtuple->userkeyValue());
    item->setText( 1, newtuple->userlabelValue());
    item->setOpen(TRUE);
    updateHeading();
    
    return(item);
}
Exemplo n.º 7
0
bool QmvList::itemRemove()
{
    if ( !currentItem() || !editor->shuttleClass())
        return(FALSE);

    QmvItem *ci = (QmvItem *)currentItem();
    if (ci->shuttletupleAttribute())
    {
        QMessageBox::warning( this, "Tuple:Remove",
                                  tr("You cannot remove a row attribute, only whole rows.\n\n %1 : %2")
                                  .arg(ci->text(0))
                                  .arg(ci->text(1)),
                                  "OK", 0);
        return(FALSE);
    }
    
    
    QmvClass * cls = ci->shuttleClass();
    QmvTuple * tp = ci->shuttleTuple();
    
    
    switch( QMessageBox::information( this, "Tuple:Remove",
				      tr("Are you sure that you want to delete this item? \n\n %1 : %2")
                                      .arg(ci->shuttleTuple()->userkeyValue())
                                      .arg(ci->shuttleTuple()->userlabelValue()),
				      "Yes", "Cancel",
				      0, 1 ) )
    {
        case 0:
                // Closing will remove the children.
            ci->setOpen(FALSE);
            delete ci;
            cls->remove(tp, TRUE);
            updateHeading();
            break;
        case 1:
        default: // just for sanity
                //ce->ignore();
            break;
    }
}
Exemplo n.º 8
0
// repaint cells that have been changed due to configuration change
void Pstable::repaint_statically_changed(int update_col)
{
    int rows = procview->procs.size();
    int cols = procview->cats.size();
    int right = lastColVisible(), left = right + 1;
    int top = topCell(), bottom = lastRowVisible();
    if(leftmostchanged == -1 || leftmostchanged > update_col)
	leftmostchanged = update_col;
    if(leftmostchanged != -1)
	left = leftmostchanged;
    if(right >= cols) right = cols - 1;
    if(bottom >= rows) bottom = rows - 1;
    for(int c = left; c <= right; c++)
	updateHeading(c);
    for(int r = top; r <= bottom; r++) {
	for(int c = left; c <= right; c++)
	    updateCell(r, c);
    }
    if(leftmostchanged != -1)
	clearRight();
}
Exemplo n.º 9
0
QmvItem * QmvList::itemInsert()
{
    if ( !editor->shuttleClass())
        return(0);
    
    QmvItem *ci;
    if (currentItem())
        ci = (QmvItem *)currentItem();
    else
        ci = 0;
    
    QmvItem *item = 0;
    QmvClass *cls = editor->shuttleClass();
    QString key  = cls->userKey();
        
        // Add tuples in current set to the list,
        // using primary key and descriptive label

    int newrow = cls->newTuple();
    if (newrow < 0)
        return(0);
    QmvTuple * newtuple = cls->tupleAt(newrow);
    QString tmp = cls->relationTitle();
        // Close the current item to reduce confusion
    if (ci && ci->isOpen())
        ci->setOpen(FALSE);
    
    item = new QmvItem(this, ci, newtuple, newtuple->userkeyValue());
    
    item->setText( 0, newtuple->userkeyValue());
    item->setText( 1, newtuple->userlabelValue());
    item->setOpen(TRUE);
    updateHeading();

    return(item);
}
Exemplo n.º 10
0
int main ( void )
{

    //TRISA = 0b0010000000000000;
    TRISA = 0b00001111;
    TRISAbits.TRISA12 = 0;
    
    TRISCbits.TRISC1 = 0;
    TRISCbits.TRISC2 = 0;
    TRISCbits.TRISC3 = 0;
    TRISCbits.TRISC4 = 0;
    
    //TRISD = 0;
    TRISD = 0b0000000000010000; // RD11: DIR2; RD8: PWM2
    
    //TRISE = 0b00001000;
    TRISE = 0b00001000; // RE6: DIR1; RE0: PWM1
    TRISEbits.TRISE7 = 0; 
   
    //LCD an
    _PCFG16 = 1; // AN16 is digital
    _PCFG17 = 1; // AN17 is digital
    _PCFG18 = 1; // AN18 is digital
    _PCFG19 = 1; // AN19 is digital
    _PCFG20 =1;
    _PCFG31=1;
    
    //pwm analog select
    _PCFG24=1;
    _PCFG30=1;
    
    //RE4 for lcd r/s
     _PCFG28=1;
     TRISEbits.TRISE4 = 0;
    
    AD1PCFGHbits.PCFG28 = 1;
    AD1PCFGHbits.PCFG27 = 1;
    AD1PCFGHbits.PCFG30 = 1;
    AD1PCFGHbits.PCFG24 = 1;
    AD1PCFGH = 0x0020;
    TRISAbits.TRISA13 = 1;
    //set pwm low
    PWM1=0;
    PWM2=0;
    
    SYS_Initialize ( ) ;
    
    CLKDIVbits.FRCDIV = 0;
    CLKDIVbits.PLLPOST = 0;  // N2 = 2
    CLKDIVbits.PLLPRE = 0;  // N1 = 2
    PLLFBD = (Fosc*N1_default*N2_default/Ffrc) - M_default; // M = 8 -> Fosc = 7.3728 MHz * 8 / 2 / 2 = 16 MHz
    while(!OSCCONbits.LOCK);	// Wait for PLL to lock
	RCONbits.SWDTEN = 0;      // Disable Watch Dog Timer
    
    //TRISF = 0;
    gpsLock = 0;
   
    lcd_init();
    print_lcd("Initializing");
    //delay_ms(500);
    //lcd_clear();
    
    /*lcd test
    char line1[] = " On Route ";
    char line2[] = " Arrived ";
    //send_command_byte(0xFF);
    //while(1){send_command_byte(0xFF);send_data_byte(0);}
   // delay_ms(2);
    //send_command_byte(0x02); // Go to start of line 1
    //send_command_byte(0b00001111); // Display: display on, cursor on, blink on
    //send_command_byte(0b00000110); // Set entry mode: ID=1, S=0
    //send_command_byte(0b00000001); // Clear display
    
    print_lcd(line1);
    delay_ms(5000);
    lcd_clear();
    print_lcd(line2);
    //send_command_byte(0xC0); // Go to start of line 1
    //while(1){send_command_byte(0b00000001);}
    while(1);*/
    
    /*int a;
    long long int ct;
    int i;
    int j=0;*/
    //i2c init

    
    //uart init
    UART_Initialize();
    delayMs(100);
    
    
    /* while(1){//test for delay ms configuration
        //PORTDbits.RD1 = 1;
        //delayUs(10);
        //for(i = 0;i <7;i++);
        delayMs(10);
        PORTDbits.RD12 = 1;
        //for (i = 0; i < 1000; i++);
        //PORTDbits.RD1 = 0;
        //for(i = 0;i <7;i++);
        delayMs(10);
        
        PORTDbits.RD12 = 0;
        //for (i  = 0; i < 1000; i++);
    }*/
    
    //ultrasonic test
    
   /* while(1){
        long double x;
        delayMs(500);
        PORTEbits.RE4 = 1;                  //TRIGGER HIGH
        PORTDbits.RD5 = 1; 
        delay_us(10);                     //10uS Delay 
        lcd_clear();
        ultraSonicEn = 1;
        ultraSonicCount = 0;

        PORTEbits.RE4 = 0;                  //TRIGGER LOW
        PORTDbits.RD5 = 0; 
        
        
        while (!PORTDbits.RD4);              //Waiting for Echo
       IEC0bits.T2IE = 1; //enable timer
        while(PORTDbits.RD4);// 
        IEC0bits.T2IE = 0; //disable timer
        x = ultraSonicCount/TICKS_PER_METER;
        sprintf(outputBuf,"%lf",x); 
        print_lcd(outputBuf);
    }*/

    //TX_str(endGPS);
    //delayMs(3000);
    //TX_str(startGPS);
    /*TX_str(startGPShot);
    delayMs(2000);
    while ( !gpsLock ) {
        TX_str(getGPS);
        delayMs(500);
    }*/
    
   //TCP code
    
    TX_str(openNet);
    delayMs(5000);
    TX_str(openConnection);
    delayMs(5000);
 
    // while(!BUTTON_IsPressed ( BUTTON_S3 ));
    //TX_str(sprintf("%s%d\r",sendTCP, strlen("10")));
    sprintf(outputBuf2,"2\n%lf,%lf\n\r",roverLog,roverLat );
    sprintf(cmdBuf,"%s%d\r", sendTCP,strlen(outputBuf2));
         
    TX_str(cmdBuf);
    delayMs(3000);
    TX_str(outputBuf2);
    while(!waypointsReady || !gpsLock);
    
    
    //while(1);
    delayMs(7000);
    lcd_clear();
    print_lcd("waypoints locked");
    
    i2c_init();
    //i2c_write3(0x3c, 0x00, 0x70);
    i2c_write3(0x3c, 0x00, 0b00011000);
    //i2c_write3(0x3c, 0x01, 0b11000000);
    i2c_write3(0x3c, 0x01, 0xA0);
    i2c_write3(0x3c, 0x02, 0x00);
    
    //timer init, do this after other initializations
    motorDuty=0;
    tim1_init();
    tim2_init();
   
    /*
    double angleTolerance = 8.0;
     motorDuty=2;
 
    while (1){ //adjust


        double angleDiff = headingDiff(0,roverHeading );


        if (angleDiff > 0 ||abs(angleDiff) > 175 ){ //turn left

            PWM1_DIR = 0; //left            NOTE: 0 is forward, 1 is reverse
            PWM2_DIR = 1; //right
        } else{ // turn right

            PWM1_DIR = 1;
            PWM2_DIR = 0;
        }
        if (abs(angleDiff) < angleTolerance){
            motorDuty = 0;
            //break;
        }else{
            //motorDuty =4;
            motorDuty =2;
        }   
        delayMs(13);
        updateHeading();
    }*/
    
    //hardcoded gps for tcpip test
    
    
     /*while(1){
//        PORTDbits.RD5 = 1;
//        for (a = 0; a < (100/33); a++) {}
//        PORTDbits.RD5 = 0;
//        for (a = 0; a < (100/33); a++) {}
        ct = 0;
        //TMR2 = 0;//Timer Starts
        delayMs(60);
        PORTEbits.RE4 = 1;                  //TRIGGER HIGH
        PORTDbits.RD5 = 1; 
        delay_us(15);
                           //10uS Delay 
        PORTEbits.RE4 = 0;                  //TRIGGER LOW
        PORTDbits.RD5 = 0; 
        while (!PORTDbits.RD4){              //Waiting for Echo
            ct++;
        }
            //T2CONbits.TON = 1;
        while(PORTDbits.RD4) {
            ct++;
        }// {
        //T2CONbits.TON = 0;
        sprintf(outputBuf,"%lld", ct); 
        //a = TMR2;
        //a = a / 58.82;
        
        //long int p;
        //for(p = 0; p <100000; p++);
        
    }*/
    //tim1_init();
    //while ( 1 );
    //UART_Initialize();
    
    /* Infinite Loop */
    /*
     long int i;
    while ( 1 )
    {//test for delay ms configuration
        //PORTDbits.RD1 = 1;
        delayMs(10);
        PORTDbits.RD12 = 1;
        //for (i = 0; i < 1000; i++);
        //PORTDbits.RD1 = 0;
        delayMs(10);
        PORTDbits.RD12 = 0;
        //for (i = 0; i < 1000; i++);
    }*/
    //IEC0bits.T1IE = 0;
    
    //IEC0bits.T1IE = 1;
    //motorDuty =2;
    motorStopFlag = 0; //ready to go
    char tempBuf1[50];
    int wapointsVisited;
    double desiredHeading = 0;
    double dToWaypoint = 99999.9;
    double angleTolerance = 6.0;
    for (wapointsVisited =0; wapointsVisited<numGPSpoints;wapointsVisited++ )
    {
        dToWaypoint = 99999.9;
        while (1)
        {

            int f;
            roverLog = 0;
            roverLat = 0;
            for(f = 0; f < ROVER_LEN; f++){
                roverLog+=roverlog[f]/ROVER_LEN_D;
                roverLat+=roverlat[f]/ROVER_LEN_D;
            }
            
            
            dToWaypoint = dist(convertGPSToDeg(roverLat),convertGPSToDeg(roverLog),convertGPSToDeg(gpsLat[wapointsVisited]),convertGPSToDeg(gpsLonge[wapointsVisited]));
            if(dToWaypoint <= 3.0){break;} //go to next waypoint

            desiredHeading = 330.0;
            desiredHeading = bearing(convertGPSToDeg(roverLat),convertGPSToDeg(roverLog),convertGPSToDeg(gpsLat[wapointsVisited]),convertGPSToDeg(gpsLonge[wapointsVisited]));
            
            updateHeading();
            
                
            if (!(abs(headingDiff(desiredHeading,roverHeading )) < angleTolerance))
            {
                motorDuty = 0;  //stop
                delayMs(300);
                while (1) //ADJUSTMENT LOOP
                {
                   
                    double angleDiff = headingDiff(desiredHeading,roverHeading );

                    //double dist = ultraSonicPing();
                    /*sprintf(tempBuf1,"%f",dist);
                    lcd_clear();
                    print_lcd(tempBuf1);*/
                     if (abs(angleDiff) < angleTolerance){
                        motorDuty = 0;
                        /*sprintf(tempBuf1,"%f",roverHeading);
                        IEC0bits.T1IE = 0;
                        print_lcd(tempBuf1);
                        IEC0bits.T1IE = 1;*/
                        break;
                    }
                    if (angleDiff > 0 || abs(angleDiff) > 175 ){ //turn right
                        /*PORTDbits.RD4 = 1; //right 0 is forwards, 1 i backwards
                        PORTDbits.RD2 = 1;
                        PORTDbits.RD8 = 0; //left*/
                        PWM1_DIR = 0; //left            NOTE: 0 is forward, 1 is reverse
                        PWM2_DIR = 1; //right
                    } else{ // turn left
                        /*PORTDbits.RD4 = 0; //right 0 is forwards, 1 i backwards
                        PORTDbits.RD2 = 0;
                        PORTDbits.RD8 = 1; //left*/
                        PWM1_DIR = 1;
                        PWM2_DIR = 0;
                    }
                   
                       
                    motorDuty =3;
                     
                    delayMs(15);
                    updateHeading();
        //        sprintf(tempBuf1,"%f",roverHeading);
        //        IEC0bits.T1IE = 0;
        //        lcd_clear();
        //        print_lcd(tempBuf1);
        //        IEC0bits.T1IE = 1;
                //delayMs(1000);
                //for(p = 0; p <100000; p++);
                }
            }
            PWM1_DIR = 0; //left            NOTE: 0 is forward, 1 is reverse
            PWM2_DIR = 0;

            motorDuty = 5;
            ultraSonicDelayEnable = 1;
            //frequency is around 20kHz
            while (ultraSonicDelayCount < 60000){ //for 4 seconds poll ultrasonic and check for obsticles
                long double x;
                //PORTEbits.RE4 = 1;                  //TRIGGER HIGH
                PORTDbits.RD5 = 1; 
                delay_us(10);                     //10uS Delay 
                lcd_clear();
                ultraSonicEn = 1;
                ultraSonicCount = 0;

                //PORTEbits.RE4 = 0;                  //TRIGGER LOW
                PORTDbits.RD5 = 0; 


                while (!PORTDbits.RD4);              //Waiting for Echo
               IEC0bits.T2IE = 1; //enable timer
                while(PORTDbits.RD4);// 
                IEC0bits.T2IE = 0; //disable timer
                ultraSonicEn = 0;
                x = ultraSonicCount/TICKS_PER_METER;
                if (x <= 1.4){
                    motorDuty = 0;
                }else{
                    motorDuty = 5;
                }
                delayMs(200);
            }
            ultraSonicDelayEnable = 0;
            ultraSonicDelayCount = 0;
        }
        
        motorDuty = 0;
        delayMs(1000);
        //IEC0bits.T1IE = 0;
        lcd_clear();
        char buf3[40];
        sprintf(buf3, "reached %d", wapointsVisited);
        print_lcd(buf3);
        delayMs(3000);
        //IEC0bits.T1IE = 1;
        
    }
    //IEC0bits.T1IE = 0;
    lcd_clear();
    print_lcd("ARRIVED!!!");
    //IEC0bits.T1IE = 1;
    while (1);
}
Exemplo n.º 11
0
Arquivo: Compas.c Projeto: sdajani/sdp
/**
 * Function: runMasterSM
 * @return None.
 * @remark Executes one cycle of the command center's state machine.
 * @author David Goodman
 * @date 2013.03.09  */
void runMasterSM() {
    //Magnetometer_runSM();
    // Record these button presses since we don't know
    //  if they will be pressed after runSM
    lockPressed = isLockPressed();
    zeroPressed = isZeroPressed();
    if(lockPressed || zeroPressed){
        #ifdef USE_ENCODERS
        Encoder_runSM();
        #endif

        if(lockPressed) {
            printf("Lock was pressed.\n");
            #ifdef USE_NAVIGATION
            #ifdef USE_ENCODERS
            Encoder_enableZeroAngle();
            Encoder_runSM();
            Coordinate ned; // = Coordinate_new(ned, 0, 0 ,0);
            if (Navigation_getProjectedCoordinate(&ned, Encoder_getYaw(),
                Encoder_getPitch(), height)) {
                printf("Desired coordinate -- N: %.6f, E: %.6f, D: %.2f (m)\n",
                    ned.x, ned.y, ned.z);


                #ifdef USE_XBEE
                Mavlink_send_start_rescue(XBEE_UART_ID, TRUE, 0,ned.x, ned.y);
                #endif
            }
            else {
                printf("Failed to obtain desired NED coordinate.\n");
            }
            Encoder_disableZeroAngle();
            #else
            printf("Navigation module is disabled.\n");
            #endif
            #endif

        }
        else if (zeroPressed) {
            // Zero was pressed
            #ifdef USE_ENCODERS
            Encoder_setZeroAngle();
            #endif
            useLevel = TRUE;
            #ifdef  USE_MAGNETOMETER
            Magnetometer_runSM();
            heading = Magnetometer_getDegree();
            updateHeading();
            #endif
            //printf("Zeroing...\n");
        }
        else {

        }
    }
    if (!zeroPressed) {
        if (useLevel)
            printf("Done zeroing.\n");
        
        useLevel = FALSE;
    }

    #ifdef USE_ACCELEROMETER
    Accelerometer_runSM();
    updateAccelerometerLEDs();
    #endif

    #ifdef USE_NAVIGATION
    Navigation_runSM();
    #endif

    #ifdef USE_XBEE
    Xbee_runSM();
    #endif

}
Exemplo n.º 12
0
void Player::update(){
	
	updateHeading();
	goodMind->update(goal);	
	//badMind->update(bad);
}