- 追加された行はこの色です。
- 削除された行はこの色です。
[[2006a/C3]]
#define blackline 40
int frag;
sub linetrace (){
if ((SENSOR_1 <= blackline) && (SENSOR_3 <= blackline)){
OnFwd(OUT_A + OUT_C);
Wait(030);
frag++;
}
else{
if ((SENSOR_1 <= blackline) && (SENSOR_3 >= blackline)) {
OnFwd (OUT_A);OnRev (OUT_C);
}
if ((SENSOR_1 >= blackline) && (SENSOR_3 <= blackline)) {
OnFwd (OUT_C);OnRev (OUT_A);
}
if ((SENSOR_1 >= blackline) && (SENSOR_3 >= blackline)){
OnFwd (OUT_A + OUT_C);
}
}
}
sub hold_can (){
Wait(500);
OnFwd(OUT_B);Wait(200);
OnRev(OUT_A+OUT_C);Wait(200);
OnRev(OUT_A+OUT_C);
if((SENSOR_1<40)&&(SENSOR_3<40)){
Off(OUT_A+OUT_C);
}
}
sub port_can (){
OnFwd(OUT_A+OUT_C);Wait(30);
OnRev(OUT_B);
Wait (200);
Off (OUT_B);
OnFwd(OUT_A+OUT_C);
Wait(20);
OnRev(OUT_A+OUT_C);
Wait(250);
}
sub go_straight (){
OnFwd (OUT_A+OUT_C);
}
sub go_down (){
OnRev (OUT_A+OUT_C);
}
sub turn_R (){
Off (OUT_A + OUT_C);OnRev (OUT_A+OUT_C);Wait (007);OnFwd (OUT_A);Wait (130);Off (OUT_A+OUT_C);
}
sub turn_L (){
Off (OUT_A + OUT_C);OnRev (OUT_C+OUT_A);Wait (007);OnFwd (OUT_C);Wait (130);Off (OUT_A+OUT_C);
}
task main(){
SetSensor (SENSOR_1, SENSOR_LIGHT);
SetSensor (SENSOR_3, SENSOR_LIGHT);
frag=0;
while (true){
if(frag==0){
hold_can();
turn_R();
frag=1;
}
if (frag ==1|| 2||4||6||7||9){
linetrace ();
}
if (frag == 3){
OnFwd(OUT_A+OUT_C);Wait(30);
turn_L ();
frag = 4;
}
if (frag == 5){
port_can();
turn_L();
frag=6;
}
if (frag == 8){
OnFwd(OUT_A+OUT_C);Wait(030);
turn_R ();
frag =9;
}
if (frag == 10){
OnFwd(OUT_A+OUT_C);Wait(200);
Off(OUT_A+OUT_C);
Wait(100);
frag = 0;
}
}
}
#define turn_right OnFwd(OUT_A);OnRev(OUT_C);
#define turn_left OnRev(OUT_A);OnFwd(OUT_C);
#define Stop_turning Off(OUT_A+OUT_C);
#define TURN_TIME 200
#define go_straight OnFwd(OUT_A+OUT_C);Wait(50);Off(OUT_A+OUT_C);Wait(50);
task main()
{
SetSensor(SENSOR_2,SENSOR_LIGHT);
int light_max=0,time_max=0;
while(true){
OnFwd(OUT_C);OnRev(OUT_A);Wait(100);Off(OUT_A+OUT_C);Wait(10);
turn_right;
ClearTimer(0);
while(FastTimer(0)<TURN_TIME){
if(SENSOR_2>light_max){
light_max=SENSOR_2;
time_max=FastTimer(0);
#define blackline 40
int frag;
int step;
sub linetrace (){
if ((SENSOR_1<=blackline)&&(SENSOR_3>=blackline)){
OnFwd (OUT_C);OnRev (OUT_A);
}
if ((SENSOR_1>=blackline)&&(SENSOR_3<=blackline)){
OnFwd (OUT_A);OnRev (OUT_C);
}
if ((SENSOR_1<=blackline)&&(SENSOR_3<=blackline)){
frag++;
OnFwd (OUT_A+OUT_C); Wait(010);
}
if ((SENSOR_1>=blackline)&&(SENSOR_3>=blackline)){
OnFwd (OUT_A+OUT_C);
}
}
sub go_straight (){
OnFwd (OUT_A+OUT_C);
}
sub go_back (){
OnRev (OUT_A+OUT_C);
}
sub turn_R (){
OnFwd (OUT_A+OUT_C);Wait(025);
OnRev (OUT_C);Wait(040);Off(OUT_A+OUT_C);
}
sub turn_L (){
OnFwd (OUT_C+OUT_A);Wait(025);
OnRev (OUT_A);Wait(040);Off(OUT_A+OUT_C);
}
sub hold_can()
{
OnFwd(OUT_B);Wait(200);Off(OUT_B);
}
sub part_can()
{
OnRev(OUT_B);Wait(300);Off(OUT_B);
}
task main(){
SetSensor (SENSOR_1, SENSOR_LIGHT);
SetSensor (SENSOR_3, SENSOR_LIGHT);
frag=0;
step=1;
while (true){
Wait(500);
hold_can();
if (step==1){
Wait(050);
go_back ();
turn_R ();
step=2;
}
if (step==2){
linetrace ();
if (frag==5){
frag=6;
turn_L ();
step=3;
}
}
if (step==3){
linetrace ();
if (frag==7){
OnFwd(OUT_A+OUT_C);Wait(50);
part_can();
OnFwd(OUT_A+OUT_C);Wait(50);
frag=8;
step=4;
}
}
if(step==4){
OnRev(OUT_A+OUT_C);Wait(100);
if (frag==9){
turn_L ();
frag=10;
step=5;
}
}
if(step==5){
linetrace();
if(frag==12){
turn_R();
frag=13;
step=6;
}
}
if(step==6){
linetrace();
if(frag==13){
go_straight();Wait(50);
frag=14;
step=7;
}
}
if(step==7){
step=1;
frag=0;
}
}
}
☆
#define blackline 40
int frag;
sub linetrace (){
if ((SENSOR_1 <= blackline) && (SENSOR_3 <= blackline)){
OnFwd(OUT_A + OUT_C);
Wait(030);
frag++;
}
else{
if ((SENSOR_1 <= blackline) && (SENSOR_3 >= blackline)){
OnFwd (OUT_A);OnRev (OUT_C);
}
if ((SENSOR_1 >= blackline) && (SENSOR_3 <= blackline)){
OnFwd (OUT_C);OnRev (OUT_A);
}
if ((SENSOR_1 >= blackline) && (SENSOR_3 >= blackline)) {
OnFwd (OUT_A + OUT_C);
}
}
}
sub hold_can (){
ClearMessage();
until (Message() != 0);
if ( Message() == 1 ){
Wait(1000);
OnFwd(OUT_B);Wait(200);
OnRev(OUT_A+OUT_C);Wait(350);
}
}
sub port_can (){
OnFwd(OUT_A+OUT_C);Wait(30);
OnRev(OUT_B);
Wait (200);
Off (OUT_B);
OnFwd(OUT_A+OUT_C);
Wait(50);
OnRev(OUT_A+OUT_C);
Wait(250);
}
sub go_straight (){
OnFwd (OUT_A+OUT_C);
}
sub go_down (){
OnRev (OUT_A+OUT_C);
}
sub turn_R (){
Off (OUT_A + OUT_C);OnRev (OUT_A+OUT_C);Wait (007);OnFwd (OUT_A);Wait (150);Off (OUT_A+OUT_C);
}
sub turn_r(){
Off(OUT_A+OUT_C);OnRev(OUT_A+OUT_C);Wait(007);OnFwd (OUT_A);Wait(130);
}
sub turn_L (){
Off (OUT_A + OUT_C);OnRev (OUT_C+OUT_A);Wait (007);OnFwd (OUT_C);Wait (130);Off (OUT_A+OUT_C);
}
task main(){
SetSensor (SENSOR_1, SENSOR_LIGHT);
SetSensor (SENSOR_3, SENSOR_LIGHT);
frag=0;
while (true){
if(frag==0){
hold_can();
turn_R();
frag=1;
}
if (frag ==1|| 2||6||7||9){
linetrace ();
}
if (frag == 3){
OnFwd(OUT_A+OUT_C);Wait(30);
turn_L ();
frag = 4;
}
Stop_turning;Wait(100);
turn_left;
Wait(TURN_TIME-time_max);
Stop_turning;
go_straight;
light_max=0;
time_max=0;
if (frag == 4){
port_can();
turn_L();
frag=6;
}
if (frag == 8){
OnFwd(OUT_A+OUT_C);Wait(050);
turn_r ();
frag =9;
}
}
if (frag == 10){
OnFwd(OUT_A+OUT_C);Wait(120);
Off(OUT_A+OUT_C);
Wait(80);
frag = 0;
}
}
}
×
#define blackline 40
int frag;
int step;
task linetrace (){
if ((SENSOR_1<=blackline)&&(SENSOR_3>=blackline)){
OnFwd (OUT_C);OnRev (OUT_A);
}
if ((SENSOR_1>=blackline)&&(SENSOR_3<=blackline)){
OnFwd (OUT_A);OnRev (OUT_C);
}
if ((SENSOR_1<=blackline)&&(SENSOR_3<=blackline)){
frag++;
OnFwd (OUT_A+OUT_C); Wait(010);
}
if ((SENSOR_1>=blackline)&&(SENSOR_3>=blackline)){
OnFwd (OUT_A+OUT_C);
}
}
sub go_straight (){
OnFwd (OUT_A+OUT_C);
}
sub go_back (){
OnRev (OUT_A+OUT_C);
}
sub turn_R (){
OnFwd (OUT_A+OUT_C);Wait(025);
OnRev (OUT_C);Wait(200);Off(OUT_A+OUT_C);
}
sub turn_L (){
OnFwd (OUT_C+OUT_A);Wait(025);
OnRev (OUT_A);Wait(200);Off(OUT_A+OUT_C);
}
sub hold_can()
{
OnFwd(OUT_B);Wait(200);Off(OUT_B);
}
sub part_can()
{
OnRev(OUT_B);Wait(300);Off(OUT_B);
}
task main(){
SetSensor (SENSOR_1, SENSOR_LIGHT);
SetSensor (SENSOR_3, SENSOR_LIGHT);
frag=0;
step=1;
while (true){
Wait(500);
hold_can();
while (step==1){
Wait(050);
go_back ();Wait(400);
turn_R ();Wait(200);
step=step+1;
}
while (step==2){
start linetrace;
if (frag==2){
frag=3;
turn_L ();
step=step++;
}
}
while (step==3){
OnFwd(OUT_A+OUT_C);Wait(100);
part_can();
OnFwd(OUT_A+OUT_C);Wait(50);
step=step++;
}
while(step==4){
OnRev(OUT_A+OUT_C);Wait(150);
turn_L ();
step=step++;
}
while(step==5){
start linetrace;
if(frag==5){
turn_R();
frag=6;
step=step++;
}
}
while(step==6){
start linetrace;
if(frag==7){
go_straight();Wait(50);
frag=8;
step=step++;
}
}
while(step==7){
step=1;
frag=0;
}
}
}
XX
int go_time;
#define TURN_TIME 150
#define BACK_TIME 250
#define HOLD_TIME 30
#define PART_TIME 150
sub go_straight()
{
OnFwd(OUT_A+OUT_C);Wait(go_time);Off(OUT_A+OUT_C);
}
sub turn_right()
{
OnFwd(OUT_A);OnRev(OUT_C);Wait(TURN_TIME);Off(OUT_A+OUT_C);
}
sub turn_left()
{
OnRev(OUT_A);OnFwd(OUT_C);Wait(TURN_TIME);Off(OUT_A+OUT_C);
}
sub back_straight()
{
OnRev(OUT_A+OUT_C);Wait(BACK_TIME);Off(OUT_A+OUT_C);
}
sub hold_can()
{
OnFwd(OUT_B);Wait(HOLD_TIME);Off(OUT_B);
}
sub part_can()
{
OnRev(OUT_B);Wait(PART_TIME);Off(OUT_B);
}
task main()
{
SetSensor(SENSOR_1,SENSOR_LIGHT);
SetSensor(SENSOR_3,SENSOR_LIGHT);
while(true)
{
Wait(500);
hold_can();
back_straight();
turn_right();
go_time=300;
go_straight();
turn_left();
go_time=100;
go_straight();
part_can();
go_time=100;
go_straight();
back_straight();
turn_left();
go_time=300;
go_straight();
turn_right();
go_time=100;
go_straight();
}
}