Proximity Sensor

This is where you talk about the RCX hardware related topics such as the brick, sensors, LEGO pieces, etc

Moderator: roger

Proximity Sensor

Postby byrneda » Tue Mar 06, 2007 3:07 pm

Hi everyone just new to this form, I am trying to create a Collision Avoidance robot that will hopefully use the Proximity Sensor, could some one please tell me how to create the sensor using the light Sensor and what test code I will need to set it up.
Thanks
Damien
byrneda
New User
 
Posts: 1
Joined: Wed Feb 28, 2007 1:26 pm

How to make a Proximity Sensor

Postby Tohlizzle » Sat Feb 20, 2010 3:46 pm

The following code is a program I wrote that is based on a program from Brian Bagnall's Core Lego Mindstorms Programming book:
Code: Select all
package tohlizzle;
import josx.platform.rcx.Sensor;
import josx.platform.rcx.LCD;
import josx.platform.rcx.Serial;
public class Proximity {
   public static byte [] PcKt = {127};
   public static int OlVl, NwVl, DfRn, ThSl;
   public static void main(String [] args) {
      LCD.clear(); LCD.refresh(); Sensor PrXm = Sensor.S2;
      PrXm.setTypeAndMode(3, 0x00); PrXm.activate(); Serial.setRangeLong();
      josx.platform.rcx.Motor LeFt = josx.platform.rcx.Motor.A; LeFt.setPower(6);
      josx.platform.rcx.Motor RgHt = josx.platform.rcx.Motor.C; RgHt.setPower(7);
      do {
         OlVl = PrXm.readValue(); Serial.sendPacket(PcKt, 0, 1); try {Thread.sleep(5);}
         catch(InterruptedException e) {Print("IntEx"); ThSl = 0; do {ThSl++;} while(ThSl != 99999);}
         catch(Exception e) {Print("Excpt"); ThSl = 0; do {ThSl++;} while(ThSl != 99999);}
         catch(Error e) {Print("Error"); ThSl = 0; do {ThSl++;} while(ThSl != 99999);}
         NwVl = PrXm.readValue(); DfRn = Math.abs(OlVl - NwVl);
         if (DfRn > 80) {
            josx.platform.rcx.Sound.playTone(DfRn, 20); LCD.showNumber(DfRn); LeFt.backward(); try {Thread.sleep(2000);}
            catch(InterruptedException e) {Print("IntEx"); ThSl = 0; do {ThSl++;} while(ThSl != 99999);}
            catch(Exception e) {Print("Excpt"); ThSl = 0; do {ThSl++;} while(ThSl != 99999);}
            catch(Error e) {Print("Error"); ThSl = 0; do {ThSl++;} while(ThSl != 99999);}
         }
         else {LeFt.forward(); RgHt.forward();}
      } while(!josx.platform.rcx.Button.VIEW.isPressed()); DfFr.stop(); PrXm.passivate();
   }
   public static void Print(String PsSt) {LCD.clear(); josx.platform.rcx.TextLCD.print(PsSt);}
       
}

Just place the light sensor in front of your robot and upload the above source code. :)
Tohlizzle
New User
 
Posts: 4
Joined: Sat Feb 20, 2010 2:57 pm
Location: United States

Re: Proximity Sensor

Postby Clarice » Thu Jan 05, 2012 10:42 pm

Thank you very much for this information! This has been really helpful in helping me figure out how to properly use the proximity sensors. I had a thought, and would like to know what you guys think. I was wondering if a rfid reader could be used in conjunction of the proximity sensor? I was thinking that the reader would could work in a way that it will not allow the bot to operate unless it is within range of the reader. I think that this would be a pretty cool feature if I could get it to work right, what do you guys think about this idea?
Clarice
New User
 
Posts: 1
Joined: Thu Jan 05, 2012 10:41 pm


Return to RCX Hardware

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff