Skip to content

Commit bb86e97

Browse files
Merge pull request #32 from ci-group/diffcpgs
Revolve improvements
2 parents 27ed467 + 53f9fef commit bb86e97

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1230
-230
lines changed

cpprevolve/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ include_directories(${Boost_INCLUDE_DIRS})
6262
find_package(GSL REQUIRED)
6363
include_directories(${GSL_INCLUDE_DIRS})
6464

65+
find_package(yaml-cpp REQUIRED)
66+
include_directories(${YAML_CPP_INCLUDE_DIR})
67+
6568
# Find Gazebo
6669
# LOCAL_GAZEBO_DIR can be set to a path with a gazebo-config.cmake
6770
if (LOCAL_GAZEBO_DIR)
@@ -154,9 +157,10 @@ set_source_files_properties(
154157
# Plugin C++ files
155158
file(GLOB_RECURSE
156159
REVOLVE_GZ_SRC
157-
revolve/gazebo/brain/*.cpp
160+
revolve/gazebo/brains/*.cpp
158161
revolve/gazebo/motors/*.cpp
159162
revolve/gazebo/sensors/*.cpp
163+
revolve/gazebo/util/*.cpp
160164
revolve/gazebo/plugin/BodyAnalyzer.cpp
161165
revolve/gazebo/plugin/RobotController.cpp
162166
revolve/gazebo/plugin/WorldController.cpp
@@ -189,6 +193,7 @@ target_link_libraries(
189193
${GAZEBO_LIBRARIES}
190194
${Boost_LIBRARIES}
191195
${GSL_LIBRARIES}
196+
${YAML_CPP_LIBRARIES}
192197
)
193198

194199
# Create World plugin

cpprevolve/revolve/gazebo/Types.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
#ifndef REVOLVE_GZ_MODEL_TYPES_H_
2121
#define REVOLVE_GZ_MODEL_TYPES_H_
2222

23+
#include <memory>
2324
#include <vector>
2425

25-
#include <boost/shared_ptr.hpp>
26-
#include <boost/weak_ptr.hpp>
27-
2826
namespace revolve
2927
{
3028
namespace gazebo
@@ -41,17 +39,17 @@ namespace revolve
4139

4240
class Evaluator;
4341

44-
typedef boost::shared_ptr< Brain > BrainPtr;
42+
typedef std::shared_ptr< Brain > BrainPtr;
4543

46-
typedef boost::shared_ptr< Motor > MotorPtr;
44+
typedef std::shared_ptr< Motor > MotorPtr;
4745

48-
typedef boost::shared_ptr< VirtualSensor > SensorPtr;
46+
typedef std::shared_ptr< VirtualSensor > SensorPtr;
4947

50-
typedef boost::shared_ptr< MotorFactory > MotorFactoryPtr;
48+
typedef std::shared_ptr< MotorFactory > MotorFactoryPtr;
5149

52-
typedef boost::shared_ptr< SensorFactory > SensorFactoryPtr;
50+
typedef std::shared_ptr< SensorFactory > SensorFactoryPtr;
5351

54-
typedef boost::shared_ptr< Evaluator > EvaluatorPtr;
52+
typedef std::shared_ptr< Evaluator > EvaluatorPtr;
5553

5654
typedef std::vector< double > Spline;
5755

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <boost/shared_ptr.hpp>
2828

2929
#include <gazebo/common/common.hh>
30+
#include <gazebo/gazebo.hh>
3031

3132
#include <revolve/gazebo/Types.h>
3233

@@ -52,6 +53,9 @@ namespace revolve
5253
const std::vector< SensorPtr > &_sensors,
5354
const double _time,
5455
const double _step) = 0;
56+
57+
/// \brief Transport node
58+
protected: ::gazebo::transport::NodePtr node_;
5559
};
5660
} /* namespace gazebo */
5761
} /* namespace revolve */
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright (C) 2015-2018 Vrije Universiteit Amsterdam
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Description: TODO: <Add brief description about file purpose>
17+
* Author: Milan Jelisavcic
18+
* Date: December 23, 2018
19+
*
20+
*/
21+
22+
#include <revolve/gazebo/brains/BrainFactory.h>
23+
#include <revolve/gazebo/brains/Brains.h>
24+
25+
namespace gz = gazebo;
26+
27+
using namespace revolve::gazebo;
28+
29+
/////////////////////////////////////////////////
30+
BrainFactory::BrainFactory(::gazebo::physics::ModelPtr _model)
31+
: model_(_model)
32+
{
33+
}
34+
35+
/////////////////////////////////////////////////
36+
BrainFactory::~BrainFactory() = default;
37+
38+
///////////////////////////////////////////////////
39+
//BrainPtr BrainFactory::Brain(
40+
// sdf::ElementPtr _brainSdf,
41+
// const std::vector< MotorPtr > &_motors,
42+
// const std::vector< SensorPtr > &_sensors)
43+
//{
44+
// BrainPtr brain = nullptr;
45+
//// if ("ann" == _type)
46+
//// {
47+
//// brain.reset(new NeuralNetwork(model_, _brainSdf, _motors, _sensors));
48+
//// }
49+
//// else if ("rlpower" == _type)
50+
//// {
51+
//// brain.reset(new RLPower(model_, _brainSdf, _motors, _sensors));
52+
//// }
53+
//// else if ("diff_cpg" == type)
54+
//// {
55+
//// brain.reset(new );
56+
//// }
57+
//
58+
// return brain;
59+
//}
60+
//
61+
///////////////////////////////////////////////////
62+
//BrainPtr BrainFactory::Create(
63+
// sdf::ElementPtr _brainSdf,
64+
// const std::vector< MotorPtr > &_motors,
65+
// const std::vector< SensorPtr > &_sensors)
66+
//{
67+
//// auto typeParam = _motorSdf->GetAttribute("type");
68+
//// auto partIdParam = _motorSdf->GetAttribute("part_id");
69+
//// auto idParam = _motorSdf->GetAttribute("id");
70+
////
71+
//// if (not typeParam or not partIdParam or not idParam)
72+
//// {
73+
//// std::cerr << "Motor is missing required attributes (`id`, `type` or "
74+
//// "`part_id`)." << std::endl;
75+
//// throw std::runtime_error("Motor error");
76+
//// }
77+
////
78+
//// auto partId = partIdParam->GetAsString();
79+
//// auto type = typeParam->GetAsString();
80+
//// auto id = idParam->GetAsString();
81+
//
82+
// BrainPtr brain = nullptr;
83+
//// this->Brain(_brainSdf, _motors, _sensors);
84+
//// assert(not brain || "[BrainFactory::Create] Brain type is unknown.");
85+
//
86+
// return brain;
87+
//}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (C) 2015-2018 Vrije Universiteit Amsterdam
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Description: TODO: <Add brief description about file purpose>
17+
* Author: Milan Jelisavcic
18+
* Date: December 23, 2018
19+
*
20+
*/
21+
22+
#ifndef REVOLVE_GAZEBO_BRAINS_BRAINFACTORY_H_
23+
#define REVOLVE_GAZEBO_BRAINS_BRAINFACTORY_H_
24+
25+
#include <string>
26+
27+
#include <gazebo/common/common.hh>
28+
29+
#include <revolve/gazebo/Types.h>
30+
31+
namespace revolve
32+
{
33+
namespace gazebo
34+
{
35+
class BrainFactory
36+
{
37+
/// \brief Constructor
38+
/// \param[in] _model Model identifier
39+
public: explicit BrainFactory(::gazebo::physics::ModelPtr _model);
40+
41+
/// \brief Destructor
42+
public: virtual ~BrainFactory();
43+
44+
/// \brief Returns a brain pointer reference from a brain element.
45+
/// This is the convenience wrapper over `create` that has required
46+
/// attributes already checked, usually you should override this when
47+
/// adding new brain types.
48+
public: virtual BrainPtr Brain(
49+
sdf::ElementPtr _brainSdf,
50+
const std::vector< MotorPtr > &_motors,
51+
const std::vector< SensorPtr > &_sensors);
52+
53+
/// \brief Creates a brain for the given model for the given SDF element.
54+
public: virtual BrainPtr Create(
55+
sdf::ElementPtr _brainSdf,
56+
const std::vector< MotorPtr > &_motors,
57+
const std::vector< SensorPtr > &_sensors);
58+
59+
/// \brief Internal reference to the robot model
60+
protected: ::gazebo::physics::ModelPtr model_;
61+
};
62+
}
63+
}
64+
65+
#endif // REVOLVE_GAZEBO_BRAINS_BRAINFACTORY_H_
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (C) 2015-2018 Vrije Universiteit Amsterdam
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Description: TODO: <Add brief description about file purpose>
17+
* Author: Milan Jelisavcic
18+
* Date: Mar 16, 2015
19+
*
20+
*/
21+
22+
#ifndef REVOLVE_GAZEBO_BRAINS_BRAINS_H_
23+
#define REVOLVE_GAZEBO_BRAINS_BRAINS_H_
24+
25+
#include <revolve/gazebo/brains/DifferentialCPG.h>
26+
#include <revolve/gazebo/brains/NeuralNetwork.h>
27+
#include <revolve/gazebo/brains/RLPower.h>
28+
29+
#endif // REVOLVE_GAZEBO_BRAINS_BRAINS_H_
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (C) 2015-2018 Vrije Universiteit Amsterdam
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* Description: TODO: <Add brief description about file purpose>
17+
* Author: Milan Jelisavcic
18+
* Date: December 29, 2018
19+
*
20+
*/
21+
22+
#include "DifferentialCPG.h"
23+
#include "../motors/Motor.h"
24+
#include "../sensors/Sensor.h"
25+
#include "../util/YamlBodyParser.h"
26+
27+
namespace gz = gazebo;
28+
29+
using namespace revolve::gazebo;
30+
31+
/////////////////////////////////////////////////
32+
DifferentialCPG::DifferentialCPG(
33+
const ::gazebo::physics::ModelPtr &_model,
34+
const sdf::ElementPtr &_node,
35+
const std::vector< revolve::gazebo::MotorPtr > &_motors,
36+
const std::vector< revolve::gazebo::SensorPtr > &_sensors)
37+
: flipState_(false)
38+
{
39+
// Create transport node
40+
this->node_.reset(new gz::transport::Node());
41+
this->node_->Init();
42+
43+
auto name = _model->GetName();
44+
// Listen to network modification requests
45+
// alterSub_ = node_->Subscribe(
46+
// "~/" + name + "/modify_diff_cpg", &DifferentialCPG::Modify,
47+
// this);
48+
49+
auto numMotors = _motors.size();
50+
auto numSensors = _sensors.size();
51+
52+
auto genome = _node->GetAttribute("genome")->GetAsString();
53+
auto parser = new YamlBodyParser(genome);
54+
55+
56+
}
57+
58+
/////////////////////////////////////////////////
59+
DifferentialCPG::~DifferentialCPG() = default;
60+
61+
/////////////////////////////////////////////////
62+
void DifferentialCPG::Update(
63+
const std::vector< revolve::gazebo::MotorPtr > &_motors,
64+
const std::vector< revolve::gazebo::SensorPtr > &_sensors,
65+
const double _time,
66+
const double _step)
67+
{
68+
}

0 commit comments

Comments
 (0)