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;
73 yInfo() <<
"cleanup complete";
92 yError() <<
"action id not found";
101 if (!driver || !action)
103 yError() <<
"invalid driver/action pointer";
106 yInfo() <<
"action selected:" << id;
107 yDebug() <<
"action controller:" << controller_name;
114 std::string ss =
"actions:\n";
118 ss = ss +
"(" + std::to_string(i++) +
") " + it->second.action_name +
"\n";
128 yError() <<
"Unable to read configuration file!";
133 if (bot_cont.
size() == 0)
135 yError() <<
"Unable to read CONTROLLERS section";
138 size_t num_of_controllers = bot_cont.
size();
139 for (
size_t i = 1; i < num_of_controllers; i++)
143 size_t num_of_celems = bot_cont_elem->
size();
144 if (bot_cont_elem && num_of_celems == 3)
147 std::string controller_name = bot_cont_elem->
get(0).
toString();
148 std::string remoteControlBoards = bot_cont_elem->
get(1).
toString();
149 std::string axesNames = bot_cont_elem->
get(2).
toString();
152 rmoptions.
put(
"remoteControlBoards", bot_cont_elem->
get(1));
153 rmoptions.
put(
"axesNames", bot_cont_elem->
get(2));
154 rmoptions.
put(
"localPortPrefix",
m_name +
"/controller/" + controller_name);
159 rob_ok &= rob->
init();
162 yError() <<
"Unable to initialize controller" << controller_name;
170 yError() <<
"Invalid entry in CONTROLLERS section";
176 if (bot_action.
size() == 0)
178 yError() <<
"Unable to read ACTIONS section";
181 for (
size_t i = 1; i < bot_action.
size(); i++)
183 std::string str = bot_action.
toString();
186 size_t num_of_aelems = bot_act_elem->
size();
187 if (bot_act_elem && num_of_aelems==3)
190 std::string action_name = bot_act_elem->
get(0).
toString();
191 std::string controller_name = bot_act_elem->
get(1).
toString();
192 std::string action_file_name = bot_act_elem->
get(2).
toString();
197 yError() << controller_name <<
"in action" << action_name <<
"does not exists";
207 if (!tmpAction.
openFile(action_file_name, njoints, 0.010))
209 yError() <<
"Unable to parse file";
212 if (resample_period!=0.0)
222 yError() <<
"Invalid entry in ACTIONS section";
227 yInfo() <<
"configuration file successfully loaded";
234 yInfo() <<
"Command line:";
235 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] ";
237 yInfo() <<
"`name` : file containing the actions";
238 yInfo() <<
"`module_name` : prefix of the ports opened by the module (default: /yarpActionsPlayer)";
239 yInfo() <<
"`execute` : if enabled, the yarpActionsPlayer will send commands to the robot. Otherwise, only it will operate in simulation mode only";
240 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";
241 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";
242 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";
243 yInfo() <<
"`period` : the period (in s) of the thread processing the commands. Default 0.010s";
244 yInfo() <<
"`resample`: all the loaded trajectory files are internally resampled at the specified period. Default: not enabled";
250 std::string test_string = rf.
toString();
253 if (rf.
check(
"name"))
256 m_name =
"/yarpActionsPlayer";
263 double period = 0.005;
264 if (rf.
check(
"period") ==
true)
273 if (rf.
check(
"execute")==
true)
275 yInfo() <<
"Enabling iPid->setReference() controller";
280 yInfo() <<
"Not using iPid->setReference() controller";
285 if (rf.
check(
"help") ==
true)
292 if (rf.
check(
"pos_tolerance") ==
true)
295 yInfo() <<
"Position tolerance set to " << tol <<
"degrees";
300 if (rf.
check(
"pos_timeout") ==
true)
303 yInfo() <<
"Position timeout set to " << timeout <<
"seconds";
308 if (rf.
check(
"pos_strict_check") ==
true)
310 bool enable = rf.
find(
"pos_strict_check").
asBool();
314 double resample_period = 0;
315 if (rf.
check(
"resample") ==
true)
318 yInfo() <<
"Set resample period equal to:" << resample_period <<
"s";
322 if (rf.
check(
"filename")==
true)
330 yError() <<
"Configuration error!";
336 yError() <<
"`filename` option syntax error.";
343 yWarning() <<
"`filename` option not found. No sequence files loaded.";
349 yInfo() <<
"There are no actions!";
354 yInfo() <<
"automatically selecting the first action";
355 std::string first_action_name;
356 first_action_name = this->m_actions.begin()->first;
362 yError() <<
"Working thread did not start, queue will not work";
366 yInfo() <<
"Working thread started";
369 yInfo() <<
"module successfully configured. ready.";
385int main(
int argc,
char *argv[])
393 if (!
yarp.checkNetwork())
395 yError() <<
"yarp.checkNetwork() failed.";
459 std::string current_action_name;
461 yInfo() <<
"current_action: " <<current_action_name;
462 yInfo() << actions_str;
471 yError(
"invalid period value");
475 yInfo(
"Period 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
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.
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.