15 std::lock_guard<std::mutex> lg(m_mtx);
21 std::lock_guard<std::mutex> lg(m_mtx);
28 std::lock_guard<std::mutex> lg(m_mtx);
36 std::lock_guard<std::mutex> lg(m_mtx);
37 m_current_action->
print();
43 std::lock_guard<std::mutex> lg(m_mtx);
52 std::lock_guard<std::mutex> lg(m_mtx);
64 m_current_action->
forever =
true;
70 std::lock_guard<std::mutex> lg(m_mtx);
82 m_current_action->
forever =
false;
88 std::lock_guard<std::mutex> lg(m_mtx);
89 m_current_action = action;
90 m_current_driver = driver;
98 std::lock_guard<std::mutex> lg(m_mtx);
108 std::lock_guard<std::mutex> lg(m_mtx);
119 yInfo() <<
"Control thread period set to: " << period;
120 m_module_name = name;
126 m_port_command_out.
close();
128 m_port_command_joints.
close();
133 if (!m_port_command_out.
open(std::string(
"/")+m_module_name+
"/port_command_out:o"))
138 if (!m_port_command_joints.
open(std::string(
"/")+m_module_name+
"/port_joints:o"))
145bool ControlThread::execute_joint_command(
int frame_id)
147 if (!m_current_driver)
return false;
153 for (
size_t j = 0; j < nj; j++)
160void ControlThread::compute_and_send_command(
int frame_id)
169 m_port_command_out.
write();
172 if (!execute_joint_command(frame_id))
174 yError(
"failed to execute command");
178 std::vector<double> encs;
179 if (m_current_driver)
183 for (
size_t j = 0; j < nj; j++)
185 m_current_driver->
getEncoder((
int)j, &encs[j]);
191 yError(
"Critical error: invalid driver");
202 for (
size_t ix=0;ix<nj;ix++)
207 for (
size_t ix=0;ix<nj;ix++)
211 this->m_port_command_joints.
write();
224 for (i = 0; i < dq.size(); i++)
226 if (dq[i].time > elapsed)
234 std::lock_guard<std::mutex> lck(m_mtx);
245 yInfo() <<
"ACTION_STOP";
251 yInfo() <<
"ACTION_RESET";
253 for (
size_t j = 0; j < nj; j++)
265 yError(
"ACTION_RUNNING: sequence empty!");
278 compute_and_send_command((
int)m_current_action->
current_frame);
293 for (
size_t j = 0; j < nj; j++)
309 yDebug() <<
"ACTION_START: switch to position mode";
310 for (
size_t j = 0; j < nj; j++)
315 for (
size_t j = 0; j < nj; j++)
321 yInfo() <<
"ACTION_START: going to start position";
327 for (
size_t j = 0; j < nj; j++)
330 double err = fabs(enc - ll[j]);
331 check = (err < m_home_position_tolerance);
336 yInfo() <<
"ACTION_START: start position reached successfully";
341 yWarning() <<
"ACTION_START: timeout while trying to reach start position";
349 yDebug() <<
"ACTION_START: switch to position mode";
351 for (
int j = 0; j <nj; j++)
356 compute_and_send_command(0);
362 yError() <<
"ACTION_START: unable to reach start position!";
363 if (m_home_position_strict_check_enabled)
370 yDebug() <<
"ACTION_START: switch to position direct mode";
371 for (
int j = 0; j <nj; j++)
376 compute_and_send_command(0);
382 yInfo() <<
"ACTION_START: sequence started";
393 yError() <<
"unknown current_status";
401 m_home_position_tolerance = tolerance;
409 m_home_position_timeout = timeout;
415 m_home_position_strict_check_enabled=enable;
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION
constexpr yarp::conf::vocab32_t VOCAB_CM_POSITION_DIRECT
bool threadInit() override
Initialization method.
bool action_getname(std::string &name)
void setPositionStrictCheck(bool enable)
bool m_enable_execute_joint_command
void run() override
Loop function.
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)
ControlThread(std::string name, double period)
void setPositionTimeout(double timeloops)
void interpolate_action_frames(double timestep)
std::deque< action_frame > action_frames_vector
bool setPosition(int j, double ref)
bool setControlMode(const int j, const int mode)
bool getEncoder(int j, double *v)
bool positionMove(int j, double ref)
A simple collection of objects that can be described and transmitted in a portable way.
void addFloat64(yarp::conf::float64_t x)
Places a 64-bit floating point number in the bottle, at the end of the list.
void clear()
Empties the bottle of any objects it contains.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
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.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
size_t getCurrentFrame(double elapsed, std::deque< action_frame > &dq)
double now()
Return the current time in seconds, relative to an arbitrary starting point.
void delay(double seconds)
Wait for a certain number of seconds.