Skip to content

Commit 2eb374e

Browse files
committed
Fix bugs with diff-drive dynamics (#115)
1 parent feb37aa commit 2eb374e

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

src/rlenvs/dynamics/diff_drive_dynamics.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DiffDriveDynamics::integrate_state_v1(const SysState<3>& state, real_t tol, real
2020
if(std::fabs(w) < tol){
2121

2222
/// assume zero angular velocity
23-
auto distance = 0.5*v*dt;
23+
auto distance = 0.5 * v * dt;
2424
auto xincrement = (distance + errors[0])*std::cos(values[2] + errors[1]);
2525
auto yincrement = (distance + errors[0])*std::sin(values[2] + errors[1]);
2626

@@ -29,7 +29,7 @@ DiffDriveDynamics::integrate_state_v1(const SysState<3>& state, real_t tol, real
2929
}
3030
else{
3131

32-
other[2] += w*dt + errors[1];
32+
other[2] += w * dt + errors[1];
3333

3434
/// clip the value
3535
if(std::fabs(state[2]) > rlenvscpp::consts::maths::PI){
@@ -215,7 +215,7 @@ DiffDriveDynamics::initialize_matrices(const DiffDriveDynamics::input_type& inpu
215215
set_matrix_update_flag(true);
216216

217217
if(!this->has_matrix("F")){
218-
matrix_type F = matrix_type::Zero(3, 2); //(3,3, 0.0);
218+
matrix_type F = matrix_type::Zero(3, 3); //(3,3, 0.0);
219219
this->set_matrix("F", F);
220220
}
221221

@@ -235,8 +235,8 @@ DiffDriveDynamics::update_matrices(const DiffDriveDynamics::input_type& input){
235235
auto v = rlenvscpp::utils::template resolve<real_t>("v", input);
236236
auto errors = rlenvscpp::utils::template resolve<std::array<real_t, 2>>("errors", input);
237237

238-
auto distance = 0.5*v*get_time_step();
239-
auto orientation = w*get_time_step();
238+
auto distance = 0.5 * v * get_time_step();
239+
auto orientation = w * get_time_step();
240240
auto values = this->state_.get_values();
241241

242242
if(std::fabs(w) < tol_){

src/rlenvs/dynamics/system_state.h

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ class SysState
123123
/// \brief Set the values of state variables
124124
/// container must be of size dim.
125125
///
126-
template<typename Container>
127-
void set(const Container& container);
126+
void add(const DynVec<real_t>& container);
127+
128+
///
129+
/// \brief Set the values of state variables
130+
/// container must be of size dim.
131+
///
132+
void add(const std::vector<real_t>& container);
128133

129134
///
130135
/// \brief Returns the size of the system
@@ -196,14 +201,6 @@ class SysState
196201
///
197202
const std::string as_string()const;
198203

199-
///
200-
/// \brief increment the analogous entries of the
201-
/// state with the entries in the container
202-
/// The container must have same size as the state
203-
///
204-
template<typename Container>
205-
void add(const Container& container);
206-
207204
///
208205
/// \brief Scale the values of the state
209206
///
@@ -579,9 +576,23 @@ SysState<dim>::as_string()const{
579576
}
580577

581578
template<int dim>
582-
template<typename Container>
583579
void
584-
SysState<dim>::add(const Container& container){
580+
SysState<dim>::add(const DynVec<real_t>& container){
581+
if(container.size() != dim){
582+
throw std::logic_error("Invalid container size for update. "+
583+
std::to_string(container.size())+
584+
" should be"+
585+
std::to_string(dim));
586+
}
587+
588+
for(uint_t i=0; i<dim; ++i){
589+
values_[i].second += container[i];
590+
}
591+
}
592+
593+
template<int dim>
594+
void
595+
SysState<dim>::add(const std::vector<real_t>& container){
585596
if(container.size() != dim){
586597
throw std::logic_error("Invalid container size for update. "+
587598
std::to_string(container.size())+

0 commit comments

Comments
 (0)