Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Driverstation Pong! (http://www.chiefdelphi.com/forums/showthread.php?t=79352)

byteit101 16-12-2009 16:50

Driverstation Pong!
 
1 Attachment(s)
Yesterday, the programming part of our team had a little fun playing pong on our (still functional!) Driverstation. I had originally written the code coming back from one of our competitions while trying to teach some C++ to a VB programmer, and had never tested it. Once we finished what we were doing yesterday, I happened to notice the project, and decided to test it out. Aside from a few small bugs, it worked! I have the (C++) source attached. This is fun!

to use: create new simpleTemplate example project, and copy DS pong files to it. Build and download. Then switch to the user display on the DS (hold Select down for 1 second). Start pong by pulling Joystick 1's trigger. to reset after winning or loosing, pull joystick 1's trigger. The ball moves in random directions from random locations.

Ideal setup: Driver station on table between 2 people, with joystick 1 on left of DS, joy 2 on right, both backwards (trigger towards front of DS)

Bigcheese 17-12-2009 19:35

Re: Driverstation Pong!
 
This is quite a cool idea, although I did take a look at your code and found some issues.
  • There are quite a few places where there's no code formatting, making it very difficult to read.
  • The use of a try/catch statement for program flow is bad. There's no reason to do this. Simply use a goto statement if you want to reenter the loop.

Now, to defend the use of goto.
Using an exception is the exact same thing as a goto in this case, except that the try/catch implies something different is going on, and ignores all real exceptions because of the catch(...).

Yes, you could use some extra logic to handle exiting the double loop, but in the end, the simplest, and most readable solution is to have a label directly before the main while, and a goto on win.

Although the best solution would be to split the code up into separate functions such as.
  • Setup
  • WaitForStart
  • Update - Returns a value in {continue, player_1_won, player_2_won}

Then the problem wouldn't be there to begin with :P.

John G 17-12-2009 19:45

Re: Driverstation Pong!
 
cool. At first glance, I thought you were talking about "apple juice" pong. I then imagined trying to play DS pong and how hard it wouold be. :)

Team1559is1337 17-12-2009 19:48

Re: Driverstation Pong!
 
where do you paste the code in the template?

Team1559is1337 17-12-2009 20:05

Re: Driverstation Pong!
 
haha just kidding i just got it. nice code! :yikes: :yikes: :yikes: :yikes: :yikes:

byteit101 17-12-2009 22:25

Re: Driverstation Pong!
 
Quote:

Originally Posted by Bigcheese (Post 888896)
This is quite a cool idea, although I did take a look at your code and found some issues.
  • There are quite a few places where there's no code formatting, making it very difficult to read.
  • The use of a try/catch statement for program flow is bad. There's no reason to do this. Simply use a goto statement if you want to reenter the loop.

Now, to defend the use of goto.
Using an exception is the exact same thing as a goto in this case, except that the try/catch implies something different is going on, and ignores all real exceptions because of the catch(...).

Yes, you could use some extra logic to handle exiting the double loop, but in the end, the simplest, and most readable solution is to have a label directly before the main while, and a goto on win.

Although the best solution would be to split the code up into separate functions such as.
  • Setup
  • WaitForStart
  • Update - Returns a value in {continue, player_1_won, player_2_won}

Then the problem wouldn't be there to begin with :P.

I know, Its not ideal (I could improve it a ton), but I did not want to spend too much time designing if statements, remembered about exceptions, and used them. (I did not think of goto until just now, being a very OOPy programmer)
Quote:

Originally Posted by John G (Post 888901)
cool. At first glance, I thought you were talking about "apple juice" pong. I then imagined trying to play DS pong and how hard it wouold be. :)

It is hard, I have a 30-40% hitting rate! (and about half are lost on the first hit)

keehun 18-12-2009 00:12

Re: Driverstation Pong!
 
Anyone dare to post a picture?

Rion Atkinson 18-12-2009 10:35

Re: Driverstation Pong!
 
Just as a random thought. (I have not dared to mess with my team's DS.) I know people have created virtual Driver Stations. Would it be possible to put this game into the Virtual DS?

byteit101 18-12-2009 15:12

Re: Driverstation Pong!
 
Quote:

Originally Posted by Formerly Famous (Post 889002)
Just as a random thought. (I have not dared to mess with my team's DS.) I know people have created virtual Driver Stations. Would it be possible to put this game into the Virtual DS?

I think it can display the User Data, so yes.

John G 18-12-2009 20:03

Re: Driverstation Pong!
 
Quote:

It is hard, I have a 30-40% hitting rate! (and about half are lost on the first hit)
that's pretty good i guess. we should start up a new game, and devote half of thursday to having a DS pong tournament. -

slavik262 22-12-2009 23:35

Re: Driverstation Pong!
 
I have a stupid question...

Where are DriverStationLCD.h and DriverStationLCD.cpp coming from? I notice the official WPILib Header, but neither are in the latest version I'm aware of (3.1.1764). Should I be getting updates form somewhere besides the following site?

http://first.wpi.edu/FRC/frcupdates.html

byteit101 26-12-2009 20:12

Re: Driverstation Pong!
 
Quote:

Originally Posted by slavik262 (Post 890032)
I have a stupid question...

Where are DriverStationLCD.h and DriverStationLCD.cpp coming from? I notice the official WPILib Header, but neither are in the latest version I'm aware of (3.1.1764). Should I be getting updates form somewhere besides the following site?

http://first.wpi.edu/FRC/frcupdates.html

The WPI think tank site: http://thinktank.wpi.edu/article/144

byteit101 16-01-2010 16:31

Re: Driverstation Pong!
 
I (finally!) have a video of DS Pong:
http://thecatattack.org/DriverStationPong
I don't know if it will work on the classmate, but I would think so, because it has the status updates in the corner


All times are GMT -5. The time now is 01:13.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi