User Manual
- 30 -
#include
"hps_camera/distance.h"//msg
#include
"hps_camera/camera.h"//srv
②ROS Initialize in the main function, create node, create topic and etc., code as below:
ros::init(argc, argv, "ros_camera_server");
ros::NodeHandle n;
ros::ServiceServer service = n.advertiseService("client_login", send_cmd);
ros::Subscriber sub = n.subscribe("camera", 1000, chatterCallback);
ros::spin();
③Write service function, code as below:
bool
send_cmd
(hps_camera::camera::Request &req, hps_camera::camera::Response
&res)
{
std::stringstream scmd;
printf("client_name: %s\n", req.client_node_name.c_str() );
if
( strcmp(req.client_node_name.c_str(), "camera_client" ) == 0 )
{
scmd<< "start";
res.control_cmd = scmd.str();
printf("send_cmd: %s\n", res.control_cmd.c_str() );
}
return
true
;
}
④ Subscribe to the topic's callback function, the code is as follows:
void
chatterCallback
(
const
hps_camera::distance& msg)
{
printf("distance_average = %d\n", msg.distance_average);
}
(2) Write Depth camera client node program
In the client node, the use of the depth camera api interface is the same as the "2.1.3 Using the
SDK in User Projects" configuration of this document. For details, please refer to "2.1.3 Using the
SDK in User Projects" in this document or give the sample code.
1 Add a header file, the code is as follows:
#include
"ros/ros.h"
#include
"std_msgs/String.h"
#include
"hps_camera/distance.h"//msg
#include
"hps_camera/camera.h"//srv
#include
"../include/api.h"
#include
<sstream>
2 In the main function, ros initialization, node creation, topic creation and depth camera api
interface configuration, the code is as follows:
ros::Publisher camera_pub;
int
main
(
int
argc,
char
**argv)
{
ros::init(argc, argv, "ros_camera_client");










