Go to Post Is it legal to build 2 robots? yes. Is it crazy to do so? maybe. - Andy Baker [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 04-04-2012, 13:14
enrique's Avatar
enrique enrique is offline
Registered User
FRC #1251 (Tech Tigers)
Team Role: Electrical
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Florida
Posts: 87
enrique will become famous soon enough
Send a message via Yahoo to enrique
Smile Declaring the AxisCamera as a module level variable.

What would be the proper way to declare the AxisCamera class as a module level so that autonomous and teleop can use the same connection and we don't have to wait for a connection twice?

AxisCamera &camera = AxisCamera::GetInstance("10.12.51.11");
Reply With Quote
  #2   Spotlight this post!  
Unread 04-04-2012, 15:30
bob.wolff68's Avatar
bob.wolff68 bob.wolff68 is offline
Da' Mentor Man
FRC #1967
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2007
Location: United States
Posts: 157
bob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nicebob.wolff68 is just really nice
Re: Declaring the AxisCamera as a module level variable.

As a member variable to your SimpleRobot class, define AxisCamera& camera; Then in the initializers, initialize it there. For instance...

Code:
#define CAMERA_IP "10.19.67.11"

class RobotDemo : public SimpleRobot
{
  AxisCamera& camera;
  Joystick driver;    // driving Joystick for driver
public:
  RobotDemo(void) :
	driver(1),
	camera(AxisCamera::GetInstance(CAMERA_IP))
  {
	// Robot constructor
  }

// ....
__________________
~~~~~~~~~~~~~~~~~~~
Bob Wolff - Software from the old-school
Mentor / C / C++ guy
Team 1967 - The Janksters - San Jose, CA
Reply With Quote
  #3   Spotlight this post!  
Unread 05-04-2012, 00:09
enrique's Avatar
enrique enrique is offline
Registered User
FRC #1251 (Tech Tigers)
Team Role: Electrical
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Florida
Posts: 87
enrique will become famous soon enough
Send a message via Yahoo to enrique
Re: Declaring the AxisCamera as a module level variable.

awesome, thanks
Reply With Quote
  #4   Spotlight this post!  
Unread 12-04-2012, 10:59
rbmj rbmj is offline
Registered User
FRC #0612 (Chantilly Robotics)
Team Role: Alumni
 
Join Date: Apr 2011
Rookie Year: 2011
Location: DC Area/Fairfax County
Posts: 192
rbmj is a jewel in the roughrbmj is a jewel in the roughrbmj is a jewel in the rough
Re: Declaring the AxisCamera as a module level variable.

Since AxisCamera is a singleton, you can just call AxisCamera::GetInstance(NULL). It doesn't reconnect. Use the SOURCE

See?
Code:
AxisCamera &AxisCamera::GetInstance(const char *cameraIP)
{
	if (NULL == _instance) //_instance is a static variable of type AxisCamera*
	{
		_instance = new AxisCamera(cameraIP);

		_instance->m_videoServer = new PCVideoServer();
	}

	return *_instance;
}
Just make sure you're not the first one to call GetInstance, otherwise you're screwed. Static initialization order fiasco anyone? Yay intermittent segfaults!

Another way is to just have an inline function:

Code:
static inline AxisCamera& camera() {
   static AxisCamera& c = AxisCamera::GetInstance(IP);
   return c;
}
Yes it's nice to have encapsulation, but when the camera is a global singleton *anyway*, what's the point?

Last edited by rbmj : 12-04-2012 at 11:01.
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 14:36.

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