Skip to content

Commit

Permalink
move json serialization to calculator_cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
pantor committed Oct 4, 2023
1 parent adb4c09 commit faa8b63
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 26 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if(BUILD_CLOUD_CLIENT)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third_party>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_compile_definitions(ruckig PUBLIC WITH_CLOUD_CLIENT WITH_SERIALIZATION)
target_compile_definitions(ruckig PUBLIC WITH_CLOUD_CLIENT)
endif()


Expand Down
8 changes: 0 additions & 8 deletions include/ruckig/brake.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include <cmath>
#include <iostream>

#ifdef WITH_SERIALIZATION
#include <json/json.hpp>
#endif

#include <ruckig/utils.hpp>


Expand Down Expand Up @@ -73,10 +69,6 @@ class BrakeProfile {
v[0] = vs;
std::tie(ps, vs, as) = integrate(t[0], ps, vs, a[0], 0.0);
}

#ifdef WITH_SERIALIZATION
NLOHMANN_DEFINE_TYPE_INTRUSIVE(BrakeProfile, duration, t, j, a, v, p)
#endif
};

} // namespace ruckig
4 changes: 4 additions & 0 deletions include/ruckig/calculator_cloud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class CloudClient {
};


NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(BrakeProfile, duration, t, j, a, v, p)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Profile, t, t_sum, j, a, v, p, pf, vf, af, brake, accel)


//! Calculation class for a trajectory along waypoints.
template<size_t DOFs, template<class, size_t> class CustomVector = StandardVector>
class WaypointsCalculator {
Expand Down
12 changes: 3 additions & 9 deletions include/ruckig/profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
#include <limits>
#include <optional>

#ifdef WITH_SERIALIZATION
#include <json/json.hpp>
#endif

#include <ruckig/brake.hpp>
#include <ruckig/roots.hpp>
#include <ruckig/utils.hpp>
Expand All @@ -29,7 +25,9 @@ struct PositionExtrema {
};


//! A single-dof kinematic profile with position, velocity, acceleration and jerk
//! @brief A single-dof kinematic profile with position, velocity, acceleration and jerk
//!
//! The class members are only available in the Ruckig Community Version.
class Profile {
constexpr static double v_eps {1e-12};
constexpr static double a_eps {1e-12};
Expand Down Expand Up @@ -529,10 +527,6 @@ class Profile {
}
return result;
}

#ifdef WITH_SERIALIZATION
NLOHMANN_DEFINE_TYPE_INTRUSIVE(Profile, t, t_sum, j, a, v, p, pf, vf, af, brake, accel)
#endif
};

} // namespace ruckig
4 changes: 2 additions & 2 deletions include/ruckig/trajectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ template<size_t, template<class, size_t> class> class TargetCalculator;
template<size_t, template<class, size_t> class> class WaypointsCalculator;


//! Interface for the generated trajectory.
//! The trajectory generated by the Ruckig algorithm.
template<size_t DOFs, template<class, size_t> class CustomVector = StandardVector>
class Trajectory {
#if defined WITH_CLOUD_CLIENT
Expand Down Expand Up @@ -245,7 +245,7 @@ class Trajectory {
}


//! Get the underlying profiles of the trajectory
//! Get the underlying profiles of the trajectory (only in the Ruckig Community Version)
Container<Vector<Profile>> get_profiles() const {
return profiles;
}
Expand Down
2 changes: 1 addition & 1 deletion test/plot_waypoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def walk_through_trajectory(otg, inp):
i = 1
while out_list[i].new_calculation:
print(f'{i}\tCalculation duration: {out_list[i].calculation_duration:0.1f} [µs]')
print(f'\tTrajectory duration: {i*otg.delta_time + out_list[i].trajectory.duration:0.4f} [s]')
print(f'\tTrajectory duration: {i * otg.delta_time + out_list[i].trajectory.duration:0.4f} [s]')
i += 1

Plotter.plot_trajectory('otg_trajectory.png', otg, inp, out_list, plot_jerk=False, time_offsets=time_offsets)
10 changes: 5 additions & 5 deletions test/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def plot_trajectory(filename, otg, inp, out_list, show=False, plot_acceleration=
global_min = min(global_min, np.min(dddqaxis[:, dof]))

plt.subplot(inp.degrees_of_freedom, 1, dof + 1)
plt.ylabel(f'DoF {dof+1}')
plt.plot(taxis, qaxis[:, dof], label=f'Position {dof+1}')
plt.plot(taxis, dqaxis[:, dof], label=f'Velocity {dof+1}')
plt.ylabel(f'DoF {dof + 1}')
plt.plot(taxis, qaxis[:, dof], label=f'Position {dof + 1}')
plt.plot(taxis, dqaxis[:, dof], label=f'Velocity {dof + 1}')
if plot_acceleration:
plt.plot(taxis, ddqaxis[:, dof], label=f'Acceleration {dof+1}')
plt.plot(taxis, ddqaxis[:, dof], label=f'Acceleration {dof + 1}')
if plot_jerk:
plt.plot(taxis, dddqaxis[:, dof], label=f'Jerk {dof+1}')
plt.plot(taxis, dddqaxis[:, dof], label=f'Jerk {dof + 1}')

# Plot sections
if hasattr(out_list[-1], 'trajectory'):
Expand Down

0 comments on commit faa8b63

Please sign in to comment.