本文整理汇总了C++中DJI_lock类的典型用法代码示例。如果您正苦于以下问题:C++ DJI_lock类的具体用法?C++ DJI_lock怎么用?C++ DJI_lock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DJI_lock类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: my_callback
int my_callback(int data_type, int data_len, char *content)
{
printf("enter callback..\n");
g_lock.enter();
if (e_image == data_type && NULL != content)
{
printf("callback: type is image..\n");
image_data data;
memcpy((char*)&data, content, sizeof(data));
memcpy(g_imleft.data, data.m_greyscale_image_left[selected_vbus], IMAGE_SIZE);
memcpy(g_imright.data, data.m_greyscale_image_right[selected_vbus], IMAGE_SIZE);
memcpy(g_depth.data, data.m_depth_image[selected_vbus], IMAGE_SIZE * 2);
}
g_lock.leave();
g_event.set_event();
return 0;
}
示例2: my_callback
int my_callback(int data_type, int data_len, char *content)
{
g_lock.enter();
/* image data */
/* if (e_image == data_type && NULL != content)
{
image_data* data = (image_data*)content;
if ( data->m_greyscale_image_left[CAMERA_ID] ){
memcpy(g_greyscale_image_left.data, data->m_greyscale_image_left[CAMERA_ID], IMAGE_SIZE);
imshow("left", g_greyscale_image_left);
// publish left greyscale image
cv_bridge::CvImage left_8;
g_greyscale_image_left.copyTo(left_8.image);
left_8.header.frame_id = "guidance";
left_8.header.stamp = ros::Time::now();
left_8.encoding = sensor_msgs::image_encodings::MONO8;
left_image_pub.publish(left_8.toImageMsg());
}
if ( data->m_greyscale_image_right[CAMERA_ID] ){
memcpy(g_greyscale_image_right.data, data->m_greyscale_image_right[CAMERA_ID], IMAGE_SIZE);
imshow("right", g_greyscale_image_right);
// publish right greyscale image
cv_bridge::CvImage right_8;
g_greyscale_image_right.copyTo(right_8.image);
right_8.header.frame_id = "guidance";
right_8.header.stamp = ros::Time::now();
right_8.encoding = sensor_msgs::image_encodings::MONO8;
right_image_pub.publish(right_8.toImageMsg());
}
if ( data->m_depth_image[CAMERA_ID] ){
memcpy(g_depth.data, data->m_depth_image[CAMERA_ID], IMAGE_SIZE * 2);
g_depth.convertTo(depth8, CV_8UC1);
imshow("depth", depth8);
//publish depth image
cv_bridge::CvImage depth_16;
g_depth.copyTo(depth_16.image);
depth_16.header.frame_id = "guidance";
depth_16.header.stamp = ros::Time::now();
depth_16.encoding = sensor_msgs::image_encodings::MONO16;
depth_image_pub.publish(depth_16.toImageMsg());
}
key = waitKey(1);
}
/* imu */
/*
if ( e_imu == data_type && NULL != content )
{
imu *imu_data = (imu*)content;
printf( "frame index: %d, stamp: %d\n", imu_data->frame_index, imu_data->time_stamp );
printf( "imu: [%f %f %f %f %f %f %f]\n", imu_data->acc_x, imu_data->acc_y, imu_data->acc_z, imu_data->q[0], imu_data->q[1], imu_data->q[2], imu_data->q[3] );
// publish imu data
geometry_msgs::TransformStamped g_imu;
g_imu.header.frame_id = "guidance";
g_imu.header.stamp = ros::Time::now();
g_imu.transform.translation.x = imu_data->acc_x;
g_imu.transform.translation.y = imu_data->acc_y;
g_imu.transform.translation.z = imu_data->acc_z;
g_imu.transform.rotation.w = imu_data->q[0];
g_imu.transform.rotation.x = imu_data->q[1];
g_imu.transform.rotation.y = imu_data->q[2];
g_imu.transform.rotation.z = imu_data->q[3];
imu_pub.publish(g_imu);
}
*/
/* velocity */
/*
if ( e_velocity == data_type && NULL != content )
{
velocity *vo = (velocity*)content;
printf( "frame index: %d, stamp: %d\n", vo->frame_index, vo->time_stamp );
printf( "vx:%f vy:%f vz:%f\n", 0.001f * vo->vx, 0.001f * vo->vy, 0.001f * vo->vz );
// publish velocity
geometry_msgs::Vector3Stamped g_vo;
g_vo.header.frame_id = "guidance";
g_vo.header.stamp = ros::Time::now();
g_vo.vector.x = 0.001f * vo->vx;
g_vo.vector.y = 0.001f * vo->vy;
g_vo.vector.z = 0.001f * vo->vz;
velocity_pub.publish(g_vo);
}
*/
/* obstacle distance */
if ( e_obstacle_distance == data_type && NULL != content )
{
obstacle_distance *oa = (obstacle_distance*)content;
printf( "frame index: %d, stamp: %d\n", oa->frame_index, oa->time_stamp );
printf( "obstacle distance:" );
for ( int i = 0; i < CAMERA_PAIR_NUM; ++i )
{
printf( " %f ", 0.01f * oa->distance[i] );
}
printf( "\n" );
// publish obstacle distance
sensor_msgs::LaserScan g_oa;
//.........这里部分代码省略.........
示例3: guidance_callback
int guidance_callback(int data_type, int data_len, char *content)
{
g_lock.enter();
if(e_image == data_type && NULL!=content)
{
printf("Success..\n");
image_data image;
memcpy((char*)&image,content,sizeof(image));
printf("frame index:%d, time stamp:%d\n",image.frame_index,image.time_stamp);
for(int d=0;d<CAMERA_PAIR_NUM;d++)
{
if(image.m_greyscale_image_left[d])
{
memcpy(g_greyscale_image_left.data, image.m_greyscale_image_left[d],IMAGE_SIZE);
vector<Point2f> nextleftpts,kpts;
if(prevleftpts.size()<MIN_FEATURES)
{
//control input
}
else if(frame_num>0)
{
//vector<CvPoint2D32f> nextleftpts;
vector<uchar> status;
vector<float> error;
vector<Mat> nextleftpyr,prevleftpyr;
buildOpticalFlowPyramid(prevleftimg, prevleftpyr, Size(7,7), 4);
buildOpticalFlowPyramid(g_greyscale_image_left, nextleftpyr, Size(7,7), 4);
CvTermCriteria optical_flow_termination_criteria
= cvTermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, 0.1 );
calcOpticalFlowPyrLK(prevleftpyr, nextleftpyr, prevleftpts, nextleftpts, status, error,Size(7,7),4,optical_flow_termination_criteria,OPTFLOW_LK_GET_MIN_EIGENVALS);
//drawing featues
Mat left_mask(g_greyscale_image_left.size(),CV_8UC3);
cvtColor(g_greyscale_image_left, left_mask, CV_GRAY2BGR);
for(size_t i=0;i<nextleftpts.size();i++)
{
if(nextleftpts[i].x>=0 && nextleftpts[i].x<=WIDTH && nextleftpts[i].y>=0 && nextleftpts[i].y<=HEIGHT)
{
CvScalar line_color; line_color = CV_RGB(255,0,0);
//int line_thickness = 1;
CvPoint p,q;
p.x = (int) prevleftpts[i].x;
p.y = (int) prevleftpts[i].y;
q.x = (int) nextleftpts[i].x;
q.y = (int) nextleftpts[i].y;
// double angle; angle = atan2( (double) p.y - q.y, (double) p.x - q.x );
// double hypotenuse; hypotenuse = sqrt( pow((p.y - q.y),2) + pow((p.x - q.x),2) );
//
// //scale the line by a factor of 3
// q.x = (int) (p.x - 2 * hypotenuse * cos(angle));
// q.y = (int) (p.y - 2 * hypotenuse * sin(angle));
arrowedLine(left_mask, p, q, line_color);
//cvLine( &left_mask, p, q, line_color, line_thickness, CV_AA, 0 );
// p.x = (int) (q.x + 9 * cos(angle + pi / 4));
// p.y = (int) (q.y + 9 * sin(angle + pi / 4));
// cvLine( &prevleftimg, p, q, line_color, line_thickness, CV_AA, 0 );
// p.x = (int) (q.x + 9 * cos(angle - pi / 4));
// p.y = (int) (q.y + 9 * sin(angle - pi / 4));
// cvLine( &prevleftimg, p, q, line_color, line_thickness, CV_AA, 0 );
circle(left_mask, nextleftpts[i], 2, Scalar(0,255,0),-1);
kpts.push_back(nextleftpts[i]);
}
}
imshow("left", left_mask);
moveWindow("left", 0, 0);
}
if(frame_num>0)
{
if(nextleftpts.size()<=MIN_FEATURES)
{
goodFeaturesToTrack(g_greyscale_image_left, prevleftpts, MAX_FEATURES, QUALITY_EIGVALUE, MIN_DISTANCE);
}
else
{
prevleftpts.assign(kpts.begin(), kpts.end());
}
}
g_greyscale_image_left.copyTo(prevleftimg);
}
if(image.m_greyscale_image_right[d])
{
memcpy(g_greyscale_image_right.data, image.m_greyscale_image_right[d],IMAGE_SIZE);
//.........这里部分代码省略.........
示例4: my_callback
int my_callback(int data_type, int data_len, char *content)
{
g_lock.enter();
/* image data */
if (e_image == data_type && NULL != content)
{
image_data* data = (image_data*)content;
dji_guidance::multi_image msg;
// forward facing guidance sensor is disabled for now...
//msg.images.push_back(create_image_message(data, e_vbus1));
msg.images.push_back(create_image_message(data, e_vbus2));
msg.images.push_back(create_image_message(data, e_vbus3));
msg.images.push_back(create_image_message(data, e_vbus4));
//msg.images.push_back(create_image_message(data, e_vbus5));
image_pub.publish(msg);
std::cout << "published " << msg.images.size() << " images" << std::endl;
}
/* imu */
if ( e_imu == data_type && NULL != content )
{
imu *imu_data = (imu*)content;
// printf( "frame index: %d, stamp: %d\n", imu_data->frame_index, imu_data->time_stamp );
// printf( "imu: [%f %f %f %f %f %f %f]\n", imu_data->acc_x, imu_data->acc_y, imu_data->acc_z, imu_data->q[0], imu_data->q[1], imu_data->q[2], imu_data->q[3] );
// publish imu data
geometry_msgs::TransformStamped g_imu;
g_imu.header.frame_id = "guidance";
g_imu.header.stamp = ros::Time::now();
g_imu.transform.translation.x = imu_data->acc_x;
g_imu.transform.translation.y = imu_data->acc_y;
g_imu.transform.translation.z = imu_data->acc_z;
g_imu.transform.rotation.w = imu_data->q[0];
g_imu.transform.rotation.x = imu_data->q[1];
g_imu.transform.rotation.y = imu_data->q[2];
g_imu.transform.rotation.z = imu_data->q[3];
imu_pub.publish(g_imu);
}
/* velocity */
if ( e_velocity == data_type && NULL != content )
{
velocity *vo = (velocity*)content;
// printf( "frame index: %d, stamp: %d\n", vo->frame_index, vo->time_stamp );
// printf( "vx:%f vy:%f vz:%f\n", 0.001f * vo->vx, 0.001f * vo->vy, 0.001f * vo->vz );
// publish velocity
geometry_msgs::Vector3Stamped g_vo;
g_vo.header.frame_id = "guidance";
g_vo.header.stamp = ros::Time::now();
g_vo.vector.x = 0.001f * vo->vx;
g_vo.vector.y = 0.001f * vo->vy;
g_vo.vector.z = 0.001f * vo->vz;
velocity_pub.publish(g_vo);
}
g_lock.leave();
g_event.set_event();
return 0;
}
示例5: my_callback
int my_callback(int data_type, int data_len, char *content)
{
g_lock.enter();
/* image data
if (e_image == data_type && NULL != content)
{
image_data data;
memcpy((char*)&data, content, sizeof(data));
memcpy(g_greyscale_image_left.data, data.m_greyscale_image_left[CAMERA_ID], IMAGE_SIZE);
memcpy(g_greyscale_image_right.data, data.m_greyscale_image_right[CAMERA_ID], IMAGE_SIZE);
memcpy(g_depth.data, data.m_depth_image[CAMERA_ID], IMAGE_SIZE * 2);
Mat depth8(HEIGHT, WIDTH, CV_8UC1);
g_depth.convertTo(depth8, CV_8UC1);
imshow("left", g_greyscale_image_left);
imshow("right", g_greyscale_image_right);
imshow("depth", depth8);
key = waitKey(1);
//publish depth image
cv_bridge::CvImage depth_16;
g_depth.copyTo(depth_16.image);
depth_16.header.frame_id = "guidance";
depth_16.header.stamp = ros::Time::now();
depth_16.encoding = sensor_msgs::image_encodings::MONO16;
depth_image_pub.publish(depth_16.toImageMsg());
// publish left greyscale image
cv_bridge::CvImage left_8;
g_greyscale_image_left.copyTo(left_8.image);
left_8.header.frame_id = "guidance";
left_8.header.stamp = ros::Time::now();
left_8.encoding = sensor_msgs::image_encodings::MONO8;
left_image_pub.publish(left_8.toImageMsg());
// publish right greyscale image
cv_bridge::CvImage right_8;
g_greyscale_image_left.copyTo(right_8.image);
right_8.header.frame_id = "guidance";
right_8.header.stamp = ros::Time::now();
right_8.encoding = sensor_msgs::image_encodings::MONO8;
right_image_pub.publish(right_8.toImageMsg());
}*/
/* imu */
if ( e_imu == data_type && NULL != content )
{
imu *imu_data = (imu*)content;
/* printf( "frame index: %d, stamp: %d\n", imu_data->frame_index, imu_data->time_stamp );
printf( "imu: [%f %f %f %f %f %f %f]\n", imu_data->acc_x, imu_data->acc_y, imu_data->acc_z, imu_data->q[0], imu_data->q[1], imu_data->q[2], imu_data->q[3] );
// publish imu data
geometry_msgs::TransformStamped g_imu;
g_imu.header.frame_id = "guidance";
g_imu.header.stamp = ros::Time::now();
g_imu.transform.translation.x = imu_data->acc_x;
g_imu.transform.translation.y = imu_data->acc_y;
g_imu.transform.translation.z = imu_data->acc_z;
g_imu.transform.rotation.x = imu_data->q[0];
g_imu.transform.rotation.y = imu_data->q[1];
g_imu.transform.rotation.z = imu_data->q[2];
g_imu.transform.rotation.w = imu_data->q[3];
imu_pub.publish(g_imu);
}
*/
imu_p.header.stamp = ros::Time::now();
imu_p.header.frame_id = "imu";
imu_p.orientation.x = imu_data->q[0];
imu_p.orientation.y = imu_data->q[1];
imu_p.orientation.z = imu_data->q[2];
imu_p.orientation.w = imu_data->q[3];
imu_p.linear_acceleration.x = imu_data->acc_x;
imu_p.linear_acceleration.y = imu_data->acc_y;
imu_p.linear_acceleration.z = imu_data->acc_z;
double roll, pitch, yaw;
tf::Quaternion orientation;
tf::quaternionMsgToTF(imu_p.orientation, orientation);
tf::Matrix3x3(orientation).getRPY(roll, pitch, yaw);
//printf( "roll:%f pitch:%f yaw:%f\n", roll, pitch, yaw );
//printf( "imu_data->acc_x:%f imu_data->acc_y:%f imu_data->acc_z:%f\n", imu_data->acc_x, imu_data->acc_y, imu_data->acc_z);
/*
if (se=="abc") orientation.setRPY(roll, pitch, yaw);
else
{
if(se=="acb") orientation.setRPY(roll, yaw, pitch);
else if(se=="bac") orientation.setRPY(pitch, roll, yaw);
else if(se=="bca") orientation.setRPY(pitch, yaw, roll);
else if(se=="cab") orientation.setRPY(yaw, roll, pitch);
else if(se=="cba") orientation.setRPY(yaw, pitch, roll);
//.........这里部分代码省略.........
示例6: my_callback
int my_callback(int data_type, int data_len, char *content)
{
g_lock.enter();
/* image data */
if (e_image == data_type && NULL != content)
{
ros::Time time_in_this_loop = ros::Time::now();
image_data* data = (image_data*)content;
if ( data->m_greyscale_image_left[CAMERA_ID] ) {
memcpy(g_greyscale_image_left.data, data->m_greyscale_image_left[CAMERA_ID], IMAGE_SIZE);
imshow("left", g_greyscale_image_left);
// publish left greyscale image
cv_bridge::CvImage left_8;
g_greyscale_image_left.copyTo(left_8.image);
left_8.header.frame_id = "guidance";
left_8.header.stamp = time_in_this_loop;
left_8.encoding = sensor_msgs::image_encodings::MONO8;
left_image_pub.publish(left_8.toImageMsg());
sensor_msgs::CameraInfo g_cam_info_left;
g_cam_info_left.header.stamp = time_in_this_loop;
g_cam_info_left.header.frame_id = "guidance";
try {
read_params_from_yaml_and_fill_cam_info_msg(camera_params_left, g_cam_info_left);
cam_info_left_pub.publish(g_cam_info_left);
} catch(...) {
// if yaml fails to read data, don't try to publish
}
}
if ( data->m_greyscale_image_right[CAMERA_ID] ) {
memcpy(g_greyscale_image_right.data, data->m_greyscale_image_right[CAMERA_ID], IMAGE_SIZE);
imshow("right", g_greyscale_image_right);
// publish right greyscale image
cv_bridge::CvImage right_8;
g_greyscale_image_right.copyTo(right_8.image);
right_8.header.frame_id = "guidance";
right_8.header.stamp = time_in_this_loop;
right_8.encoding = sensor_msgs::image_encodings::MONO8;
right_image_pub.publish(right_8.toImageMsg());
sensor_msgs::CameraInfo g_cam_info_right;
g_cam_info_right.header.stamp = time_in_this_loop;
g_cam_info_right.header.frame_id = "guidance";
try {
read_params_from_yaml_and_fill_cam_info_msg(camera_params_right, g_cam_info_right);
cam_info_right_pub.publish(g_cam_info_right);
} catch(...) {
// if yaml fails to read data, don't try to publish
}
}
if ( data->m_depth_image[CAMERA_ID] ) {
memcpy(g_depth.data, data->m_depth_image[CAMERA_ID], IMAGE_SIZE * 2);
g_depth.convertTo(depth8, CV_8UC1);
imshow("depth", depth8);
//publish depth image
cv_bridge::CvImage depth_16;
g_depth.copyTo(depth_16.image);
depth_16.header.frame_id = "guidance";
depth_16.header.stamp = ros::Time::now();
depth_16.encoding = sensor_msgs::image_encodings::MONO16;
depth_image_pub.publish(depth_16.toImageMsg());
}
//left image pair(ID=2)
if ( data->m_greyscale_image_left[CAMERA_ID_2] ) {
memcpy(g_greyscale_image_left_2.data, data->m_greyscale_image_left[CAMERA_ID_2], IMAGE_SIZE);
imshow("left_2", g_greyscale_image_left_2);
// publish left greyscale image
cv_bridge::CvImage left_8_2;
g_greyscale_image_left_2.copyTo(left_8_2.image);
left_8_2.header.frame_id = "guidance2";
left_8_2.header.stamp = time_in_this_loop;
left_8_2.encoding = sensor_msgs::image_encodings::MONO8;
left_image_pub_2.publish(left_8_2.toImageMsg());
sensor_msgs::CameraInfo g_cam_info_left;
g_cam_info_left.header.stamp = time_in_this_loop;
g_cam_info_left.header.frame_id = "guidance2";
try {
read_params_from_yaml_and_fill_cam_info_msg(camera2_params_left, g_cam_info_left);
cam2_info_left_pub.publish(g_cam_info_left);
} catch(...) {
// if yaml fails to read data, don't try to publish
}
}
if ( data->m_greyscale_image_right[CAMERA_ID_2] ) {
memcpy(g_greyscale_image_right_2.data, data->m_greyscale_image_right[CAMERA_ID_2], IMAGE_SIZE);
imshow("right_2", g_greyscale_image_right_2);
// publish right greyscale image
cv_bridge::CvImage right_8_2;
g_greyscale_image_right_2.copyTo(right_8_2.image);
right_8_2.header.frame_id = "guidance2";
right_8_2.header.stamp = time_in_this_loop;
right_8_2.encoding = sensor_msgs::image_encodings::MONO8;
right_image_pub_2.publish(right_8_2.toImageMsg());
//.........这里部分代码省略.........
示例7: my_callback
int my_callback(int data_type, int data_len, char *content)
{
g_lock.enter();
if (e_image == data_type && NULL != content)
{
image_data data;
memcpy( (char*)&data, content, sizeof(data) );
printf( "frame index:%d,stamp:%d\n", data.frame_index, data.time_stamp );
#if !USE_GUIDANCE_ASSISTANT_CONFIG
#ifdef HAVE_OPENCV
memcpy( g_greyscale_image_left.data, data.m_greyscale_image_left[sensor_id], IMAGE_SIZE );
memcpy( g_greyscale_image_right.data, data.m_greyscale_image_right[sensor_id], IMAGE_SIZE );
memcpy( g_depth.data, data.m_depth_image[sensor_id], IMAGE_SIZE * 2 );
imshow("left", g_greyscale_image_left);
imshow("right", g_greyscale_image_right);
#endif
#else
for ( int d = 0; d < CAMERA_PAIR_NUM; ++d )
{
string stmps;
if ( data.m_greyscale_image_left[d] )
{
#ifdef HAVE_OPENCV
memcpy( g_greyscale_image_left.data, data.m_greyscale_image_left[d], IMAGE_SIZE );//maybe select too many image so just overwrite it
stmps = "left";
stmps = stmps + (char)('0'+d);
imshow(stmps.c_str(), g_greyscale_image_left);
#endif
}
if ( data.m_greyscale_image_right[d] )
{
#ifdef HAVE_OPENCV
memcpy( g_greyscale_image_right.data, data.m_greyscale_image_right[d], IMAGE_SIZE );
stmps = "right";
stmps = stmps + (char)('0'+d);
imshow(stmps, g_greyscale_image_right);
#endif
}
if ( data.m_depth_image[d] )
{
#ifdef HAVE_OPENCV
Mat depthmap(HEIGHT, WIDTH, CV_16SC1);
Mat depthmap8(HEIGHT, WIDTH, CV_8UC1);
memcpy( depthmap.data, data.m_depth_image[d], IMAGE_SIZE * 2 );
depthmap.convertTo(depthmap8, CV_8UC1);
stmps = "depthmap";
stmps = stmps + (char)('0'+d);
imshow(stmps, depthmap8);
#endif
}
}
#endif
#ifdef HAVE_OPENCV
waitKey(1);
#endif
}
if ( e_imu == data_type && NULL != content )
{
imu *imu_data = (imu*)content;
printf( "imu:%f %f %f,%f %f %f %f\n", imu_data->acc_x, imu_data->acc_y, imu_data->acc_z, imu_data->q[0], imu_data->q[1], imu_data->q[2], imu_data->q[3] );
printf( "frame index:%d,stamp:%d\n", imu_data->frame_index, imu_data->time_stamp );
}
if ( e_velocity == data_type && NULL != content )
{
velocity *vo = (velocity*)content;
printf( "vx:%f vy:%f vz:%f\n", 0.001f * vo->vx, 0.001f * vo->vy, 0.001f * vo->vz );
printf( "frame index:%d,stamp:%d\n", vo->frame_index, vo->time_stamp );
}
if ( e_obstacle_distance == data_type && NULL != content )
{
obstacle_distance *oa = (obstacle_distance*)content;
printf( "obstacle distance:" );
for ( int i = 0; i < CAMERA_PAIR_NUM; ++i )
{
printf( " %f ", 0.01f * oa->distance[i] );
}
printf( "\n" );
printf( "frame index:%d,stamp:%d\n", oa->frame_index, oa->time_stamp );
}
if ( e_ultrasonic == data_type && NULL != content )
{
ultrasonic_data *ultrasonic = (ultrasonic_data*)content;
for ( int d = 0; d < CAMERA_PAIR_NUM; ++d )
{
printf( "ultrasonic distance:%f,reliability:%d\n", ultrasonic->ultrasonic[d] * 0.001f, (int)ultrasonic->reliability[d] );
}
printf( "frame index:%d,stamp:%d\n", ultrasonic->frame_index, ultrasonic->time_stamp );
}
g_lock.leave();
g_event.set_event();
return 0;
}