|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
Re: Using Keyboard to Drive
You would have a lot more control if you used the mouse.
|
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
|||||
|
|||||
|
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.
|
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||||
|
|||||
|
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. |
|
#7
|
|||||
|
|||||
|
Re: Using Keyboard to Drive
Reminds me of computer games we used to play with our kids 15-20 years ago.
![]() |
|
#8
|
||||
|
||||
|
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...
|
|
#9
|
|||
|
|||
|
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 |
|
#10
|
|||
|
|||
|
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!
|
|
#11
|
||||
|
||||
|
Re: Using Keyboard to Drive
Quote:
Code:
addKeyListener(this); 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) {}
|
|
#12
|
|||
|
|||
|
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?
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|