For Valentine's Day, I will spoiler with a spring bouquet.
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 6 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 08-02-2014, 12:49
fiberdrive fiberdrive is offline
Registered User
FRC #1351
 
Join Date: Feb 2014
Location: San Jose
Posts: 6
fiberdrive is an unknown quantity at this point
Using Keyboard to Drive

Hey Guys,
I am a rookie programmer on my team and was assigned to work on using arrow keys to drive. I was wondering if anybody has experience and what they used to make their arrow key drive work. I have tried many times, but could not succeed. Any help on making keyboard drive work in C++ would be great. Thanks.
Reply With Quote
  #2   Spotlight this post!  
Unread 08-02-2014, 13:44
brycen66 brycen66 is offline
Registered User
FRC #1678 (Citrus Circuits)
Team Role: Electrical
 
Join Date: Jan 2013
Rookie Year: 2011
Location: United States
Posts: 34
brycen66 is just really nicebrycen66 is just really nicebrycen66 is just really nicebrycen66 is just really nice
Re: Using Keyboard to Drive

You would have a lot more control if you used the mouse.
Reply With Quote
  #3   Spotlight this post!  
Unread 08-02-2014, 13:52
fiberdrive fiberdrive is offline
Registered User
FRC #1351
 
Join Date: Feb 2014
Location: San Jose
Posts: 6
fiberdrive is an unknown quantity at this point
Re: Using Keyboard to Drive

We were using arrow keys to test the robot,not to use in the competition. We wanted to use arrow key for non-variable drive. Thanks for your input, however.
Reply With Quote
  #4   Spotlight this post!  
Unread 08-02-2014, 23:16
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Using Keyboard to Drive

We put some keyboard control features on our robot last year. The general scheme was to read the keys in a LabVIEW Dashboard program and send them to the robot using Smart Dashboard variables. The robot can read those variables using any of the supported programming languages.
Reply With Quote
  #5   Spotlight this post!  
Unread 10-02-2014, 18:22
fiberdrive fiberdrive is offline
Registered User
FRC #1351
 
Join Date: Feb 2014
Location: San Jose
Posts: 6
fiberdrive is an unknown quantity at this point
Re: Using Keyboard to Drive

Could you please upload the Vi you used to get and stream keyboard input to the robot? I am a beginner developer with LabView and understand the concept. The C++ code used to retrieve the data would be nice as well. Thank you very much.
Reply With Quote
  #6   Spotlight this post!  
Unread 10-02-2014, 22:01
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Using Keyboard to Drive

The functions used in the Dashboard to read the keyboard are in the Connectivity -> Input Device Control function palette.

Use the Initialize Keyboard function to get a "device ID" output, and pass that into the loop that reads the keyboard using the Acquire Input Data function. The result will be an array of keys being pressed. If the length of the array is zero, no keys are pressed. If you don't want to be able to handle multiple keys pressed at the same time, just use an Index Array function to pick out the first element of the array.

The Smart Dashboard functions used to send data to the robot are in the WPI Robotics Library -> Dashboard function palette.

Use the SD Write String function to put the value of the key being pressed (or a null string if no keys are pressed) into a Smart Dashboard variable.

In the C++ code, use the NetworkTables support to read the value of the variable out of the SmartDashboard table. http://wpilib.screenstepslive.com/s/...client-pc-side gives a lot of information and some example code for using NetworkTables.
Reply With Quote
  #7   Spotlight this post!  
Unread 11-02-2014, 19:02
GaryVoshol's Avatar
GaryVoshol GaryVoshol is offline
Cogito ergo arbitro
no team
 
Join Date: Aug 2005
Rookie Year: 2000
Location: Royal Oak, MI
Posts: 5,767
GaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond reputeGaryVoshol has a reputation beyond repute
Re: Using Keyboard to Drive

Reminds me of computer games we used to play with our kids 15-20 years ago.
__________________
(since 2004)
Reply With Quote
  #8   Spotlight this post!  
Unread 11-02-2014, 23:48
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
Re: Using Keyboard to Drive

My team really wanted to do this, too, but we got worried about potential operator errors and haven't really gone through with it yet. The basic idea for us was to create a custom dashboard (using Processing) and having that take the WASDShift/arrow keys/mouse commands and send them to the robot via NetworkTables (we got the programme written but never tested it). The issue we were worried about was the driver accidentally pressing the space bar or return key while driving and potentially disabling the robot mid-match. In order to solve this potential issue, we were thinking of having something like a Raspberry Pi in-between a USB keyboard and the DriverStation computer which would take the input from the keyboard and send it to the DriverStation like a joystick. We never tried that out either, though...
Reply With Quote
  #9   Spotlight this post!  
Unread 13-02-2014, 07:34
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,780
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Using Keyboard to Drive

If the FMS is present, the spacebar doesn't estop the robot, the big red mushroom button does. When plugged into the FMS, only the F1 key does anything on the DS, and it scans for new joysticks and redoes the joystick connections.

Greg McKaskle
Reply With Quote
  #10   Spotlight this post!  
Unread 15-02-2014, 22:54
Platypi3 Platypi3 is offline
Registered User
FRC #5003
 
Join Date: Feb 2014
Location: Wisconsin
Posts: 2
Platypi3 is an unknown quantity at this point
Re: Using Keyboard to Drive

Hello, similar question...how would you program the arrow key control in Java? Sorry, I'm also a rookie, so a (simplified) explanation would be greatly appreciated!
Reply With Quote
  #11   Spotlight this post!  
Unread 15-02-2014, 23:29
ekapalka's Avatar
ekapalka ekapalka is offline
Registered User
FRC #3216
 
Join Date: Dec 2012
Location: Bermuda
Posts: 277
ekapalka has a spectacular aura aboutekapalka has a spectacular aura about
Re: Using Keyboard to Drive

Quote:
Originally Posted by Platypi3 View Post
Hello, similar question...how would you program the arrow key control in Java? Sorry, I'm also a rookie, so a (simplified) explanation would be greatly appreciated!
Simplified. Of course :P What I think you want to do is to add a KeyListener to your custom driverstation. This code is out of context and won't work as stand alone. You'll have to make your class implement a keyListener (i.e "public class myClass implements KeyListener { }" ) and have the following line in the constructor:
Code:
addKeyListener(this);
This is what the actual listening portion would look like:
Code:
public void keyPressed(KeyEvent ke) {
	if (ke.getKeyCode() == KeyEvent.VK_UP) {/*instruction for Up-key*/} //VK_UP is a pre-defined constant value
	else if (ke.getKeyCode() == KeyEvent.VK_DOWN) {/*instruction for Down-key*/} 
	else if (ke.getKeyCode() == KeyEvent.VK_LEFT) {/*instruction for Left-key*/}
	else if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {/*instruction for Right-key*/}
}
public void keyTyped(KeyEvent ke) {}
public void keyReleased(KeyEvent ke) {}
Whatever I've said that didn't make sense should be remedied by looking at the example code found here.
Reply With Quote
  #12   Spotlight this post!  
Unread 16-02-2014, 22:05
Platypi3 Platypi3 is offline
Registered User
FRC #5003
 
Join Date: Feb 2014
Location: Wisconsin
Posts: 2
Platypi3 is an unknown quantity at this point
Re: Using Keyboard to Drive

Hey thanks! The key listener tutorial was really helpful. I think I got the listening part, but I can't figure out how to add the actual keyListener... Er...do I need to import something special for it?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 05:14.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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