Skip to content

Instantly share code, notes, and snippets.

@squiddon
Created November 21, 2014 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squiddon/ab9aab96e812421687dc to your computer and use it in GitHub Desktop.
Save squiddon/ab9aab96e812421687dc to your computer and use it in GitHub Desktop.
ARGoS robot turning function
void CSingleRobot::SetWheelSpeeds(const CCI_PositioningSensor::SReading& sPosReading) {
//LOG << "\n";
/* Get positioning reading */
CRadians cZAngle, cYAngle, cXAngle;
sPosReading.Orientation.ToEulerAngles(cZAngle, cYAngle, cXAngle);
// Yaw
//LOG << "Yaw: " << cZAngle << "\n";
m_cRobotDirection.Set(
Cos(cZAngle),
Sin(cZAngle)
);
m_cDesiredDirection.Set(
(m_sCurrentGoal.x - sPosReading.Position.GetX()),
(m_sCurrentGoal.y - sPosReading.Position.GetY())
);
m_cDesiredDirection.Normalize();
Real dot = (m_cRobotDirection.GetX() * m_cDesiredDirection.GetX()) +
(m_cRobotDirection.GetY() * m_cDesiredDirection.GetY());
CRadians cAngle = (ATan2(m_cRobotDirection.GetY(), m_cRobotDirection.GetX())) -
(ATan2(m_cDesiredDirection.GetY(), m_cDesiredDirection.GetX()));
LOG << "Angle: " << cAngle << std::endl;
if(m_cGoStraightAngleRange.WithinMinBoundIncludedMaxBoundIncluded(cAngle)) {
//if(check_range(cAngle.GetValue(), , 0.2)) {
// straight
m_pcWheels->SetLinearVelocity(m_fWheelVelocity, m_fWheelVelocity);
} else {
if(cAngle.GetValue() >= 0.0f) {
//if(dot < 0.0f) {
// right
m_pcWheels->SetLinearVelocity(m_fWheelVelocity, 0.0f);
} else {
// left
m_pcWheels->SetLinearVelocity(0.0f, m_fWheelVelocity);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment