00001 #include "darwin_camera_driver_node.h" 00002 #include "Camera.h" 00003 00004 DarwinCameraDriverNode::DarwinCameraDriverNode(ros::NodeHandle &nh) : 00005 iri_base_driver::IriBaseNodeDriver<DarwinCameraDriver>(nh), 00006 camera_manager(ros::NodeHandle(this->public_node_handle_)) 00007 { 00008 //init class attributes if necessary 00009 this->loop_rate_ = 10;//in [Hz] 00010 this->it=new image_transport::ImageTransport(this->public_node_handle_); 00011 00012 // [init publishers] 00013 this->camera_image_publisher_ = this->it->advertiseCamera("camera_image", 1); 00014 00015 // [init subscribers] 00016 00017 // [init services] 00018 00019 // [init clients] 00020 00021 // [init action servers] 00022 00023 // [init action clients] 00024 } 00025 00026 void DarwinCameraDriverNode::mainNodeThread(void) 00027 { 00028 Image *new_image=NULL; 00029 int i=0; 00030 00031 //lock access to driver if necessary 00032 this->driver_.lock(); 00033 00034 // [fill msg Header if necessary] 00035 //<publisher_name>.header.stamp = ros::Time::now(); 00036 //<publisher_name>.header.frame_id = "<publisher_topic_name>"; 00037 00038 // [fill msg structures] 00039 00040 00041 // [fill srv structure and make request to the server] 00042 00043 // [fill action structure and make request to the action server] 00044 00045 // get a frame from the camera 00046 new_image=this->driver_.get_image(); 00047 if(new_image!=NULL) 00048 { 00049 // configure Image message 00050 this->Image_msg_.encoding="rgb8"; 00051 this->Image_msg_.width=new_image->m_Width; 00052 this->Image_msg_.height=new_image->m_Height; 00053 this->Image_msg_.step=new_image->m_WidthStep; 00054 this->Image_msg_.data.resize(new_image->m_ImageSize); 00055 for(i=0;i<new_image->m_ImageSize;i++) 00056 this->Image_msg_.data[i]=new_image->m_ImageData[i]; 00057 00058 // [publish messages] 00059 this->Image_msg_.header.stamp = ros::Time::now(); 00060 this->camera_image_publisher_.publish(this->Image_msg_,this->camera_manager.getCameraInfo()); 00061 delete new_image; 00062 } 00063 //unlock access to driver if previously blocked 00064 this->driver_.unlock(); 00065 } 00066 00067 /* [subscriber callbacks] */ 00068 00069 /* [service callbacks] */ 00070 00071 /* [action callbacks] */ 00072 00073 /* [action requests] */ 00074 00075 void DarwinCameraDriverNode::postNodeOpenHook(void) 00076 { 00077 } 00078 00079 void DarwinCameraDriverNode::addNodeDiagnostics(void) 00080 { 00081 } 00082 00083 void DarwinCameraDriverNode::addNodeOpenedTests(void) 00084 { 00085 } 00086 00087 void DarwinCameraDriverNode::addNodeStoppedTests(void) 00088 { 00089 } 00090 00091 void DarwinCameraDriverNode::addNodeRunningTests(void) 00092 { 00093 } 00094 00095 void DarwinCameraDriverNode::reconfigureNodeHook(int level) 00096 { 00097 } 00098 00099 DarwinCameraDriverNode::~DarwinCameraDriverNode(void) 00100 { 00101 // [free dynamic memory] 00102 } 00103 00104 /* main function */ 00105 int main(int argc,char *argv[]) 00106 { 00107 return driver_base::main<DarwinCameraDriverNode>(argc, argv, "darwin_camera_driver_node"); 00108 }