ROBOTC.net forums
http://robotc.net/forums/

program to stay near wall & program to go back and forth
http://robotc.net/forums/viewtopic.php?f=1&t=4426
Page 1 of 1

Author:  tgarrisoniv [ Mon Apr 02, 2012 5:35 pm ]
Post subject:  program to stay near wall & program to go back and forth

i am trying to create a program for my robot to sear within 8-10 cm of a wall. i have 2 sensors, one facing forward and one to the right. the square the robot will be in has walls that come out so the forward is necessary. the program i have made simply makes the robot go in circles and when it is with 8-10 cm it just stops.
Code:
void stayNearWall()
{
 
while(SensorValue[sonarSensor1 || sonarSensor2] => 8)
{
  motor(motorB)=50;
  motor(motorC)=0;
  wait1Msec(100);
 
  motor(motorB)=50;
  motor(motorC)=50;
 
 
}
  while(SensorValue[sonarSensor1 || sonarSensor2]=< 10)
{
  motor(motorB)=50;
  motor(motorC)=0;
  wait1Msec(100);
 
  motor(motorB)=50;
  motor(motorC)=50;
}

}


i also am trying to make a program that makes the robot go back and forth across the arena while moving forward each time. unfortunately, it is also a failure... any help is appreciated!!
Code:
void BackandForth()
{
  while(sensorValue[sonarSensor1 || sonarSensor2] > 12)
{
  motor(motorB)=50;
  motor(motorC)=50;
}

  //Left Turn
  motor(motorB)=16.665;
  motor(motorC)=-16.665;
  wait1Msec(1150);

  motor(motorB)=50;
  motor(motorC)=50;
  wait1Msec(100);

  //Left Turn
  motor(motorB)=16.665;
  motor(motorC)=-16.665;
  wait1Msec(1150);

  motor(motorB)=50;
  motor(motorC)=50;
  wait1Msec(500);

  while(sensorValue[sonarSensor1 || sonarSensor2] > 5)
{
  motor(motorB)=50;
  motor(motorC)=50;
}

  //Right Turn
  motor(motorB)=-16.665;
  motor(motorC)=16.665;
  wait1Msec(1150);

  motor(motorB)=50;
  motor(motorC)=50;
  wait1Msec(100);

  //Right turn
  motor(motorB)=-16.665;
  motor(motorC)=16.665;
  wait1Msec(1150);

  motor(motorB)=50;
  motor(motorC)=50;
  wait1Msec(500);

  while(sensorValue[sonarSensor1 || sonarSensor2] > 5)
{
  motor(motorB)=50;
  motor(motorC)=50;
}

  //Left Turn
  motor(motorB)=16.665;
  motor(motorC)=-16.665;
  wait1Msec(1150);

  motor(motorB)=50;
  motor(motorC)=50;
  wait1Msec(100);

  //Left Turn
  motor(motorB)=16.665;
  motor(motorC)=-16.665;
  wait1Msec(1150);

  motor(motorB)=50;
  motor(motorC)=50;
  wait1Msec(500);


  while(sensorValue[sonarSensor1 || sonarSensor2] > 5)
{
  motor(motorB)=50;
  motor(motorC)=50;
}

  //Right Turn
  motor(motorB)=-16.665;
  motor(motorC)=16.665;
  wait1Msec(1150);

  motor(motorB)=50;
  motor(motorC)=50;
  wait1Msec(100);

  //Right turn
  motor(motorB)=-16.665;
  motor(motorC)=16.665;
  wait1Msec(1150);

  motor(motorB)=50;
  motor(motorC)=50;
  wait1Msec(500);
}

Author:  ronmcrae [ Mon Apr 02, 2012 10:48 pm ]
Post subject:  Re: program to stay near wall & program to go back and forth

I'm thinking you might want to replace
Code:
while(SensorValue[sonarSensor1 || sonarSensor2] => 8)

with
Code:
while((SensorValue[sonarSensor1]>=8) || (SensorValue[sonarSensor2]>=8 ))

Author:  mightor [ Tue Apr 03, 2012 1:20 am ]
Post subject:  Re: program to stay near wall & program to go back and forth

Ron,

It's certainly the most creative use of SensorValue and logic operators I have ever seen :)

- Xander

Author:  tgarrisoniv [ Tue Apr 03, 2012 8:08 am ]
Post subject:  Re: program to stay near wall & program to go back and forth

ron,

thanks.

xander,

i think thats a compliment? this has been a nightmare for me! :breakcomputer:

Author:  mightor [ Tue Apr 03, 2012 2:53 pm ]
Post subject:  Re: program to stay near wall & program to go back and forth

Yeah, it was a bit of a joke. It is amusing to see people do things that seem perfectly logical (pardon the pun) but that really don't work. I can see the thought process behind it and am somewhat surprised that I have not fallen into the same trap :)

Making mistakes, some even slightly amusing (to others anyway), are a great way to learn new things. I still make plenty of boneheaded mistakes and I've been programming for almost 18 years :)

- Xander

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/