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

wall detection (touch) % wall detection(ultra sonic)
http://robotc.net/forums/viewtopic.php?f=1&t=5712
Page 1 of 3

Author:  MariosRobot [ Wed Apr 17, 2013 7:02 am ]
Post subject:  wall detection (touch) % wall detection(ultra sonic)

i have problem in two programs
with wall detections(touch)
and wall detections(ultra sonic)

the while loop not take the function that go forward, someone knows why?

1st program
const tSensors touchSensor = (tSensors) S1;//sensor touch
task main()
{
while(SensorValue(touchSensor) == 0)
//go forware
{
motor[motorA]=10;
motor[motorC]=10;
wait1Msec(4550);
}
//go backward
motor[motorA]=-3;
motor[motorC]=-3;
wait1Msec(4550);

2nd program
const tSensors bumper = (tSensors) S1;//sensor touch
task main()
{
while(SensorValue(bumper) == 0)
//go forware
{
motor[motorA]=10;
motor[motorC]=10;
wait1Msec(4550);
}
//go backward
motor[motorA]=-3;
motor[motorC]=-3;
wait1Msec(4550);

Author:  NeXT-Generation [ Wed Apr 17, 2013 10:28 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

What version of RobotC are you using? And could you please use the [code][/code] tags for your code? It makes it easier to read and understand.

Author:  MariosRobot [ Wed Apr 17, 2013 3:27 pm ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

i use the latest version 3.6

Author:  NeXT-Generation [ Wed Apr 17, 2013 3:52 pm ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

Ok well, I just took your code and indented it all myself. Several things stand out.

1. You don't have a closing brace for your task main()
2. You're not defining the S1 sensor type.
3. And I have no idea what you're trying to accomplish with "const tSensors touchSensor = (tSensors) S1;//sensor touch".

Try this code, it should work fine.

Code:
#pragma config(Sensor, S1,     touchSensor,    sensorTouch)

task main()
{
   //Go forwards if the touch sensor is NOT pressed.
   while(SensorValue(touchSensor) == 0)
   {
      motor[motorA]=10;
      motor[motorC]=10;
      wait1Msec(4550);
   }
   //else if is pressed go backwards.
   motor[motorA]=-3;
   motor[motorC]=-3;
   wait1Msec(4550);
}


and,

Code:
#pragma config(Sensor, S1,     bumper,    sensorTouch)

task main()
{
   //Go forwards if the touch sensor is NOT pressed.
   while(SensorValue(bumper) == 0)
   {
      motor[motorA]=10;
      motor[motorC]=10;
      wait1Msec(4550);
   }
   //else if is pressed go backwards.
   motor[motorA]=-3;
   motor[motorC]=-3;
   wait1Msec(4550);
}


FYI, these two programs are identical, they just have different names for the sensor. Also just wondering, why are your motor speeds so slow?

Author:  MariosRobot [ Thu Apr 18, 2013 7:08 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

thanks a lot bro, i try again with these codes,
i test the robot's sensor because i have a project in robotC but my area it is small for this reason i put lower speed, to control easy the robot

Author:  MariosRobot [ Thu Apr 18, 2013 8:02 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

i try with this code but the while loop not working, when the Lego touch in the wall not go back, how to check if the Lego's sensor working?

Author:  NeXT-Generation [ Thu Apr 18, 2013 10:23 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

Ok, so you want it to go forwards until it hits the wall? If so, then try this:

Code:
#pragma config(Sensor, S1,     touchSensor,    sensorTouch)

task main()
{
   //Go forwards if the touch sensor is NOT pressed.
   while(SensorValue(touchSensor) == 0)
   {
      motor[motorA]=10;
      motor[motorC]=10;
      //wait1Msec(4550);
   }
   //else if is pressed go backwards.
   motor[motorA]=-3;
   motor[motorC]=-3;
   wait1Msec(4550);
}


I have commented out the wait time in the while loop, because if you do have it waiting it will only check the touch sensor every 4.55 seconds. That's bad. You also might get better results with some faster motor speeds. Even 25% would be good.

Author:  MariosRobot [ Fri Apr 19, 2013 7:09 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

thanks again bro, i try again with this code

Author:  MariosRobot [ Sat Apr 20, 2013 4:18 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

again not working bro,
how to check if the robot's sensor it working great?

Author:  NeXT-Generation [ Sat Apr 20, 2013 11:07 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

Go to the "view" menu, and select touch sensor. That'll tell you if it's working or not.

Author:  MariosRobot [ Sun Apr 21, 2013 3:21 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

thanks a lot bro

Author:  MariosRobot [ Sun Apr 21, 2013 3:59 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

i not found the touch sensor in "view" menu
i uploaded the print screen

Attachments:
view menu.png
view menu.png [ 121.88 KiB | Viewed 9092 times ]

Author:  NeXT-Generation [ Sun Apr 21, 2013 9:27 am ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

No, no, on the NXT. You scroll through it's menu screen until you see "View".

Author:  Coder A [ Sun Apr 21, 2013 7:37 pm ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

NeXT-Generation wrote:
No, no, on the NXT. You scroll through it's menu screen until you see "View".



That's where my friends apostrophe went!

Sorry, I couldn't resist. If you look one my profile on of my interests is correct grammar.

Author:  NeXT-Generation [ Sun Apr 21, 2013 7:43 pm ]
Post subject:  Re: wall detection (touch) % wall detection(ultra sonic)

No, no, I, am like, way, way, correct. :lol: We unfortunate Americans say "No, no" when we correct someone. :lol:

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