Skip to content
Snippets Groups Projects
Commit 814bd080 authored by Mirko Wächter's avatar Mirko Wächter
Browse files

Merge branch 'RTRobotUnitV2' of https://gitlab.com/ArmarX/RobotAPI into RTRobotUnitV2

parents 9c270394 886ec95f
No related branches found
No related tags found
1 merge request!26Rt robot unit v2
......@@ -44,23 +44,34 @@ namespace armarx
startTime = sensorValuesTimestamp;
}
auto timeSinceStart = sensorValuesTimestamp - startTime;
auto positions = trajectory.getStates(timeSinceStart.toSecondsDouble(), 0);
auto velocities = trajectory.getStates(timeSinceStart.toSecondsDouble(), 1);
// size_t dim = trajectory->dim();
for (size_t d = 0; d < targets.size(); ++d)
if (timeSinceStart.toSecondsDouble() > duration)
{
ARMARX_CHECK_EXPRESSION(d < targets.size());
ARMARX_CHECK_EXPRESSION(d < PIDs.size());
ARMARX_CHECK_EXPRESSION(d < sensors.size());
ARMARX_CHECK_EXPRESSION(d < positions.size());
ARMARX_CHECK_EXPRESSION(d < velocities.size());
PIDControllerPtr& pid = PIDs.at(d);
pid->update(timeSinceLastIteration.toSecondsDouble(),
sensors.at(d)->position,
positions.at(d));
double newVel = pid->getControlValue();
newVel += velocities.at(1);
targets.at(d)->velocity = newVel;
for (size_t d = 0; d < targets.size(); ++d)
{
targets.at(d)->velocity = 0;
}
}
else
{
auto positions = trajectory.getStates(timeSinceStart.toSecondsDouble(), 0);
auto velocities = trajectory.getStates(timeSinceStart.toSecondsDouble(), 1);
// size_t dim = trajectory->dim();
for (size_t d = 0; d < targets.size(); ++d)
{
ARMARX_CHECK_EXPRESSION(d < targets.size());
ARMARX_CHECK_EXPRESSION(d < PIDs.size());
ARMARX_CHECK_EXPRESSION(d < sensors.size());
ARMARX_CHECK_EXPRESSION(d < positions.size());
ARMARX_CHECK_EXPRESSION(d < velocities.size());
PIDControllerPtr& pid = PIDs.at(d);
pid->update(timeSinceLastIteration.toSecondsDouble(),
sensors.at(d)->position,
positions.at(d));
double newVel = pid->getControlValue();
newVel += velocities.at(1);
targets.at(d)->velocity = newVel;
}
}
TIMING_END(TrajectoryControl);
......@@ -95,7 +106,7 @@ namespace armarx
TrajectoryPtr newTraj = new Trajectory();
Ice::DoubleSeq newTimestamps;
double duration = timeOptimalTraj.getDuration();
duration = timeOptimalTraj.getDuration();
for (double t = 0.0; t < duration; t += timeStep)
{
newTimestamps.push_back(t);
......@@ -127,6 +138,7 @@ namespace armarx
}
newTraj->setDimensionNames(trajectory->getDimensionNames());
TIMING_END(TrajectoryOptimization);
ARMARX_INFO << "Trajectory duration: " << newTraj->getTimeLength();
LockGuardType guard {controlDataMutex};
getWriterControlStruct().trajectory = newTraj;
writeControlStruct();
......
......@@ -38,6 +38,7 @@ namespace armarx
private:
// TrajectoryPtr trajectory;
IceUtil::Time startTime;
double duration = 0;
std::vector<PIDControllerPtr> PIDs;
std::vector<ControlTarget1DoFActuatorVelocity*> targets;
std::vector<const SensorValue1DoFActuatorPosition*> sensors;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment