![]() |
Printing Float to Dashboard
I'm looking at printing the value of the joystick y axis to the screen.
Code:
DriverStation *ds;Also is there string concatenation that you can add two strings together?? "Left Drive: " + driverController->GetY() |
Re: Printing Float to Dashboard
Quote:
If you want to write a float to a string you can use some of the following methods. Code:
float my_float = 123.456f; |
Re: Printing Float to Dashboard
We ran into this exact same problem yesterday and after searching online for an hour and getting nowhere on the cocanate issue i finally found this link which was immensely helpful.
http://www.cppreference.com/wiki/c/io/printf Like the poster above me showed, I kept finding convoluted methods to do something that is extremely trivial in other program languages. After evaluating the DriverStationLCD class and seeing it was probably inheriting most of its features from the C++ printf class I figured I would give the %f thing in the link above a try. When we tried it this evening it worked perfect. Your code might look like this as an example: dsLCD->Printf(DriverStationLCD::kUser_Line4, 1,"Joystick Y axis: %f", driveController->GetY()); The %f is a placeholder waiting for a float variable to be passed. Hope this helps you out. |
Re: Printing Float to Dashboard
Quote:
|
Re: Printing Float to Dashboard
For reference the following code DOES work :-)
Code:
char line_buffer[22]; |
Re: Printing Float to Dashboard
Quote:
The best way is to use the Printf() method as it was intended: put the format string in the argument list, followed by your variable(s): Code:
dsLCD->Printf(DriverStationLCD::kUser_Line2, 1, "Y: %.2f", driveController->GetY());HTH. |
Re: Printing Float to Dashboard
Quote:
Please remember that when a person asks for help, he has made himself vulnerable and doesn't want to be attacked, he wants help. I tried to help him with the thing that worked for me when I ran into this exact problem. I do appreciate the correction on your part and I will refer to printf as a function from now on. Just remember gracious professionalism is the overriding goal of FIRST please. |
Re: Printing Float to Dashboard
I wonder why they decided to use printf instead of the C++ streams. this would be much easier, and more modular, you don't need to know what you are putting in, and you could even (if it implements it) output a whole joystick
dsLCD.Printf(line,collum, "JoyY: %f",stick.GetY); vs dsLCD(line,collum)<<"JoyY:"<<stick.GetY(); |
Re: Printing Float to Dashboard
Quote:
Also using an std::stringstream would be a great idea. However, I would just remove the column index completely as you can use seekp(). |
Re: Printing Float to Dashboard
Quote:
Especially for a function like writing to the Driver Station, you want to keep things as simple and fast as possible, so as not to slow down or impede communications with the robot. So sometimes the old ways are better not because they are "familiar", but instead are "just better" for the particular task at hand. Now you kids get off my lawn with that crazy "<<" stuff! :D |
Re: Printing Float to Dashboard
Quote:
|
Re: Printing Float to Dashboard
Quote:
You will notice that nowhere else in the WPILib source code is either WPILib.h or iostream.h included. The iostream.h inclusion in WPILib.h is simply there for convenience, not because it is required. I'm really not against the use of iostream.h (or <<iostream>>) where it makes sense. It's just that on our robots, the few places where it might actually be useful do not justify the overhead required. |
Re: Printing Float to Dashboard
Frankly, I am a little lost on what's going on. I searched Chief Delphi and found this thread (to my joy::safety::).
I wonder where the program prints to on the driver station dashboard? Is it under the "User Messages" box? (I am a freshman, so please explain :]) THANKS!:) |
Re: Printing Float to Dashboard
The standard out is written to the NetConsole. Look at C++ documentation for details.
|
| All times are GMT -5. The time now is 12:13. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi