*ロボットの仕組み [#kebd7403]
 
*プログラム [#s9a60325]
 #define short_break Off(OUT_ABC);Wait(5000);
 sub find_can()
 { 
	int rantime=7000; //1週するのにかかる時間
	int lightmin=100; //仮の距離
	int timemin=0; //仮の時間
	int turn_time=rantime-timemin; //発見した缶の方を向くのにかかる時間
	SetSensorLowspeed(S1);
        long t0 = CurrentTick();
	while(CurrentTick()-t0<rantime)
	{
		OnFwd(OUT_B,30);
		OnFwd(OUT_C,-30); //左旋回
		if(SensorUS(S1)<lightmin) //1メートル以内に缶があったら時間を 記憶し一番近いものとする
		{
			lightmin=SensorUS(S1);
			timemin=CurrentTick();
		}
	}
	short_break;
	OnFwd(OUT_B,-30);
	OnFwd(OUT_C,30); //右旋回
	Wait(turn_time); //缶のところまで戻る
	short_break;	
	ResetSensor(S1);		
 } 
 sub approach_can() //缶との距離を30センチにする
 {
	SetSensorLowspeed(S1);
        if(SensorUS(S1)>30)				
	{
		OnFwd(OUT_BC,30);
		until(SensorUS(S1)==30); //30センチより離れていたら前進する
	}
	if(SensorUS(S1)<30)
	{
		OnFwd(OUT_BC,-30);
		until(SensorUS(S1)==30); //30センチより近かったら後退する
	}
 } 
 task main()
 {
	find_can();
	approach_can();
	short_break;
	OnFwd(OUT_A,30); //アームを降ろしてボールを転がす
	Wait(500);
 }

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS