|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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"); |
|
#2
|
||||
|
||||
|
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
}
// ....
|
|
#3
|
||||
|
||||
|
Re: Declaring the AxisCamera as a module level variable.
awesome, thanks
|
|
#4
|
|||
|
|||
|
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;
}
Another way is to just have an inline function: Code:
static inline AxisCamera& camera() {
static AxisCamera& c = AxisCamera::GetInstance(IP);
return c;
}
Last edited by rbmj : 12-04-2012 at 11:01. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|