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 
void limitSpeed(yarp::sig::Vector &command)
void setVel(int i, double vel)
bool init(yarp::dev::PolyDriver *d, std::string moduleName, std::string partName, std::string robotName, yarp::os::Bottle *jointsList)
void setGain(int i, double gain)