View unanswered posts | View active topics It is currently Wed Apr 23, 2014 11:06 am






Reply to topic  [ 5 posts ] 
program to stay near wall & program to go back and forth 
Author Message
Rookie

Joined: Mon Mar 26, 2012 12:55 pm
Posts: 2
Post 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);
}


Mon Apr 02, 2012 5:35 pm
Profile
Rookie

Joined: Wed Jul 21, 2010 11:23 pm
Posts: 39
Post 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 ))


Mon Apr 02, 2012 10:48 pm
Profile
Online
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3112
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Apr 03, 2012 1:20 am
Profile WWW
Rookie

Joined: Mon Mar 26, 2012 12:55 pm
Posts: 2
Post 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:


Tue Apr 03, 2012 8:08 am
Profile
Online
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3112
Location: Rotterdam, The Netherlands
Post 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

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Tue Apr 03, 2012 2:53 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: mightor and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.