Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Robot Needs To Follow A Parkour, Can’t Seem To Make It Work  RSS feed

 
Tim Brandt
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Title: Robot Needs To Follow A Parkour, Can’t Seem To Make It Work
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.
States are made so you can write code linear, first do this (state 1) and then do this (state 2).
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.


Parkour-NLT.png
[Thumbnail for Parkour-NLT.png]
 
Stephan van Hulst
Saloon Keeper
Posts: 7190
118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before we can help you, we need to know a lot more:

  • What API do you have available to interact with the robot?
  • When must only the color sensor be used?
  • When must both sensors be used?
  • What does it mean for the program to be "indexed"?

  • One thing I can already tell you, is that your code is not easy to look at. Here are some things you can improve:

  • Don't use abbreviations for variable names. Write names out in full. Characters don't cost anything, but legibility is worth a lot!
  • If you're making a state machine, don't use integers for state. Use enums. That way, it's easy to see what state the robot is in.
  • Break up your code in multiple methods, each with a strictly defined purpose. The doBehavior() method is much too vague.
  •  
    Tim Brandt
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Stephan van Hulst wrote:Before we can help you, we need to know a lot more:

  • What API do you have available to interact with the robot?
  • When must only the color sensor be used?
  • When must both sensors be used?
  • What does it mean for the program to be "indexed"?

  • One thing I can already tell you, is that your code is not easy to look at. Here are some things you can improve:

  • Don't use abbreviations for variable names. Write names out in full. Characters don't cost anything, but legibility is worth a lot!
  • If you're making a state machine, don't use integers for state. Use enums. That way, it's easy to see what state the robot is in.
  • Break up your code in multiple methods, each with a strictly defined purpose. The doBehavior() method is much too vague.


  • Hi thanks for responding!
    I am not sure what API I have available, the thing I know is that I use the latest java version. Its run in a simulator so we dont use a real Robot.
    We need to follow the black line (seen in the picture attached) first with only one color sensor and after that we need to switch and use both color sensors. At the end of the line we need to avoid a object, probably with the distance sensor. Atm we are struggling with the subroutine because it loops after the third command (state 4,5,6 go well and than it stays in state 6 and doesn't move forward to the next state for example)
    Its a assignment I think they mean by indexed that it is in a good order and not random code here and code there.
    I have to confess that I received a workspace from school and a book, we didnt write the beginning of the code but I will try to change it (we wrote the subroutine and linefollower all by ourselves but we also looked alot at other peaces of code and the book to write this, being thrown into Java without previous experience is quite hard).
    Could you please explain how we use enums!
    We know it might be much to ask but the teacher that gives NLT normal gives biology so he doesn't understand it alot better than we do... So we would really appreciate it if you could explain Enums!.
    The doBehaviour method is a example of code that already was there but we'll try to fix it without breaking the code!
    I am sorry if i misinterpreted anything and gave like a really non logical answer.
    We really hope you can help us further with the extra information we have given!
    We would like to learn but yah the book and the teacher aren't very good...
    Thanks in advance,
    Tim and his group.

     
    Stephan van Hulst
    Saloon Keeper
    Posts: 7190
    118
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Tim Brandt wrote:I am not sure what API I have available, the thing I know is that I use the latest java version. Its run in a simulator so we dont use a real Robot.

    By this I mean all the methods and their descriptions that are already provided to you. For instance, I see that you have classes PeriodicTimer, Behavior and BaseController. It would be helpful if you could share the documentation of these classes with us, and any other classes you have that are not part of the Java standard API.

    Atm we are struggling with the subroutine because it loops after the third command (state 4,5,6 go well and than it stays in state 6 and doesn't move forward to the next state for example)

    How do you know it's stuck in a particular state?

    being thrown into Java without previous experience is quite hard).
    Could you please explain how we use enums!

    Have you guys already checked out the Java tutorials? That's the first resource I would check out. These are the most important trails for you to learn for now:
  • Language Basics
  • Classes and Objects

  • The doBehaviour method is a example of code that already was there but we'll try to fix it without breaking the code!

    You don't need to remove it, you just need to break up its contents so that different behaviors are defined in different methods. The doBehavior() method then just calls these methods as appropriate.
     
    John Joe
    Ranch Hand
    Posts: 314
    2
    Android Eclipse IDE Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi, welcome to CodeRanch  

    Look like a cross-post to me.

    Robot needs to follow a parkour, cant seem to make it work
     
    Campbell Ritchie
    Sheriff
    Posts: 54033
    130
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Please always tell the people on both websites if you post a question in two places.
     
    Tim Brandt
    Greenhorn
    Posts: 3
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,
    Sorry for not responding as fast.
    We have fixed our code and it now at least works, yes I know that most coders will probably hate our method of working with code but hey it works.. (finally after 5 hours in one day).
    We really appreciate your help though! You were really nice and willing to help! If I ever have a other question I'll be shure to go to this forum.
    We thank you for your help again and I will close this thread now

    Bye,
    Tim and his Group

    For the guys who are curious, here is our code

     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!