Robot needs to follow a parkour, cant seem to make it work

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 898 Views - Last Post: 07 June 2017 - 12:02 PM Rate Topic: -----

#1 TimBC   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-June 17

Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 07:38 AM

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);
		}
	}
}


Is This A Good Question/Topic? 0
  • +

Replies To: Robot needs to follow a parkour, cant seem to make it work

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15799
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 07:48 AM

What are you states supposed to be?
Was This Post Helpful? 0
  • +
  • -

#3 TimBC   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-June 17

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 07:55 AM

View Postmodi123_1, on 05 June 2017 - 07:48 AM, said:

What are you states supposed to be?


States define like a state where the Robot is in, it works in a way so you can linear write the code. Do this (state 1) and then do this (state 2).
I hope I explained it well enough :)
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15799
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 07:57 AM

No, I get what a 'state' is in theory, but what are you robot's states? I see references to state 1, 4, 5, 6, 7, and 8.. do those mean something, or what?

Like state 1 is setup.. state 2 is drive.. state 3 is wait.. state four is 'finished'.. etc?
Was This Post Helpful? 0
  • +
  • -

#5 TimBC   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-June 17

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 07:59 AM

View Postmodi123_1, on 05 June 2017 - 07:57 AM, said:

No, I get what a 'state' is in theory, but what are you robot's states? I see references to state 1, 4, 5, 6, 7, and 8.. do those mean something, or what?

Like state 1 is setup.. state 2 is drive.. state 3 is wait.. state four is 'finished'.. etc?


No the states don't represent anything, we code in a way so the states make sense. We ourselfs define a state by telling it state 1 is this, for the rest they don't reference to anywhere else in the code.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15799
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 08:11 AM

Okay.. so that's a problem in your thinking. A state shouldn't just be a count on the iteration.. it should be a defined concept you can draw out and connect with arrows to frame out your logic.

To me you would have four over arching states:
- start
- drive
- wait
- end

In theory the 'start' would setup variables, values, initialize things, etc.
Your 'drive' would set the vehicle in motion
'Wait' does.. what ever.. nothing? sleep? Pause, etc..
'Wait' would also evaluate if it should go to the 'end' state or back to 'drive'.

After the 'start' state drive/wait would be in, most likely, some sort of while loop or repeating function until 'end' is hit.
Was This Post Helpful? 0
  • +
  • -

#7 TimBC   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-June 17

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 08:18 AM

View Postmodi123_1, on 05 June 2017 - 08:11 AM, said:

Okay.. so that's a problem in your thinking. A state shouldn't just be a count on the iteration.. it should be a defined concept you can draw out and connect with arrows to frame out your logic.

To me you would have four over arching states:
- start
- drive
- wait
- end

In theory the 'start' would setup variables, values, initialize things, etc.
Your 'drive' would set the vehicle in motion
'Wait' does.. what ever.. nothing? sleep? Pause, etc..
'Wait' would also evaluate if it should go to the 'end' state or back to 'drive'.

After the 'start' state drive/wait would be in, most likely, some sort of while loop or repeating function until 'end' is hit.


I understand where you coming from, the problem is that we got a workspace and the book was like yah do this. We never learned the way you are working with states. I dont know what the rest of the code is using. How would we define the states in the way you suggest it? The way we are working at the moment works quite fine if I say so myself but I am always open for improvement!
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15799
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 08:36 AM

Seems easy enough to have functions called: start, drive, wait, end.
Was This Post Helpful? 0
  • +
  • -

#9 TimBC   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-June 17

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 08:38 AM

View Postmodi123_1, on 05 June 2017 - 08:36 AM, said:

Seems easy enough to have functions called: start, drive, wait, end.


Sorry I really want to understand but we/I are really really bad at coding. So I do not understand how you use and define a function...
(gosh I feel dumb now)
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15799
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 08:49 AM

You already defined functions in all that code you wrote..

Example:
13    private void jobotDrive (int curState, int newState, int l, int r, int t) {
...
23    public Drivebehavior05(BaseController initJoBot,
24            PeriodicTimer initServiceTick, int servicePeriod) {
...
29    public void dobehavior()

Was This Post Helpful? 0
  • +
  • -

#11 TimBC   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-June 17

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 08:51 AM

View Postmodi123_1, on 05 June 2017 - 08:49 AM, said:

You already defined functions in all that code you wrote..

Example:
13    private void jobotDrive (int curState, int newState, int l, int r, int t) {
...
23    public Drivebehavior05(BaseController initJoBot,
24            PeriodicTimer initServiceTick, int servicePeriod) {
...
29    public void dobehavior()


So something like this? Have I now defined StateDrive to make the robot drive at full power?

private void StateDrive (joBot.drive 100,100)

Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15799
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 08:56 AM

Well.. no. You are mixing the method signature and implementation.

Soooooo... I am guessing all that code above wasn't written by you or your team?
Was This Post Helpful? 0
  • +
  • -

#13 TimBC   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-June 17

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 05 June 2017 - 09:05 AM

View Postmodi123_1, on 05 June 2017 - 08:56 AM, said:

Well.. no. You are mixing the method signature and implementation.

Soooooo... I am guessing all that code above wasn't written by you or your team?


As I said, we got a workspace already so all the code was written for us. The only thing we actually did was apply methods used in our book and read other peaces of code and use them. The If statements and subroutine are written by us yes but not the whole code, sorry If that wasn't clear.
Was This Post Helpful? 0
  • +
  • -

#14 TimBC   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-June 17

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 07 June 2017 - 11:56 AM

ALREADY SOLVED!
(Couldnt find the close thread button :( )
Was This Post Helpful? 0
  • +
  • -

#15 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 15799
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: Robot needs to follow a parkour, cant seem to make it work

Posted 07 June 2017 - 11:57 AM

What did you do to ended up with a solution?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2