Go to Post Everything is possible. Some things are just harder to do than others. - vigkvagkv2 [more]
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 Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 25-02-2014, 19:07
SenorPotter SenorPotter is offline
Student Programmer/Electrical
AKA: Daniel
FRC #3880 (Tiki Techs)
Team Role: Programmer
 
Join Date: Feb 2014
Rookie Year: 2012
Location: United States
Posts: 4
SenorPotter is an unknown quantity at this point
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
But whenever I try to print a few more (I'll attach the second example, it's a bit cumbersome to look at in this format), I get an error from NetConsole about a kernel issue, the cRio crashes, and we have to reboot the robot and take away the cout's to make it work again.
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!
Attached Files
File Type: txt Won't Print.txt (625 Bytes, 15 views)

Last edited by SenorPotter : 25-02-2014 at 19:55. Reason: Realized I could wrap the code as a neat little code block
Reply With Quote
  #2   Spotlight this post!  
Unread 26-02-2014, 00:53
Joe Hershberger Joe Hershberger is offline
National Instruments
AKA: jhersh
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: Nov 2005
Rookie Year: 1997
Location: Austin, TX
Posts: 148
Joe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to allJoe Hershberger is a name known to all
Re: Trouble Printing to NetConsole

Quote:
Originally Posted by SenorPotter View Post
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
But whenever I try to print a few more (I'll attach the second example, it's a bit cumbersome to look at in this format), I get an error from NetConsole about a kernel issue, the cRio crashes, and we have to reboot the robot and take away the cout's to make it work again.
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!
I've always used printf() with no issues. It is surprising that you are having this issue, but printf() could be a workaround.
Reply With Quote
  #3   Spotlight this post!  
Unread 26-02-2014, 15:44
Toa Circuit's Avatar
Toa Circuit Toa Circuit is offline
Thaddeus Maximus
AKA: Thad Hughes
FRC #4213 (MetalCow Robotics)
Team Role: Leadership
 
Join Date: Nov 2012
Rookie Year: 2012
Location: Shirley, IL
Posts: 131
Toa Circuit is an unknown quantity at this point
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());
I believe what you're doing here is creating a new pointer to an int (With the int()) and passing that into the value of *G. I think what you want to do is either remove the asterisk (assign the new pointer to G, not the value pointed to by G). You also need to remember to delete G each time. So you should end with something like this:
Code:
delete G;
G = int(gyro->GetAngle());
I believe the easier option is to remove the pointer-ness altogether. Direct access of data isn't bad.

That cout statement looks... very... very... very strange... and it's mere existance looks to be the issue...

Code:
 cout<<("Gyroscope Angle: " && *G && "\n");
In 5-6 years of C++, I've never seen anything like that. (I've thought && was soley a boolean operator and couldn't be used on strings, especially in the way it is here.) I think you're trying to write something like this:

Code:
cout<<"Gyroscope Angle: "<<*G<<"\n";
Though I've noticed execution speed issues, formatting mishaps, with cout<<, and tend to use printf.
If *G is an int, then use this:

Code:
printf("Gyroscope Angle: %d\n", *G);
If *G is a double/float, replace the %d with %f.
__________________

2012 Head of Programming and Electrical
2013-14 Overall Team Captain and Programming Head
2012-14 Mentor of FLL Team Power Surge
2014 Dean's List Finalist
2014 CIR Xerox Creativity Award
Webpage

Last edited by Toa Circuit : 26-02-2014 at 15:45. Reason: Error in printf example code
Reply With Quote
  #4   Spotlight this post!  
Unread 26-02-2014, 19:41
SenorPotter SenorPotter is offline
Student Programmer/Electrical
AKA: Daniel
FRC #3880 (Tiki Techs)
Team Role: Programmer
 
Join Date: Feb 2014
Rookie Year: 2012
Location: United States
Posts: 4
SenorPotter is an unknown quantity at this point
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 03-03-2014, 09:11
AlexBrinister AlexBrinister is offline
Registered User
AKA: Alex Brinister
FRC #1768 (RoboChiefs)
Team Role: Alumni
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Bolton, MA
Posts: 93
AlexBrinister will become famous soon enough
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
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 04:50.

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