6 #include <BayesFilters/ResamplingWithPrior.h> 7 #include <yarp/os/ConstString.h> 8 #include <yarp/os/LogStream.h> 9 #include <yarp/os/Network.h> 10 #include <yarp/os/ResourceFinder.h> 11 #include <yarp/os/Value.h> 12 #include <opencv2/core/core.hpp> 13 #include <opencv2/core/cuda.hpp> 28 using namespace Eigen;
38 int main(
int argc,
char *argv[])
40 ConstString log_ID =
"[Main]";
41 yInfo() << log_ID <<
"Configuring and starting module...";
44 if (!yarp.checkNetwork(3.0))
46 yError() <<
"YARP seems unavailable!";
54 cuda::DeviceInfo gpu_dev;
56 yInfo() << log_ID <<
"[CUDA] Can have concurrent kernel:" << gpu_dev.concurrentKernels();
57 yInfo() << log_ID <<
"[CUDA] Streaming multiprocessor count:" << gpu_dev.multiProcessorCount();
58 yInfo() << log_ID <<
"[CUDA] Can map host memory:" << gpu_dev.canMapHostMemory();
59 yInfo() << log_ID <<
"[CUDA] Clock:" << gpu_dev.clockRate() <<
"KHz";
64 rf.setDefaultContext(
"hand-tracking");
65 rf.setDefaultConfigFile(
"config.ini");
66 rf.configure(argc, argv);
68 FilteringParamtersD paramsd;
69 paramsd[
"num_particles"] = rf.findGroup(
"PF").check(
"num_particles", Value(50)).asInt();
70 paramsd[
"gpu_count"] = rf.findGroup(
"PF").check(
"gpu_count", Value(1.0)).asInt();
71 paramsd[
"resample_prior"] = rf.findGroup(
"PF").check(
"resample_prior", Value(1.0)).asInt();
72 paramsd[
"gate_pose"] = rf.findGroup(
"PF").check(
"gate_pose", Value(0.0)).asInt();
73 paramsd[
"resolution_ratio"] = rf.findGroup(
"PF").check(
"resolution_ratio", Value(1.0)).asInt();
74 paramsd[
"num_images"] = paramsd[
"num_particles"] / paramsd[
"gpu_count"];
76 paramsd[
"play"] = 1.0;
78 paramsd[
"play"] = rf.findGroup(
"PF").check(
"play", Value(1.0)).asDouble();
80 paramsd[
"q_xy"] = rf.findGroup(
"BROWNIANMOTION").check(
"q_xy", Value(0.005)).asDouble();
81 paramsd[
"q_z"] = rf.findGroup(
"BROWNIANMOTION").check(
"q_z", Value(0.005)).asDouble();
82 paramsd[
"theta"] = rf.findGroup(
"BROWNIANMOTION").check(
"theta", Value(3.0)).asDouble();
83 paramsd[
"cone_angle"] = rf.findGroup(
"BROWNIANMOTION").check(
"cone_angle", Value(2.5)).asDouble();
84 paramsd[
"seed"] = rf.findGroup(
"BROWNIANMOTION").check(
"seed", Value(1.0)).asDouble();
86 paramsd[
"use_thumb"] = rf.findGroup(
"VISUALPROPRIOCEPTION").check(
"use_thumb", Value(0.0)).asDouble();
87 paramsd[
"use_forearm"] = rf.findGroup(
"VISUALPROPRIOCEPTION").check(
"use_forearm", Value(0.0)).asDouble();
89 paramsd[
"likelihood_gain"] = rf.findGroup(
"VISUALUPDATEPARTICLES").check(
"likelihood_gain", Value(0.001)).asDouble();
91 paramsd[
"gate_x"] = rf.findGroup(
"GATEPOSE").check(
"gate_x", Value(0.1)).asDouble();
92 paramsd[
"gate_y"] = rf.findGroup(
"GATEPOSE").check(
"gate_y", Value(0.1)).asDouble();
93 paramsd[
"gate_z"] = rf.findGroup(
"GATEPOSE").check(
"gate_z", Value(0.1)).asDouble();
94 paramsd[
"gate_aperture"] = rf.findGroup(
"GATEPOSE").check(
"gate_aperture", Value(15.0)).asDouble();
95 paramsd[
"gate_rotation"] = rf.findGroup(
"GATEPOSE").check(
"gate_rotation", Value(30.0)).asDouble();
97 paramsd[
"resample_ratio"] = rf.findGroup(
"RESAMPLING").check(
"resample_ratio", Value(0.3)).asDouble();
98 paramsd[
"prior_ratio"] = rf.findGroup(
"RESAMPLING").check(
"prior_ratio", Value(0.5)).asDouble();
100 FilteringParamtersS paramss;
101 paramss[
"robot"] = rf.findGroup(
"PF").check(
"robot", Value(
"icub")).asString();
103 paramss[
"cam_sel"] = rf.find(
"cam").asString();
105 paramss[
"cam_sel"] = rf.findGroup(
"PF").check(
"cam_sel", Value(
"left")).asString();
106 paramss[
"laterality"] = rf.findGroup(
"PF").check(
"laterality", Value(
"right")).asString();
109 yInfo() << log_ID <<
"Running with:";
110 yInfo() << log_ID <<
" - robot:" << paramss[
"robot"];
111 yInfo() << log_ID <<
" - cam_sel:" << paramss[
"cam_sel"];
112 yInfo() << log_ID <<
" - laterality:" << paramss[
"laterality"];
114 yInfo() << log_ID <<
" - num_particles:" << paramsd[
"num_particles"];
115 yInfo() << log_ID <<
" - gpu_count:" << paramsd[
"gpu_count"];
116 yInfo() << log_ID <<
" - num_images:" << paramsd[
"num_images"];
117 yInfo() << log_ID <<
" - resample_prior:" << paramsd[
"resample_prior"];
118 yInfo() << log_ID <<
" - gate_pose:" << paramsd[
"gate_pose"];
119 yInfo() << log_ID <<
" - play:" << (paramsd[
"play"] == 1.0 ?
"true" :
"false");
121 yInfo() << log_ID <<
" - q_xy:" << paramsd[
"q_xy"];
122 yInfo() << log_ID <<
" - q_z:" << paramsd[
"q_z"];
123 yInfo() << log_ID <<
" - theta:" << paramsd[
"theta"];
124 yInfo() << log_ID <<
" - cone_angle:" << paramsd[
"cone_angle"];
125 yInfo() << log_ID <<
" - seed:" << paramsd[
"seed"];
127 yInfo() << log_ID <<
" - use_thumb:" << paramsd[
"use_thumb"];
128 yInfo() << log_ID <<
" - use_forearm:" << paramsd[
"use_forearm"];
130 yInfo() << log_ID <<
" - likelihood_gain:" << paramsd[
"likelihood_gain"];
132 yInfo() << log_ID <<
" - resample_ratio:" << paramsd[
"resample_ratio"];
133 yInfo() << log_ID <<
" - prior_ratio:" << paramsd[
"prior_ratio"];
135 yInfo() << log_ID <<
" - gate_x:" << paramsd[
"gate_x"];
136 yInfo() << log_ID <<
" - gate_y:" << paramsd[
"gate_y"];
137 yInfo() << log_ID <<
" - gate_z:" << paramsd[
"gate_z"];
138 yInfo() << log_ID <<
" - gate_aperture:" << paramsd[
"gate_aperture"];
139 yInfo() << log_ID <<
" - gate_rotation:" << paramsd[
"gate_rotation"];
143 std::unique_ptr<Initialization> init_arm(
new InitiCubArm(
"hand-tracking/InitiCubArm", paramss[
"cam_sel"], paramss[
"laterality"]));
147 std::unique_ptr<StateModel> brown(
new BrownianMotionPose(paramsd[
"q_xy"], paramsd[
"q_z"], paramsd[
"theta"], paramsd[
"cone_angle"], paramsd[
"seed"]));
149 std::unique_ptr<ExogenousModel> icub_motion;
150 if (paramsd[
"play"] != 1.0)
152 std::unique_ptr<iCubFwdKinModel> icub_fwdkin(
new iCubFwdKinModel(paramss[
"robot"], paramss[
"laterality"], paramss[
"cam_sel"]));
153 icub_motion = std::move(icub_fwdkin);
157 std::unique_ptr<PlayFwdKinModel> play_fwdkin(
new PlayFwdKinModel(paramss[
"robot"], paramss[
"laterality"], paramss[
"cam_sel"]));
158 icub_motion = std::move(play_fwdkin);
163 pf_prediction->setStateModel(std::move(brown));
164 pf_prediction->setExogenousModel(std::move(icub_motion));
168 std::unique_ptr<VisualProprioception> proprio;
172 paramsd[
"use_forearm"],
173 paramsd[
"num_images"],
174 paramsd[
"resolution_ratio"],
176 paramss[
"laterality"],
179 proprio = std::move(vp);
180 paramsd[
"num_particles"] = proprio->getOGLTilesRows() * proprio->getOGLTilesCols() * paramsd[
"gpu_count"];
181 paramsd[
"cam_width"] = proprio->getCamWidth();
182 paramsd[
"cam_height"] = proprio->getCamHeight();
184 catch (
const std::runtime_error& e)
186 yError() << e.what();
191 std::unique_ptr<PFVisualCorrection> vpf_correction;
193 std::unique_ptr<PFVisualCorrection> vpf_update_particles(
new VisualUpdateParticles(std::move(proprio), paramsd[
"likelihood_gain"], paramsd[
"gpu_count"]));
195 if (paramsd[
"gate_pose"] == 1.0)
197 if (paramsd[
"play"] != 1.0)
199 std::unique_ptr<iCubGatePose> icub_gate_pose(
new iCubGatePose(std::move(vpf_update_particles),
200 paramsd[
"gate_x"], paramsd[
"gate_y"], paramsd[
"gate_z"],
201 paramsd[
"gate_aperture"], paramsd[
"gate_rotation"],
202 paramss[
"robot"], paramss[
"laterality"], paramss[
"cam_sel"]));
203 vpf_correction = std::move(icub_gate_pose);
207 std::unique_ptr<PlayGatePose> icub_gate_pose(
new PlayGatePose(std::move(vpf_update_particles),
208 paramsd[
"gate_x"], paramsd[
"gate_y"], paramsd[
"gate_z"],
209 paramsd[
"gate_aperture"], paramsd[
"gate_rotation"],
210 paramss[
"robot"], paramss[
"laterality"], paramss[
"cam_sel"]));
211 vpf_correction = std::move(icub_gate_pose);
215 vpf_correction = std::move(vpf_update_particles);
219 std::unique_ptr<Resampling> pf_resampling;
220 if (paramsd[
"resample_prior"] != 1.0)
222 std::unique_ptr<Resampling> resampling(
new Resampling());
224 pf_resampling = std::move(resampling);
228 std::unique_ptr<InitiCubArm> resample_init_arm(
new InitiCubArm(
"hand-tracking/ResamplingWithPrior/InitiCubArm", paramss[
"cam_sel"], paramss[
"laterality"]));
229 std::unique_ptr<Resampling> resampling_prior(
new ResamplingWithPrior(std::move(resample_init_arm), paramsd[
"prior_ratio"]));
231 pf_resampling = std::move(resampling_prior);
237 paramsd[
"cam_width"], paramsd[
"cam_height"],
238 paramsd[
"num_particles"],
239 paramsd[
"resample_ratio"]);
240 vsis_pf.setInitialization(std::move(init_arm));
241 vsis_pf.setPrediction(std::move(pf_prediction));
242 vsis_pf.setCorrection(std::move(vpf_correction));
243 vsis_pf.setResampling(std::move(pf_resampling));
250 yInfo() << log_ID <<
"Application closed succesfully.";
258 if (engine_count == 0)
return "concurrency is unsupported on this device";
259 if (engine_count == 1)
return "the device can concurrently copy memory between host and device while executing a kernel";
260 if (engine_count == 2)
return "the device can concurrently copy memory between host and device in both directions and execute a kernel at the same time";
261 return "wrong argument...!";
int main(int argc, char *argv[])
std::string engine_count_to_string(int engine_count)