Esempio n. 1
0
// @brief : If the robot is ENTERING a junction, any 7 of the 12 line sensors should
//			exceed JUNCTION_SEN_THRESHOLD. bJunctionFlag will be asserted as a result.
//			Once bJunctionFlag is asserted, wait for the robot to travel 30mm before de-
//			asserting the flag (ensuring the robot has successfully left the junction).
// @param : none
// @retval: none
void CheckForJunction(void) {
	int sensorNo, sensorCnt = 0;

	if (bRunFlag && bJunctionFlag) {
		if (!posJunction) {
			posJunction = curPos[XSPEED];

			if (bExplorationFlag) {
				RecordNewSegment(JUNCTION);
				pSegment.junctionTrack[pSegment.junctionCnt] = (int32_t)(posJunction / DIST_mm_oc(1));
				pSegment.junctionCnt++;
			}
		} else {
			if ((curPos[XSPEED] - posJunction) > JUNCTION_WAIT_DIST) {
				bJunctionFlag = FALSE;
				posJunction = 0;
				StartBeep();
			}
		}

		return;
	}

	for (sensorNo = 0; sensorNo <= NUM_LINE_SENSORS; sensorNo++) {
		if (sensor[sensorNo] > JUNCTION_SEN_THRESHOLD) {
			sensorCnt++;
		}
	}

	bJunctionFlag = (sensorCnt >= JUNCTION_NUM_SENSORS);
}
Esempio n. 2
0
/*
 ** Beeper()
 *
 *  FILENAME: beep.c
 *
 *  PARAMETERS:	BeepMsg.  Holds length of beep, [4:0] and number of
 *						  beeps, [7:5]
 *
 *  DESCRIPTION:  When BeepMsg != 0 then it splits the uint8 into the two
 *				  parameters needed and starts the beep sequence.
 *
 *  RETURNS: Nothing.
 *
 */
void 
BeeperDevice() {

    switch (BeepState) {

      case BEEP_START :
	  	if (BeepMsg != 0) {
            // Set how long beeper is on and off.
            BeepTime = (BeepMsg & 0x1F) << 2;  // times 4 for 40ms to 1.24 sec.
            // Set how many times we beep
            BeepRep = (BeepMsg & 0xE0) >> 5;
	        StartBeep();
            StartTimer( BEEP_TIMER, BeepTime );
            BeepMsg = 0;
            BeepState = BEEP_OFF;
        }
        break;

      case BEEP_OFF :
        if (TimerDone( BEEP_TIMER ) ) {
            StopBeep();
            BeepRep--;
            StartTimer( BEEP_TIMER, BeepTime );
            BeepState = BEEP_ON;
        };    
        break;

      case BEEP_ON:
        if (TimerDone( BEEP_TIMER ) ) {
            if ( BeepRep != 0 ) {
	            StartBeep();
	            StartTimer( BEEP_TIMER, BeepTime );
	            BeepState = BEEP_OFF;
            }
            else {
                BeepState = BEEP_START;  // Beeping is done.
            }
        }
        break;

      default:
		BeepState = BEEP_START;
        break;
    }
Esempio n. 3
0
void ExplorationRun(void) {
	int i;

	if (pSegment.cnt != 0) {
		switch (DispDotMatrixWait("There are recorded data. Continue?")) {
			case SW_PRESS: return;
			default: break;
		}
	}

	// clear rSegment.
	clrSegStruct = (char *) &rSegment;
	for (i = 0; i < sizeof(rSegment); i++)
		*clrSegStruct++ = 0;

	 // clear pSegment before recording data.
	clrSegStruct = (char *) &pSegment;
	for (i = 0; i < sizeof(pSegment); i++)
		*clrSegStruct++ = 0;

	StartBeep();
	DispDotMatrix("GOGO");
	DelaymSec(1500);

	StartRun();
	bExplorationFlag = TRUE;

	// constant speed & acceleration
//	SetRobotSpeedX(EXPLORATION_SPEED);
//	SetRobotAccX(ACCELERATION);

	SetMoveCommand(XSPEED, 100000, 0, EXPLORATION_SPEED, 0, ACCELERATION);

	while (1) {
		PrintRunStatus();

		// prematurely terminate the run with switch press
		if (bSWFlag) {
			bExplorationFlag = FALSE;
			bSWFlag = FALSE;

			StopRun();
			break;
		}

		if (bStopFlag) {
			rSegment.totalDisp = curPos[XSPEED] / DIST_mm_oc(1);
			StopRun();

			ProcessData();
			DispExplorationStats();
			break;
		}
	}
}
Esempio n. 4
0
void DispExplorationStats(void) {
	char str[4];
	int i;

	if (pSegment.cnt == 0) {
		DispDotMatrixWait("No data recorded");
		return;
	}

//	sprintf(str, "%04d", (int)rSegment.cnt);
//	DispDotMatrix(str);
//
//	WaitSW();
//	clrscr();
//
//	printf("RAW data. Marker count = %d\n\n", (markerCnt[LEFT_SENSOR]+markerCnt[RIGHT_SENSOR]));
//	printf("No.   State      Length     Angle \n");
//	printf("---   -----      ------     ----- \n");
//
//	for (i = 0; i < rSegment.cnt; i++)
//		printf("%-3d  %-9s  %5dmm  %5ddeg\n", i, run_state[rSegment.state[i]],
//				rSegment.length[i], rSegment.angle[i]);

	sprintf(str, "%04d", (int)pSegment.cnt);
	DispDotMatrixWait(str);
	clrscr();

	printf("PROCESSED data. Marker count = %d. Junction count= %d Total disp = %dmm. Calculated disp = %dmm. \n\n",
			(markerCnt[LEFT_SENSOR]+markerCnt[RIGHT_SENSOR]), pSegment.junctionCnt, rSegment.totalDisp, pSegment.totalDisp);
	printf("No.  State       Length     Angle    Radius    Brake    Desired    Top       End      Flag    Sync\n");
	printf("---  -----       ------     -----    ------    -----    -------    ---       ---      ----    ----\n");

	for (i = 0; i < pSegment.cnt; i++) {
		printf("%-3d  %-9s  %5dmm  %5ddeg  %6dmm   %4dmm   %4dmm/s  %4dmm/s  %4dmm/s     %d     %4d     %d\n",
				i, run_state[pSegment.state[i]], pSegment.length[i], pSegment.angle[i], pSegment.radius[i],
				pSegment.brakeDist[i], pSegment.speed[i], pSegment.topSpeed[i], pSegment.endSpeed[i],
				pSegment.bMarkerBreakFlag[i], pSegment.syncLength[i], pSegment.juncSegCnt[i]);
	}

	StartBeep();
	DispDotMatrixWait("Done");
	clrscr();
}
Esempio n. 5
0
void CheckJunctionFastRun(void) {
	int sensorNo, sensorCnt = 0, junctionCnt;
	static int junctionPassed;

	junctionCnt = (*segPtr).juncSegCnt[segmentIndex];

	if (junctionCnt) {  // > 0
		if (junctionPassed < junctionCnt) {
			if (bJunctionFlag) {
				if (!posJunction) {
					posJunction = curPos[XSPEED];
				} else {
					if ((curPos[XSPEED] - posJunction) > JUNCTION_WAIT_DIST) {
						bJunctionFlag = FALSE;
						posJunction = 0;
						StartBeep();
					}
				}

				return;
			}


			for (sensorNo = JUNCTION_SENSOR_START; sensorNo <= JUNCTION_SENSOR_END; sensorNo++) {
				if (sensor[sensorNo] > JUNCTION_SEN_THRESHOLD) {
					sensorCnt++;
				}
			}

			bJunctionFlag = (sensorCnt >= JUNCTION_NUM_SENSORS_FAST);
		}
	} else {
		bJunctionFlag = FALSE;
		junctionPassed = 0;
		posJunction = 0;
	}
}
Esempio n. 6
0
void SpeedTuning(void) {
	int i, cnt = 0;
	int16_t dist = 2500;
	int16_t variable[4][2500];

	DispDotMatrix("    ");
	DelaymSec(1500);

	StartRun();

	SetRobotSpeedX(tuneSpeed);
	SetRobotAccX(ACCELERATION);

	while (markerCnt[RIGHT_SENSOR] != 1) {
		if (bSWFlag) {
			bSWFlag = FALSE;
			StopRun();
			return;
		}
	}

	SetMoveCommand(XSPEED, dist, 0, tuneSpeed, tuneSpeed, ACCELERATION);

	while (1) {
		sprintf(s, "%04d", linePosition);
		DispDotMatrix(s);
		DelaymSec(1);  // record every 1 msec

		if (EndOfMove(XSPEED)) {
			StartBeep();
			break;
		}

		if (bStopFlag)
			break;

		if (bSWFlag) {
			bSWFlag = FALSE;
			break;
		}

		if (cnt <= 2500) {
			variable[0][cnt] = linePosition;
			variable[1][cnt] = alignmentSpeed;
			variable[2][cnt] = posErr[WSPEED];
			variable[3][cnt] = posPWM[WSPEED];
			cnt++;
		}
	}

	StartBeep();
	StopRun();

	sprintf(s, "%4d", cnt);
	DispDotMatrixWait(s);

	for (i = 0; i < cnt; i++) {
		printf("%-4d   %4d   %4d   %4d\n", variable[0][i], variable[1][i], variable[2][i], variable[3][i]);
	}

	StartBeep();
	DispDotMatrixWait("Done");
}
Esempio n. 7
0
void RecordSegment(void) {
	int i, cnt = 0;
	char s[5];

	int16_t variable[2500];
//	int16_t variable[2][2500];
//	int16_t line_position_med[500], *med_sort;
//	int a, b;

	DispDotMatrix("    ");
	DelaymSec(1500);

	StartRun();
	bRecordFlag = TRUE;
	bSwapSide = TRUE;

	SetRobotSpeedX(EXPLORATION_SPEED);
	SetRobotAccX(ACCELERATION);

	while (markerCnt[RIGHT_SENSOR] != 1) {
		if (bSWFlag) {
			bSWFlag = TRUE;
			StopRun();
			return;
		}
	}

	while (1) {
		sprintf(s, "%04d", linePosition);
		DispDotMatrix(s);
		DelaymSec(1);  // record every 1 msec

		if (cnt <= 2500) {
			variable[cnt] = linePosition;
//			variable[0][cnt] = gyroReading;
//			variable[1][cnt] = PIDFeedback[WSPEED];
			cnt++;
		}

		if (bStopFlag)
			break;

		if (bSWFlag) {
			bSWFlag = FALSE;
			break;
		}
	}

	StartBeep();
	StopRun();
	bRecordFlag = FALSE;
	bSwapSide = FALSE;

	DispDotMatrixWait("Segment recorded successfully");
	StartBeep();
	clrscr();

	sprintf(s, "%4d", cnt);
	DispDotMatrixWait(s);
	DispDotMatrix("    ");

	// insertion sort (median)
//	for (i = 0; i < cnt; i += 5) {
//		med_sort = line_position+i;
//
//		for (a = 1; a < 5; a++) {
//			while (med_sort[a] < med_sort[a-1]) {
//				b = med_sort[a];
//				med_sort[a] = med_sort[a-1];
//				med_sort[a-1] = b;
//
//				a--;
//
//				if (!a)
//					break;
//			}
//		}
//
//		line_position_med[i%5] = med_sort[2];
//	}

	for (i = 0; i < cnt; i++) {
		printf("%-4d\n", variable[i]);
//		printf("%-4d   %-3d\n", variable[0][i], variable[1][i]);
//		printf("%-3d\n", line_position_med[i]);
	}

	WaitSW();
}
Esempio n. 8
0
void FastRun(int fastType) {
	sSeg segment;
	int index, *i = &segmentIndex;
	char s[4];

	if (pSegment.cnt == 0) {
		DispDotMatrixWait("No data recorded");
		return;
	}

	StartBeep();
	DispDotMatrix("GOGO");
	DelaymSec(1500);

	bFastFlag = TRUE;
	ComputeSpeed(fastType);

	segment = pSegment;
	segPtr = &segment;
	segmentIndex = 0;

	StartRun();

//	SetRobotSpeedX(segment.topSpeed[*i]);
//	SetRobotAccX(ACCELERATION);

	SetMoveCommand(XSPEED, 1000, 0, segment.topSpeed[*i], segment.topSpeed[*i], ACCELERATION);

	while (markerCnt[RIGHT_SENSOR] != 1) {
		if (bSWFlag) {
			bSWFlag = FALSE;
			StopRun();
			return;
		}
	}

	StartRunTimer();

	for (; *i < segment.cnt; (*i)++) {
		sprintf(s, "%4d", *i);
		DispDotMatrix(s);

		WaitSyncFastRun();

		if (MoveRobotFastRun(XSPEED, segment.length[*i], segment.brakeDist[*i], segment.topSpeed[*i],
				segment.endSpeed[*i], ACCELERATION))
			break;  // switch break

//		if (segment.bSyncFlag[*i]) {
//			*i = markerCnt[LEFT_SENSOR] - 1;
//		}

		segment.curDisp += segment.length[*i];

		if (bStopFlag) {
			(*i)++;
			break;
		}

//		StartBeep();
	}

	StopRunTimer();
	StopRun();

	align_Kp = 4;
	align_Kd = 40;

	sprintf(s, "%04d", runTime);
//	DispDotMatrixWait(s);
	WaitSW();
	clrscr();

	printf("segment cnt: %d   i: %d\n", segment.cnt, *i);
	printf("No.   State         Top        Min        Max       Dist     Length    Actual   Break    Marker\n");
	printf("---   -----         ---        ---        ---       ----     ------    ------   -----    ------\n");
	for (index = 0; index < *i; index++) {
		printf("%3d   %-9s   %4dmm/s   %4dmm/s   %4dmm/s   %4dmm   %4dmm    %4dmm      %d        %d\n", index, run_state[segment.state[index]],
				segment.topSpeed[index], segment.actMinSpeed[index], segment.actMaxSpeed[index], segment.dist[index], segment.length[index],
				segment.actDisp[index], segment.bActBreakFlag[index], segment.bMarkerBreakFlag[index]);
	}
	DispDotMatrixWait("Done");
}