|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Trouble Printing to NetConsole
I've been having an interesting issue with printing data to the NetConsole using the standard cout<< function. When printing just one or two different reads, like this (from the end of our OperatorControl) then it works fine:
Code:
if (h%24 == 0){
*G = int(gyro->GetAngle());
cout<<("Gyroscope Angle: " && *G && "\n");
}
h++;
Wait(0.03); // wait for a motor update time
The code's been compiling just fine otherwise, but I can't imagine why this wouldn't work. Would the cRio somehow be overloaded by the few extra prints? Any help is appreciated! Last edited by SenorPotter : 25-02-2014 at 19:55. Reason: Realized I could wrap the code as a neat little code block |
|
#2
|
|||
|
|||
|
Re: Trouble Printing to NetConsole
Quote:
|
|
#3
|
|||||
|
|||||
|
Re: Trouble Printing to NetConsole
A few things:
I'm fairly certain modulus (%) works only on int... that could be causing some issues. (Though I think I see what you're doing (Trying to make this code execute once every 24 run-throughs) and that isn't the issue) You most likely are having issues at this line: Code:
*G = int(gyro->GetAngle()); Code:
delete G; G = int(gyro->GetAngle()); That cout statement looks... very... very... very strange... and it's mere existance looks to be the issue... Code:
cout<<("Gyroscope Angle: " && *G && "\n");
Code:
cout<<"Gyroscope Angle: "<<*G<<"\n"; If *G is an int, then use this: Code:
printf("Gyroscope Angle: %d\n", *G);
Last edited by Toa Circuit : 26-02-2014 at 15:45. Reason: Error in printf example code |
|
#4
|
|||
|
|||
|
Re: Trouble Printing to NetConsole
Thank you both, this is my first year really using C++ and I'm sure there are plenty of other inefficient problems in my code so far.
I'll make sure to try to use printf, and fix up my pointer obsession too... Thanks again for all your help! I'm sure I'll be coming back around fairly often. ![]() |
|
#5
|
|||
|
|||
|
Re: Trouble Printing to NetConsole
I haven't benchmarked this myself but I'm fairly sure that the performance gain you get from using C formatted string functions over the C++ ones isn't very significant.
Stack Overflow - Printf vs Cout Printf vs Cout - Google Groups Personally, I would use the stream classes to keep to C++ as closely as possible. They're trying to do fix WPILib to use C++ streams and such instead of the old C functions. They've done it for the most part. Alex Brinister |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|