iCub-main
positionDirectThread.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 // Copyright (C) 2015 Istituto Italiano di Tecnologia - iCub Facility
3 // Author: Marco Randazzo <marco.randazzo@iit.it>
4 // CopyPolicy: Released under the terms of the GNU GPL v2.0.
5 
6 #ifndef __POSDIRCONTROLTHREAD__
7 #define __POSDIRCONTROLTHREAD__
8 
9 #include <mutex>
10 #include <string>
11 
12 #include <yarp/os/PeriodicThread.h>
13 #include <yarp/os/Bottle.h>
14 #include <yarp/dev/ControlBoardInterfaces.h>
15 #include <yarp/dev/PolyDriver.h>
16 #include <yarp/sig/Vector.h>
17 #include <yarp/os/Time.h>
18 
19 class positionDirectControlThread: public yarp::os::PeriodicThread
20 {
21 private:
22  char robotName[255];
23  yarp::dev::IPositionDirect *idir;
24  yarp::dev::IControlLimits *ilim;
25  yarp::dev::IPositionControl *ipos;
26  yarp::dev::IEncoders *ienc;
27  yarp::dev::IControlMode *imod;
28 
29  unsigned int part_joints;
30  unsigned int control_joints;
31  int* control_joints_list;
32 
33  yarp::dev::PolyDriver *driver;
34 
35  yarp::sig::Vector min_limits;
36  yarp::sig::Vector max_limits;
37  yarp::sig::Vector encoders;
38 
39  yarp::sig::Vector targets;
40  yarp::sig::Vector prev_targets;
41 
42  yarp::sig::Vector error;
43  std::mutex _mutex;
44 
45  bool suspended;
46 
47  int control_period;
48  double t_start;
49 
50  yarp::os::BufferedPort<yarp::os::Bottle> command_port;
51 
52 public:
57 
58  bool init(yarp::dev::PolyDriver *d, std::string moduleName, std::string partName, std::string robotName, yarp::os::Bottle* jointsList);
59 
60  void halt();
61  void go();
62 
63  void setVel(int i, double vel);
64  void setGain(int i, double gain);
65 
66  void run();
67  bool threadInit();
68  void threadRelease();
69 
70  void limitSpeed(yarp::sig::Vector &command);
71 };
72 
73 #endif
74 
positionDirectControlThread::limitSpeed
void limitSpeed(yarp::sig::Vector &command)
Definition: positionDirectThread.cpp:258
positionDirectControlThread::run
void run()
Definition: positionDirectThread.cpp:33
positionDirectControlThread::init
bool init(yarp::dev::PolyDriver *d, std::string moduleName, std::string partName, std::string robotName, yarp::os::Bottle *jointsList)
Definition: positionDirectThread.cpp:131
positionDirectControlThread::threadInit
bool threadInit()
Definition: positionDirectThread.cpp:113
positionDirectControlThread::halt
void halt()
Definition: positionDirectThread.cpp:235
positionDirectControlThread::threadRelease
void threadRelease()
Definition: positionDirectThread.cpp:120
string
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}") include_directories($
Definition: CMakeLists.txt:9
positionDirectControlThread::go
void go()
Definition: positionDirectThread.cpp:241
positionDirectControlThread::positionDirectControlThread
positionDirectControlThread(int rate)
Definition: positionDirectThread.cpp:19
positionDirectControlThread::~positionDirectControlThread
~positionDirectControlThread()
Definition: positionDirectThread.cpp:29
positionDirectControlThread::setGain
void setGain(int i, double gain)
Definition: positionDirectThread.cpp:252
positionDirectControlThread::joints_limiter
double joints_limiter
Definition: positionDirectThread.h:53
positionDirectControlThread::setVel
void setVel(int i, double vel)
Definition: positionDirectThread.cpp:247
positionDirectControlThread::target_limiter
double target_limiter
Definition: positionDirectThread.h:54
positionDirectControlThread
Definition: positionDirectThread.h:19