6

One way of doing this is using a loop and interrupting it. How it works: The "Loop Interrupt" block stops all blocks running inside of the loop, so by interrupting the loop after either wait block, it will stop the other wait block. The type of loop doesn't actually matter because we never reach that point. I chose to wait for "Logic" with a value of "...


4

It's a little unclear from your question where this is currently failing, but I do see a couple issues with your code. 1. Your if blocks are probably not doing what you expect. You should include braces to conditionally run the block following an if statement. As written, all of your code executes all of the time. This is a tricky bug to spot, as it looks ...


2

There are a few different but related problems here. Position Your robot should be able to know where it is in the room. This can be achieved in a few ways: Using the ultrasonic sensor as a sonar, rotating it around and storing the readouts, then calcualting based on the known map of the room (if the layout is fixed and known in advance). Tracking the ...


2

Balanc3r is a good alternative for gyro-boy: http://robotsquare.com/2014/06/23/tutorial-building-balanc3r/ However, why do you conclude that the 45504 sensor is out of stock? In my region (Belgium) it can be ordered from the lego website and is listed as "Available", also it is contained in the core educational set (45544) which is certainly still available ...


1

I like your username. I'm not exactly good at NXC either, but I'm experienced in C and Java. So here's some pseudocode that should get the job done. This will rotate the scanning motor 180 degrees, while remembering the closest object it's seen, and then rotating that motor back to point towards the closest object. You will need to change the functions to ...


1

Second if needs to be replaced by a loop... Very unlikely that the distance will be immediately less then 25 cm after starting the motors, you need to continuously check... And stopping the motors can then be done unconditionally (i.e. outside the while loop) Something like while (us1.getDistance() >= 25 && !Button.ESCAPE.IsDown()) { Thread....


1

If a significant distance from the wall, you'll need to turn 90 degrees in place clockwise, drive up to the wall and turn 90 degrees in place counterclockwise. I'd suggest mounting a touch sensor in front of the vehicle handle the part of driving up to the wall, if that is not possible, estimate from the scanned distance how far the vehicle should drive. If ...


1

You can use the lejos.ev3.robotics.RangeFinder abstraction class: EV3UltrasonicSensor sensorUS; RangeFinder sonar; public UltrasonicSensor(Port port) { sensorUS = new EV3UltrasonicSensor(port); sonar = new RangeFinder(sensorUS); } @Override public boolean takeControl() { return sonar.getRange() < 0.3; } Use the float getRange() method to ...


1

As you suspected, you cannot use the Ultrasonic sensor without an "Intelligent Brick" (EV3 or NXT). MINDSTROMS would be a great way to automate your train if you are willing to make the investment. For more ideas on how to use LEGO MINDSTORMS with LEGO trains, check out Sioux.NET.


Only top voted, non community-wiki answers of a minimum length are eligible