RcsPySim
A robot control and simulation library
RcsPyBot.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (c) 2020, Fabio Muratore, Honda Research Institute Europe GmbH, and
3  Technical University of Darmstadt.
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without
7  modification, are permitted provided that the following conditions are met:
8  1. Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  2. Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  3. Neither the name of Fabio Muratore, Honda Research Institute Europe GmbH,
14  or Technical University of Darmstadt, nor the names of its contributors may
15  be used to endorse or promote products derived from this software without
16  specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  DISCLAIMED. IN NO EVENT SHALL FABIO MURATORE, HONDA RESEARCH INSTITUTE EUROPE GMBH,
22  OR TECHNICAL UNIVERSITY OF DARMSTADT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  POSSIBILITY OF SUCH DAMAGE.
29 *******************************************************************************/
30 
31 #ifndef _RCSPYBOT_H_
32 #define _RCSPYBOT_H_
33 
34 #include "ExperimentConfig.h"
35 #include "DataLogger.h"
36 
37 #include <Rcs_filters.h>
38 #include <MotionControlLayer.h>
39 
40 #include <mutex>
41 
42 namespace Rcs
43 {
44 
45 class ActionModel;
46 
47 class ObservationModel;
48 
49 class ControlPolicy;
50 
51 class RcsPyBot : public MotionControlLayer
52 {
53 public:
54  /**
55  * Create the bot from the given property source.
56  * @param propertySource configuration
57  */
58  explicit RcsPyBot(PropertySource* propertySource);
59 
60  virtual ~RcsPyBot();
61 
62  // not copy- or movable
64 
66 
67  /**
68  * Replace the control policy.
69  * This method may be called while the bot is running.
70  * Setting `controlPolicy` to`nullptr` and `q_des` to a joint config causes the bot to go to this configuration.
71  * Does **not** take ownership.
72  */
73  void setControlPolicy(ControlPolicy* controlPolicy, const MatNd* q_des = nullptr);
74 
75  void syncGraphsToCurrent();
76 
78  {
79  std::unique_lock<std::mutex> lock(controlPolicyMutex);
80  return controlPolicy;
81  }
82 
83  //! Data logger
85 
86  /**
87  * Get storage matrix for current observation.
88  *
89  * WARNING: the contents may update asynchronously. The dimensions are constant.
90  */
91  MatNd* getObservation() const;
92 
93  /**
94  * Get storage matrix for current action.
95  *
96  * WARNING: the contents may update asynchronously. The dimensions are constant.
97  */
98  MatNd* getAction() const;
99 
100  //! Filter for going to the home pose
101  Rcs::SecondOrderLPFND* homePoseFilt;
102 
103 protected:
104  virtual void updateControl();
105 
106  //! Control policy mutex (mutable to allow using it from const functions)
107  mutable std::mutex controlPolicyMutex;
108 
109  //! Experiment configuration
112 
113  //! Control policy
115 
116  //! Temporary matrices
117  MatNd* q_ctrl;
118  MatNd* qd_ctrl;
119  MatNd* T_ctrl;
120 
121  MatNd* observation;
122  MatNd* action;
123 };
124 
125 } /* namespace Rcs */
126 
127 #endif /* _RCSPYBOT_H_ */
std::mutex controlPolicyMutex
Control policy mutex (mutable to allow using it from const functions)
Definition: RcsPyBot.h:107
RcsPyBot(PropertySource *propertySource)
Definition: RcsPyBot.cpp:66
MatNd * observation
Definition: RcsPyBot.h:121
MatNd * getAction() const
Definition: RcsPyBot.cpp:201
void syncGraphsToCurrent()
Definition: RcsPyBot.cpp:206
MatNd * q_ctrl
Temporary matrices.
Definition: RcsPyBot.h:117
bool allJointsPosCtrl
Definition: RcsPyBot.h:111
MatNd * qd_ctrl
Definition: RcsPyBot.h:118
ControlPolicy * getControlPolicy() const
Definition: RcsPyBot.h:77
#define RCSPYSIM_NOCOPY_NOMOVE(cls)
Definition: nocopy.h:40
virtual ~RcsPyBot()
Definition: RcsPyBot.cpp:107
ExperimentConfig * getConfig()
Definition: RcsPyBot.h:65
MatNd * getObservation() const
Definition: RcsPyBot.cpp:196
ControlPolicy * controlPolicy
Control policy.
Definition: RcsPyBot.h:114
Rcs::SecondOrderLPFND * homePoseFilt
Filter for going to the home pose.
Definition: RcsPyBot.h:101
ExperimentConfig * config
Experiment configuration.
Definition: RcsPyBot.h:110
virtual void updateControl()
Definition: RcsPyBot.cpp:156
void setControlPolicy(ControlPolicy *controlPolicy, const MatNd *q_des=nullptr)
Definition: RcsPyBot.cpp:129
DataLogger logger
Data logger.
Definition: RcsPyBot.h:84
MatNd * action
Definition: RcsPyBot.h:122
MatNd * T_ctrl
Definition: RcsPyBot.h:119