Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Using Keyboard to Drive (http://www.chiefdelphi.com/forums/showthread.php?t=126048)

fiberdrive 08-02-2014 12:49

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.

brycen66 08-02-2014 13:44

Re: Using Keyboard to Drive
 
You would have a lot more control if you used the mouse.

fiberdrive 08-02-2014 13:52

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.

Alan Anderson 08-02-2014 23:16

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.

fiberdrive 10-02-2014 18:22

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.

Alan Anderson 10-02-2014 22:01

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.

GaryVoshol 11-02-2014 19:02

Re: Using Keyboard to Drive
 
Reminds me of computer games we used to play with our kids 15-20 years ago. :rolleyes:

ekapalka 11-02-2014 23:48

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...

Greg McKaskle 13-02-2014 07:34

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

Platypi3 15-02-2014 22:54

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!

ekapalka 15-02-2014 23:29

Re: Using Keyboard to Drive
 
Quote:

Originally Posted by Platypi3 (Post 1343771)
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.

Platypi3 16-02-2014 22:05

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?


All times are GMT -5. The time now is 12:11.

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