18 #ifndef __D4C_SERVER_H__
19 #define __D4C_SERVER_H__
26 #include <yarp/os/all.h>
27 #include <yarp/dev/all.h>
28 #include <yarp/sig/all.h>
30 #include <iCub/ctrl/pids.h>
31 #include <iCub/d4c/d4c.h>
47 yarp::sig::Vector center;
48 yarp::sig::Vector orientation;
49 yarp::sig::Vector radius;
50 yarp::sig::Vector color;
53 virtual bool fromProperty(
const yarp::os::Property &options);
54 virtual yarp::os::Property toProperty()
const;
55 virtual yarp::sig::Vector getField(
const yarp::sig::Vector &x,
56 const yarp::sig::Vector &xdot)=0;
62 class Target_MSD :
public Item
69 bool fromProperty(
const yarp::os::Property &options);
70 yarp::os::Property toProperty()
const;
71 yarp::sig::Vector getField(
const yarp::sig::Vector &x,
72 const yarp::sig::Vector &xdot);
77 class Obstacle_Gaussian :
public Item
84 bool fromProperty(
const yarp::os::Property &options);
85 yarp::os::Property toProperty()
const;
86 yarp::sig::Vector getField(
const yarp::sig::Vector &x,
87 const yarp::sig::Vector &xdot);
92 class GuiReporter :
public yarp::os::PortReport
99 void setServer(D4CServer *server);
100 void report(
const yarp::os::PortInfo &info);
104 class D4CServer :
public D4C,
105 public yarp::os::RateThread,
106 public yarp::os::PortReader
112 bool simulationEnabled;
113 bool simulationFirstStep;
115 bool initIntegration;
116 bool doInitGuiTrajectory;
124 std::string activeIF;
126 std::map<int,Item*> table;
131 yarp::sig::Vector xdot;
133 yarp::sig::Vector xhat;
134 yarp::sig::Vector qhat;
136 yarp::sig::Matrix toolFrame;
137 yarp::sig::Matrix invToolFrame;
139 iCub::ctrl::Integrator If;
140 iCub::ctrl::Integrator Iv;
142 yarp::os::Mutex mutex;
143 yarp::dev::PolyDriver dCtrlLeft;
144 yarp::dev::ICartesianControl *iCtrlLeft;
145 yarp::dev::PolyDriver dCtrlRight;
146 yarp::dev::ICartesianControl *iCtrlRight;
147 yarp::dev::ICartesianControl *iCtrlActive;
149 yarp::os::BufferedPort<yarp::os::Property> data;
150 yarp::os::BufferedPort<yarp::os::Bottle> gui;
151 yarp::os::RpcServer rpc;
153 friend class GuiReporter;
154 GuiReporter reporter;
160 std::map<int,Item*>::iterator iter;
166 GuiRequest(
const std::string &type, std::map<int,Item*>::iterator &iter)
168 std::ostringstream name;
169 name<<iter->second->name<<
":"<<std::hex<<iter->first;
173 this->name=name.str();
176 std::string getType()
const {
return type; }
177 std::string getName()
const {
return name; }
178 std::map<int,Item*>::iterator getIter()
const {
return iter; }
180 bool operator==(
const GuiRequest &req)
182 return ((type==req.type)&&(iter==req.iter));
186 std::deque<GuiRequest> guiQueue;
188 virtual void printMessage(
const int logtype,
const int level,
189 const char *format, ...)
const;
191 Item* itemFactory(
const yarp::os::Property &options);
192 bool read(yarp::os::ConnectionReader &connection);
193 void scheduleInitGuiTrajectory();
194 void initGuiTrajectory();
195 void updateGuiTrajectory();
196 void eraseGuiTrajectory();
197 void updateGuiItem(
const GuiRequest &req);
198 void eraseGuiItem(
const GuiRequest &req);
199 void pushUpdateGuiItem(std::map<int,Item*>::iterator &it);
200 void pushEraseGuiItem(std::map<int,Item*>::iterator &it);
201 void handleGuiQueue();
204 yarp::os::Property prepareData();
205 void getTargetForCartesianIF(yarp::sig::Vector &pos, yarp::sig::Vector &orien);
209 bool open(
const yarp::os::Property &options);
211 bool addItem(
const yarp::os::Property &options,
int &item);
212 bool eraseItem(
const int item);
214 bool getItems(yarp::os::Bottle &items);
215 bool setProperty(
const int item,
const yarp::os::Property &options);
216 bool getProperty(
const int item, yarp::os::Property &options);
219 bool getFieldStatus(
bool &status);
220 bool enableControl();
221 bool disableControl();
222 bool getControlStatus(
bool &status);
223 bool enableSimulation();
224 bool disableSimulation();
225 bool getSimulationStatus(
bool &status);
226 bool setPeriod(
const int period);
227 bool getPeriod(
int &period);
228 bool setPointStateToTool();
229 bool attachToolFrame(
const yarp::sig::Vector &x,
const yarp::sig::Vector &o);
230 bool getToolFrame(yarp::sig::Vector &x, yarp::sig::Vector &o);
231 bool removeToolFrame();
232 bool getTool(yarp::sig::Vector &x, yarp::sig::Vector &o);
233 bool setPointState(
const yarp::sig::Vector &x,
const yarp::sig::Vector &o,
234 const yarp::sig::Vector &xdot,
const yarp::sig::Vector &odot);
235 bool setPointOrientation(
const yarp::sig::Vector &o,
const yarp::sig::Vector &odot);
236 bool getPointState(yarp::sig::Vector &x, yarp::sig::Vector &o,
237 yarp::sig::Vector &xdot, yarp::sig::Vector &odot);
238 bool getField(yarp::sig::Vector &field);
239 bool getSimulation(yarp::sig::Vector &xhat, yarp::sig::Vector &ohat,
240 yarp::sig::Vector &qhat);
241 bool getActiveIF(std::string &activeIF);
242 bool setActiveIF(
const std::string &activeIF);
243 bool getTrajectory(std::deque<yarp::sig::Vector> &trajPos,
244 std::deque<yarp::sig::Vector> &trajOrien,
245 const unsigned int maxIterations=D4C_DEFAULT_MAXITERATIONS,
246 const double Ts=D4C_DEFAULT_TS_DISABLED);
247 bool executeTrajectory(
const std::deque<yarp::sig::Vector> &trajPos,
248 const std::deque<yarp::sig::Vector> &trajOrien,
249 const double trajTime);
250 virtual ~D4CServer();