Hello, we have a subject that’s called NLT (Nature, life and technology), every time we do a different project and this time we need to code a robot in Java (or as the book calls it: a simplified version of Java). We are working in Eclipse.
Our robot needs to follow a black line and avoid an object at the end of the line.
Here are the requirements:
1. The Robot drives for 1 second, stops 1 sec and follows the line after that.
2. The Robot needs to finish the parkour under 45 seconds.
3. If we have the fastest time we get bonus points.
4. Every tight corner is made.
5. Every normal corner is made.
6. The object is in a controlled manner avoided.
7. The robot stops on the yellow finish.
8. A part must be driven with one sensor (the color sensor)
9. A Part must be driven with two sensors (also the colors sensors)
10. There must be a subroutine in the code that’s utilized.
11. The robot must put what it’s doing on its LCD display and in the server messages.
12. There must be a ’self-made’ piece of code.
13. The program is indexed and made easy to look at.
The robot has a distance sensor and a color sensor that I know off.
As we are not very good at coding and have tried a lot but I don’t think we have the most efficient code so we would really like some help!
We would like to make it so it follows the line a lot faster. Also, we do not know how to switch to a different state from the line follower.
One of the bigger problems is that in a subroutine it stops using the subroutine after like the third one and just keeps doing the third given subroutine.
We thought of using a timer that would count and when it’s done counting it would avoid the object, don’t know if that’s the best way though.
We only need to drive the robot in the simulator so there wouldn’t be any inaccurate sensors or something similar.
We would really like some help, even if it’s just a small thing, we really appreciate it!
P.S: If you need more, like the whole workspace we have been working in or when something is unclear, don’t be scared to ask! (P.P.S Sorry if my English wasn’t clear, we are Dutch)
Have a good one,
Tim and his group.
package javaBot.Nano.Rescue; import com.muvium.apt.PeriodicTimer; public class DriveBehavior05 extends Behavior { private BaseController joBot; private int state = 1; private int count = 0; int fl = 0; int fr = 0; int ds = 0;; //Subroutine Defined private void jobotDrive (int curState, int newState, int l, int r, int t) { if (state == curState) { joBot.drive(l, r); if (count++ >= t) { state = newState; joBot.printLCD("State="+ state); count = 0; } } } public DriveBehavior05(BaseController initJoBot, PeriodicTimer initServiceTick, int servicePeriod) { super(initJoBot, initServiceTick, servicePeriod); joBot = initJoBot; } public void doBehavior() // Robot Drives one second, stops one second and continues { jobotDrive(1, 2, 100, 100, 10); jobotDrive(2, 3, 0, 0, 10); if (state == 3) { System.out.println("Line Follower"); joBot.setStatusLeds(false, false, false); joBot.drive(100, 100); // Drives Straight joBot.setFieldLeds(true); // Turns on Field Leds state = 4; } //Color Sensor Follower if (state == 4) { ds = joBot.getSensorValue(BaseController.SENSOR_DS); fl = joBot.getSensorValue(BaseController.SENSOR_FL); // Left sensor fr = joBot.getSensorValue(BaseController.SENSOR_FR); // Right sensor if (fl < 350) { joBot.drive(10, 60); // Go left joBot.setLed(BaseController.LED_GREEN, true); } if (fr < 350) { joBot.drive(60, 10); // Go right joBot.setLed(BaseController.LED_GREEN, false); } } count ++; if (count >= 400){ state = 5; } //non working soubroutine { jobotDrive(5, 6, 100, 0, 10); jobotDrive(6, 7, 100, 100, 20); jobotDrive(6, 7, 0, 100, 10); jobotDrive(7, 8, 100, 100, 20); } if (state == 5){ joBot.drive (0,0); } } }