45 bool start()
override;
47 bool reset()
override;
51 bool resample(
const double value)
override;
53 bool play_action(
const std::string& action_name)
override;
74 yInfo() <<
"cleanup complete";
93 yError() <<
"action id not found";
102 if (!driver || !action)
104 yError() <<
"invalid driver/action pointer";
107 yInfo() <<
"action selected:" << id;
108 yDebug() <<
"action controller:" << controller_name;
115 std::string ss =
"actions:\n";
119 ss = ss +
"(" + std::to_string(i++) +
") " + it->second.action_name +
"\n";
129 yError() <<
"Unable to read configuration file!";
134 if (bot_cont.
size() == 0)
136 yError() <<
"Unable to read CONTROLLERS section";
139 size_t num_of_controllers = bot_cont.
size();
140 for (
size_t i = 1; i < num_of_controllers; i++)
144 size_t num_of_celems = bot_cont_elem->
size();
145 if (bot_cont_elem && num_of_celems == 3)
148 std::string controller_name = bot_cont_elem->
get(0).
toString();
149 std::string remoteControlBoards = bot_cont_elem->
get(1).
toString();
150 std::string axesNames = bot_cont_elem->
get(2).
toString();
153 rmoptions.
put(
"remoteControlBoards", bot_cont_elem->
get(1));
154 rmoptions.
put(
"axesNames", bot_cont_elem->
get(2));
155 rmoptions.
put(
"localPortPrefix",
m_name +
"/controller/" + controller_name);
160 rob_ok &= rob->
init();
163 yError() <<
"Unable to initialize controller" << controller_name;
171 yError() <<
"Invalid entry in CONTROLLERS section";
177 if (bot_action.
size() == 0)
179 yError() <<
"Unable to read ACTIONS section";
182 for (
size_t i = 1; i < bot_action.
size(); i++)
184 std::string str = bot_action.
toString();
187 size_t num_of_aelems = bot_act_elem->
size();
188 if (bot_act_elem && num_of_aelems==3)
191 std::string action_name = bot_act_elem->
get(0).
toString();
192 std::string controller_name = bot_act_elem->
get(1).
toString();
193 std::string action_file_name = bot_act_elem->
get(2).
toString();
198 yError() << controller_name <<
"in action" << action_name <<
"does not exists";
208 if (!tmpAction.
openFile(action_file_name, njoints, 0.010))
210 yError() <<
"Unable to parse file";
213 if (resample_period!=0.0)
223 yError() <<
"Invalid entry in ACTIONS section";
228 yInfo() <<
"configuration file successfully loaded";
235 yInfo() <<
"Command line:";
236 yInfo() <<
"yarpActionsPlayer --filename `name` [--name `module_name`] [--execute] [--period period_s] [--resample resample_period_s] [--pos_tolerance pos] [--pos_timeout pos] [--pos_strict_check enable] ";
238 yInfo() <<
"`name` : file containing the actions";
239 yInfo() <<
"`module_name` : prefix of the ports opened by the module (default: /yarpActionsPlayer)";
240 yInfo() <<
"`execute` : if enabled, the yarpActionsPlayer will send commands to the robot. Otherwise, only it will operate in simulation mode only";
241 yInfo() <<
"`pos_tolerance` : the tolerance (in degrees) that will be checked by the initial movement in position mode, before switching to positionDirect mode. Default: 2degrees";
242 yInfo() <<
"`pos_timeout` : the amount of time (in seconds) the robot will attempt to reach the target position within the specified position tolerance. Default: 2s";
243 yInfo() <<
"`pos_strict_check` : if set to true, the system will halt if home position is halted, otherwise it will continue after the timeout expires. Default: false";
244 yInfo() <<
"`period` : the period (in s) of the thread processing the commands. Default 0.010s";
245 yInfo() <<
"`resample`: all the loaded trajectory files are internally resampled at the specified period. Default: not enabled";
246 yInfo() <<
"`initial_move_time`: the duration (in seconds) of the initial homing position of the joints before starting the trajectory. Default: 4s";
252 std::string test_string = rf.
toString();
255 if (rf.
check(
"name"))
258 m_name =
"/yarpActionsPlayer";
265 double period = 0.005;
266 if (rf.
check(
"period") ==
true)
275 if (rf.
check(
"execute")==
true)
277 yInfo() <<
"Enabling iPid->setReference() controller";
282 yInfo() <<
"Not using iPid->setReference() controller";
287 if (rf.
check(
"help") ==
true)
293 if (rf.
check(
"initial_move_time") ==
true)
300 if (rf.
check(
"pos_tolerance") ==
true)
303 yInfo() <<
"Position tolerance set to " << tol <<
"degrees";
308 if (rf.
check(
"pos_timeout") ==
true)
311 yInfo() <<
"Position timeout set to " << timeout <<
"seconds";
316 if (rf.
check(
"pos_strict_check") ==
true)
318 bool enable = rf.
find(
"pos_strict_check").
asBool();
322 double resample_period = 0;
323 if (rf.
check(
"resample") ==
true)
326 yInfo() <<
"Set resample period equal to:" << resample_period <<
"s";
330 if (rf.
check(
"filename")==
true)
338 yError() <<
"Configuration error!";
344 yError() <<
"`filename` option syntax error.";
351 yWarning() <<
"`filename` option not found. No sequence files loaded.";
357 yInfo() <<
"There are no actions!";
362 yInfo() <<
"automatically selecting the first action";
363 std::string first_action_name;
364 first_action_name = this->m_actions.begin()->first;
370 yError() <<
"Working thread did not start, queue will not work";
374 yInfo() <<
"Working thread started";
377 yInfo() <<
"module successfully configured. ready.";
393int main(
int argc,
char *argv[])
401 if (!
yarp.checkNetwork())
403 yError() <<
"yarp.checkNetwork() failed.";
467 std::string current_action_name;
469 yInfo() <<
"current_action: " <<current_action_name;
470 yInfo() << actions_str;
479 yError(
"invalid period value");
483 yInfo(
"Period set to %f", value);
493 yError(
"invalid initial move time");
497 yInfo(
"Initial move time set to %f", value);
contains the definition of a Vector type
bool action_getname(std::string &name)
void setPositionStrictCheck(bool enable)
bool m_enable_execute_joint_command
void setInitialMoveTime(double t)
action_status_enum getStatus()
bool action_resample(double value)
bool action_setSpeedFactor(double factor=1)
void setPositionTolerance(double tolerance)
bool action_change(action_class *action, robotDriver *driver)
void setPositionTimeout(double timeloops)
void interpolate_action_frames(double timestep)
bool openFile(std::string filename, size_t njoints, double timestep=-1)
std::string controller_name
std::deque< action_frame > action_frames_vector
bool configure(const yarp::os::Property &copt)
bool reset() override
Rewinds the currently selected action.
bool speed_factor(const double value) override
Sets the playback speed factor for the currently selected action (default value: 1....
bool show_actions() override
Prints all the loaded actions.
std::string string_list_actions()
bool loadConfiguration(std::string filename, double resample_period)
std::map< std::string, action_class > m_actions
virtual bool updateModule()
Override this to do whatever your module needs to do.
BroadcastingThread * m_bthread
bool resample(const double value) override
Resamples the currently selected action (in seconds, recommended value 0.010s).
bool start() override
Start (or resumes, if stopped) the currently selected action.
bool choose_action(const std::string &action_name) override
Choose the current action and wait for further commands.
bool forever() override
Similar to play, but it will automatically restart the playback when the last frame is reached.
bool set_thread_period(const double value) override
Sets the period of the sampling thread (for advanced use only, default value: 0.010s).
bool print_frames() override
Prints all the frames of the currently selected action.
std::string m_current_action_id
virtual double getPeriod()
You can override this to control the approximate periodicity at which updateModule() is called by run...
virtual bool configure(yarp::os::ResourceFinder &rf)
Configure the module, pass a ResourceFinder object to the module.
bool stop() override
Stops the currently selected (running) action.
bool play_action(const std::string &action_name) override
Play an action one single time.
bool chooseActionByName(std::string id)
virtual bool close()
Close function.
bool set_initial_move_time(const double value) override
Sets the uration for the initial homing movement (for advanced use only, default value: 2s).
ControlThread * m_wthread
std::map< std::string, robotDriver * > m_robotControllers
yarpActionsPlayer_IDL Interface.
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
Utilities for manipulating the YARP network, including initialization and shutdown.
bool setPeriod(double period)
Set the (new) period of the thread.
bool start()
Call this to start the thread.
A mini-server for network communication.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
bool fromConfigFile(const std::string &fname, bool wipe=true)
Interprets a file as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
A base-class for standard YARP modules that supports ResourceFinder.
virtual int runModule()
Calls updateModule() until that returns false.
Helper class for finding config files and other external resources.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
std::string toString() const override
Return a standard text representation of the content of the object.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool isString() const
Checks if value is a string.
virtual bool asBool() const
Get boolean value.
virtual Bottle * asList() const
Get list value.
std::string toString() const override
Return a standard text representation of the content of the object.
virtual std::string asString() const
Get string value.
bool attachAsServer(yarp::os::UnbufferedContactable &port)
Tag this WireLink as a server, receiving commands via the specified port.
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
int main(int argc, char *argv[])
void delay(double seconds)
Wait for a certain number of seconds.
The main, catch-all namespace for YARP.