Go to Post I have caught a very strong case of FIRST fever. - weinbergmath [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 21-12-2011, 14:51
Stonemotmot Stonemotmot is offline
Registered User
FRC #0486
 
Join Date: Sep 2011
Location: United States, Pa
Posts: 53
Stonemotmot is an unknown quantity at this point
System.out.println help

Hello, I am trying to get my encoder value to print to the net console.
The only line giving me an error is.

System.out.println(encoder1.Get());

the error console says System is not defined. Any help would be appreciated.
Reply With Quote
  #2   Spotlight this post!  
Unread 21-12-2011, 16:41
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 671
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: System.out.println help

Try this instead:
Code:
printf("Encoder1=%d", encoder1.Get());
__________________
Reply With Quote
  #3   Spotlight this post!  
Unread 21-12-2011, 16:48
Radical Pi Radical Pi is offline
Putting the Jumper in the Bumper
AKA: Ian Thompson
FRC #0639 (Code Red Robotics)
Team Role: Programmer
 
Join Date: Jan 2010
Rookie Year: 2010
Location: New York
Posts: 655
Radical Pi has a spectacular aura aboutRadical Pi has a spectacular aura aboutRadical Pi has a spectacular aura about
Re: System.out.println help

Judging by the use of a capital in Get(), and that you posted to the C++ forum, I'm assuming you're using C++. System.out.println isn't a thing in C, the equivalent is printf(). An example:
Code:
// Top of file
#include <stdio.h>
...
// Inside your function
printf("%d\n", encoder1.Get());
The %d means we have an integer to print, and \n means to add a newline afterwards. Look here for more info

One thing to note, however, is that excessive use of printf can sometimes flood the network and if this is being called every iteration, you'll get a ton of text in netconsole. I prefer to use the DriverStationLCD class, which will put the text on the right of the Operation tab of the driver station.
Code:
void OperatorControl(void)
{
	DriverStationLCD *dslcd = DriverStationLCD::GetInstance();
	...
	while (IsOperatorControl())
	{
		dslcd->Clear();
		...
		dslcd->Printf(DriverStationLCD::kUser_Line1, 1, "Left Encoder: %d", encoder1->Get());
		...
		dslcd->UpdateLCD();
	}
}
kUser_Line1 tells it which line to go on, 1 is the column to start in (generally 1), and the rest of it is called just like the regular printf(). Make sure you include the Clear() at the top of your loop, otherwise you can get some weird stuff in the text box.
__________________

"To have no errors would be life without meaning. No strugle, no joy"
"A network is only as strong as it's weakest linksys"
Reply With Quote
  #4   Spotlight this post!  
Unread 22-12-2011, 12:52
Stonemotmot Stonemotmot is offline
Registered User
FRC #0486
 
Join Date: Sep 2011
Location: United States, Pa
Posts: 53
Stonemotmot is an unknown quantity at this point
Re: System.out.println help

Thanks, so am i correct in understanding that println is a java command not c++ which uses printf?
I will try this thanks for the help.
Reply With Quote
  #5   Spotlight this post!  
Unread 22-12-2011, 13:14
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: System.out.println help

Quote:
Originally Posted by Stonemotmot View Post
Thanks, so am i correct in understanding that println is a java command not c++ which uses printf?
I will try this thanks for the help.
It's because printf doesn't have a class to go along with it. In Java, everything must have a class (You essentially can't call a function without a . before it), but in C++ classes are optional.
Reply With Quote
  #6   Spotlight this post!  
Unread 11-01-2012, 23:31
hdastwb's Avatar
hdastwb hdastwb is offline
Registered User
AKA: Daniel Woodworth
FRC #1677 (Quantum Ninjas)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Kalamazoo, MI
Posts: 8
hdastwb is an unknown quantity at this point
Re: System.out.println help

Actually, in most variants of C++ we've got things called "streams" that greatly enhance the readability and flexibility of code by use of the overloaded bitshift operator- for instance:
Code:
#include <iostream>

. . .

using namespace std;

. . .

cout << encoder1.Get() << endl;
Printf's really a C thing, but it is available in C++ if one needs fancier formatting or if one is allergic to the standard library for whatever reason. Then again, I can't speak for WindRiver/Diab- I still haven't gotten anything to run on that thing. It appears that they do have the simulator in this year's version (as opposed to last year where LabVIEW was the hands-down choice because of my team's large amount of code needing debugging and relative lack of robot), yet the installation of the C++ update seems to have failed probably due to the whole 32/64 bit thing. . .
Reply With Quote
  #7   Spotlight this post!  
Unread 12-01-2012, 15:57
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: System.out.println help

it does work in windriver if you use cerr instead of cout (or if you reasign the streams)

EDIT: the C++ streams, that is
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib

Last edited by byteit101 : 12-01-2012 at 16:14. Reason: clarifying
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 03:06.

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