The problem with the solution u have provided is that I have already used the Light Sensor for the Line Following operation that the robot is doing. The bot does line following, color identification, bar code - magnetic card reading & measure distances and returns all feedback to a user on a remote machine, which has a Macromedia Flash User Interface.  Also with proper user logins, u can even upload your own programs into the RCX from this remote location. Using this Flash UI the user can give commands to the bot and get feedback on the above given operations.

Actually Im doing this project as part of my final year BS, and I have also made a gc for the leJOS (which can collect unused objects as well, not just variables like the current mark()..but alas :( adds a 2KB footprint  ), that I later plan to release to the leJOS team, after my proj is submitted.

I just need the time for which the robot travelled before getting a signal from the touch sensors. But then this is an urgent requirement that can be implemented easily, if someone has already made anything like this before or some package any1 has made earlier!!


--
Regards,
Saptarshi PURKAYASTHA

You Live by CHOICE, Not by CHANCE


On 4/14/06, William J Rust < [EMAIL PROTECTED]> wrote:
I've never tried this but ...

You could make a crude rotation sensor with a light sensor and a paper
disk (this is essentially what we do on the bigger robots that I work
with). Mark one or more diameters on the disk (think of it like a pizza
and mark it to cut into quarters). Attach the disk to a wheel and
position the light sensor so that it can count the number of times the
lines pass under it. Then calculate how long one rotation is in terms of
distance traveled by the robot. LeJOS is fast enough that a listener
should be able to count the rotations even if the robot is traveling
fairly fast. Again, I haven't tried this but it shouldn't take more than
10 minutes to cut out a piece of paper, draw a line on the paper, attach
it to an axle and wheel, mount the light sensor and then write a program
to count the number of light to dark transitions.

I went ahead and made a wheel and modified a program. You might want to
play with it, especially just counting just the to dark transitions
instead of both the to dark and to light ones.

wjr

Saptarshi Purkayastha wrote:
> I have created a robot on differential drive which is connected with a
> bumper mechanism using the touch sensor. I want to create a program
> that measures distances between walls of the room.
>
> I know the robot can travel 1m distance in 2secs. But now what I want
> to do is, when the bumper is pressed(robot hits the wall) the robot
> should stop moving forward and display the distance travelled on the
> LCD. I've tried using System.currentTimeMillis(), but since leJOS
> doesnt support "long" datatypes, Im unable to use it and find the time
> for which it travelled before hitting the wall. I cant find anything
> useful in the TimingNavigator class that can give me distance
> travelled by robot.
>
> Please provide some solution on how can this be done. Please reply
> quickly as this is an urgent requirement.
>
> --
> Regards,
> Saptarshi PURKAYASTHA
>
> You Live by CHOICE, Not by CHANCE


package MyRobots;

import josx.platform.rcx.Sensor ;
import josx.platform.rcx.SensorListener;
import josx.platform.rcx.LCD;

/**
* SensorListenerAIC is a listener style program. The SensorListener interface
* specifies only one method, stateChanged. In this program, an anonymous inner
* class is used. That is, in the call to the addSensorListener method, a new
* SensorListener is created with stateChanged method defined inside the
* addSensorListener method call.
*/

class LightCounter {

        public static int count;
        public static int threshold = 40;
        public static boolean side = true;

        public static void main(String[] args) {
                // define sensor as light sensor, 3, and percent mode, 0x80
                Sensor.S1.setTypeAndMode(3, 0x80);
                Sensor.S1.activate();
                Sensor.S1.addSensorListener (new SensorListener() {
                public void stateChanged (Sensor src, int oldValue, int newValue) {
                // Will be called whenever sensor value changes
//                      LCD.showNumber (newValue);
                        if (newValue < threshold && side) count++;
                        if (newValue > threshold && !side) count++;
                        side = newValue > threshold;
                LCD.showNumber (count);
                }
                });
                while (true);
     }
}

Reply via email to