Skip to content

Commit

Permalink
Added handbrake to CarState
Browse files Browse the repository at this point in the history
  • Loading branch information
kissslorinc committed Apr 20, 2018
1 parent d620563 commit 04691ed
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions AirLib/include/vehicles/car/api/CarApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ class CarApiBase : public VehicleApiBase {
int gear;
float rpm;
float maxrpm;
bool handbrake;
CollisionInfo collision;
Kinematics::State kinematics_true;
uint64_t timestamp;

CarState(float speed_val, int gear_val, float rpm_val, float maxrpm_val, const CollisionInfo& collision_val,
CarState(float speed_val, int gear_val, float rpm_val, float maxrpm_val, bool handbrake_val, const CollisionInfo& collision_val,
const Kinematics::State& kinematics_true_val, uint64_t timestamp_val)
: speed(speed_val), gear(gear_val), collision(collision_val), kinematics_true(kinematics_true_val), timestamp(timestamp_val),
rpm(rpm_val), maxrpm(maxrpm_val)
rpm(rpm_val), maxrpm(maxrpm_val), handbrake(handbrake_val)
{
}
};
Expand Down
6 changes: 4 additions & 2 deletions AirLib/include/vehicles/car/api/CarRpcLibAdapators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ class CarRpcLibAdapators : public RpcLibAdapatorsBase {
int gear;
float rpm;
float maxrpm;
bool handbrake;
CollisionInfo collision;
KinematicsState kinematics_true; //ground truth
uint64_t timestamp;

MSGPACK_DEFINE_MAP(speed, gear, rpm, maxrpm, collision, kinematics_true, timestamp);
MSGPACK_DEFINE_MAP(speed, gear, rpm, maxrpm, handbrake, collision, kinematics_true, timestamp);

CarState()
{}
Expand All @@ -67,14 +68,15 @@ class CarRpcLibAdapators : public RpcLibAdapatorsBase {
gear = s.gear;
rpm = s.rpm;
maxrpm = s.maxrpm;
handbrake = s.handbrake;
collision = s.collision;
kinematics_true = s.kinematics_true;
timestamp = s.timestamp;
}
msr::airlib::CarApiBase::CarState to() const
{
return msr::airlib::CarApiBase::CarState(
speed, gear, rpm, maxrpm, collision.to(), kinematics_true.to(), timestamp);
speed, gear, rpm, maxrpm, handbrake, collision.to(), kinematics_true.to(), timestamp);
}
};
};
Expand Down
16 changes: 9 additions & 7 deletions Unreal/Plugins/AirSim/Source/Car/CarPawnApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void CarPawnApi::setCarControls(const CarApiBase::CarControls& controls)
{
if (api_control_enabled_)
last_controls_ = controls;
//else don't save
//else only save handbrake state
else last_controls_.handbrake = controls.handbrake;

if (!controls.is_manual_gear && movement_->GetTargetGear() < 0)
movement_->SetTargetGear(0, true); //in auto gear we must have gear >= 0
Expand Down Expand Up @@ -101,12 +102,13 @@ void CarPawnApi::setCameraOrientation(int camera_id, const msr::airlib::Quaterni

CarApiBase::CarState CarPawnApi::getCarState() const
{
CarApiBase::CarState state(
movement_->GetForwardSpeed() / 100, //cm/s -> m/s
movement_->GetCurrentGear(),
movement_->GetEngineRotationSpeed(),
movement_->GetEngineMaxRotationSpeed(),
pawn_->getCollisionInfo(),
CarApiBase::CarState state(
movement_->GetForwardSpeed() / 100, //cm/s -> m/s
movement_->GetCurrentGear(),
movement_->GetEngineRotationSpeed(),
movement_->GetEngineMaxRotationSpeed(),
last_controls_.handbrake,
pawn_->getCollisionInfo(),
*pawn_->getTrueKinematics(),
msr::airlib::ClockFactory::get()->nowNanos()
);
Expand Down

0 comments on commit 04691ed

Please sign in to comment.