Skip to content

Commit 71057dc

Browse files
committed
fixed review by gemini
1 parent 43e588a commit 71057dc

File tree

2 files changed

+49
-18
lines changed

2 files changed

+49
-18
lines changed

src/commands/yarpActionsPlayer/controlThread.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ bool ControlThread::action_change(action_class* action, robotDriver* driver)
9090
m_current_driver = driver;
9191
m_status = ACTION_IDLE;
9292
m_current_action->current_frame = 0;
93+
m_clock.resetTimer();
9394
return true;
9495
}
9596

src/commands/yarpActionsPlayer/main.cpp

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,22 @@ class scriptModule: public yarp::os::RFModule, public yarpActionsPlayer_IDL
193193
{
194194
yDebug() << bot_clients.get(i).toString();
195195
yarp::os::Bottle* bot_client_elem = bot_clients.get(i).asList();
196+
if (bot_client_elem == nullptr)
197+
{
198+
yError() << "Invalid entry in CLIENTS section";
199+
return false;
200+
}
196201
size_t num_of_client_elems = bot_client_elem->size();
197-
if (bot_client_elem && num_of_client_elems == 2)
202+
if (num_of_client_elems == 2)
198203
{
199204
//parse a line of the CLIENTS section
200205
std::string client_name = bot_client_elem->get(0).toString();
201206
std::string remoteControlBoards = bot_client_elem->get(1).toString();
207+
if (m_robotClients[client_name] != nullptr)
208+
{
209+
yError() << "Duplicate client entry: " << client_name;
210+
return false;
211+
}
202212
m_robotClients[client_name] = new yarp::dev::PolyDriver;
203213
yarp::os::Property clientoptions;
204214
clientoptions.put("device", "remote_controlboard");
@@ -216,12 +226,12 @@ class scriptModule: public yarp::os::RFModule, public yarpActionsPlayer_IDL
216226
}
217227
else
218228
{
219-
yError() << "Invalid entry in CLIENTS section";
229+
yError() << "Invalid number of entries in CLIENTS section";
220230
return false;
221231
}
222232
}
223233

224-
//load the controllers/remappers
234+
//load the remappers
225235
yarp::os::Bottle& bot_cont = p.findGroup("REMAPPERS");
226236
if (bot_cont.size() == 0)
227237
{
@@ -233,11 +243,16 @@ class scriptModule: public yarp::os::RFModule, public yarpActionsPlayer_IDL
233243
{
234244
yDebug() << bot_cont.get(i).toString();
235245
yarp::os::Bottle* bot_cont_elem = bot_cont.get(i).asList();
246+
if (bot_cont_elem == nullptr)
247+
{
248+
yError() << "Invalid entry in REMAPPERS section";
249+
return false;
250+
}
236251
size_t num_of_celems = bot_cont_elem->size();
237-
if (bot_cont_elem && num_of_celems == 3)
252+
if (num_of_celems == 3)
238253
{
239-
//parse a line of the controllers/remappers section
240-
std::string controller_name = bot_cont_elem->get(0).toString();
254+
//parse a line of the remappers section
255+
std::string remapper_name = bot_cont_elem->get(0).toString();
241256
yarp::os::Bottle* clients_name = bot_cont_elem->get(1).asList();
242257
std::string axes_names = bot_cont_elem->get(2).toString();
243258
if (clients_name==nullptr || clients_name->size() == 0)
@@ -251,53 +266,68 @@ class scriptModule: public yarp::os::RFModule, public yarpActionsPlayer_IDL
251266
return false;
252267
}
253268

254-
//configure the controller/remapper
255-
m_robotRemappers[controller_name] = new yarp::dev::PolyDriver;
269+
//configure the remapper
270+
if (m_robotRemappers[remapper_name] != nullptr)
271+
{
272+
yError() << "Duplicate remapper entry: " << remapper_name;
273+
return false;
274+
}
275+
m_robotRemappers[remapper_name] = new yarp::dev::PolyDriver;
256276
yarp::os::Property rmoptions;
257277
rmoptions.put("device", "controlboardremapper");
258278
yarp::os::Value* jlist = yarp::os::Value::makeList(axes_names.c_str());
259279
rmoptions.put("axesNames",jlist);
260-
bool rob_ok = m_robotRemappers[controller_name]->open(rmoptions);
280+
bool rob_ok = m_robotRemappers[remapper_name]->open(rmoptions);
261281
if (!rob_ok)
262282
{
263-
yError() << "Unable to initialize remapper: " << controller_name;
283+
yError() << "Unable to initialize remapper: " << remapper_name;
264284
return false;
265285
}
266286

267-
//attach the controller/remapper to one or more clients
287+
//attach the remapper to one or more clients
268288
{
269289
yarp::dev::IMultipleWrapper* ww_rem=nullptr;
270-
m_robotRemappers[controller_name]->view(ww_rem);
290+
m_robotRemappers[remapper_name]->view(ww_rem);
271291
yarp::dev::PolyDriverList pdlist;
272292
for (size_t i=0; i<clients_name->size(); i++)
273293
{
274294
std::string cnn = clients_name->get(i).toString();
275295
yarp::dev::PolyDriver* ddnwc = m_robotClients[cnn];
296+
if (ddnwc == nullptr)
297+
{
298+
yError() << "Configuration error while searching for client" << cnn;
299+
return false;
300+
}
276301
std::string boardname = "nwcboard" + std::to_string(i);
277302
pdlist.push(ddnwc, boardname.c_str());
278303
}
279304
bool result_att = ww_rem->attachAll(pdlist);
280305
if (!result_att)
281306
{
282307
yError() << "Configuration error while trying to attach the remapper: "
283-
<< controller_name << " with the control_boards: " << clients_name->toString();
308+
<< remapper_name << " with the control_boards: " << clients_name->toString();
284309
return false;
285310
}
286311
}
287312

288313
//put the controller in the list
289-
m_robotControllers[controller_name] = new robotDriver;
290-
rob_ok = m_robotControllers[controller_name]->configure(m_robotRemappers[controller_name]);
291-
rob_ok &= m_robotControllers[controller_name]->init();
314+
if (m_robotControllers[remapper_name] != nullptr)
315+
{
316+
yError() << "Duplicate controller entry: " << remapper_name;
317+
return false;
318+
}
319+
m_robotControllers[remapper_name] = new robotDriver;
320+
rob_ok = m_robotControllers[remapper_name]->configure(m_robotRemappers[remapper_name]);
321+
rob_ok &= m_robotControllers[remapper_name]->init();
292322
if (!rob_ok)
293323
{
294-
yError() << "Unable to initialize controller: " << controller_name;
324+
yError() << "Unable to initialize controller: " << remapper_name;
295325
return false;
296326
}
297327
}
298328
else
299329
{
300-
yError() << "Invalid entry in CONTROLLERS section";
330+
yError() << "Invalid number of entries in REMAPPERS section";
301331
return false;
302332
}
303333
}

0 commit comments

Comments
 (0)