mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
Add simple motor simulation classes (#1117)
This commit is contained in:
committed by
Peter Johnson
parent
57fc614074
commit
76c901ce78
@@ -0,0 +1,22 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class EncoderSim {
|
||||
public:
|
||||
virtual void SetPosition(double position) = 0;
|
||||
virtual void SetVelocity(double velocity) = 0;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EncoderSim.h"
|
||||
#include "MotorSim.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class MotorEncoderConnector {
|
||||
public:
|
||||
MotorEncoderConnector(MotorSim& motorController, EncoderSim& encoder);
|
||||
|
||||
void Update();
|
||||
|
||||
private:
|
||||
MotorSim& motorSimulator;
|
||||
EncoderSim& encoderSimulator;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,28 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class MotorModel {
|
||||
public:
|
||||
virtual void Reset() = 0;
|
||||
virtual void SetVoltage(double voltage) = 0;
|
||||
virtual void Update(double elapsedTime) = 0;
|
||||
|
||||
virtual double GetPosition() const = 0;
|
||||
virtual double GetVelocity() const = 0;
|
||||
virtual double GetAcceleration() const = 0;
|
||||
virtual double GetCurrent() const = 0;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,40 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LowFiSim/MotorModel/MotorModel.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class SimpleMotorModel : public MotorModel {
|
||||
public:
|
||||
explicit SimpleMotorModel(double maxSpeed);
|
||||
|
||||
void Reset() override;
|
||||
void SetVoltage(double voltage) override;
|
||||
void Update(double elapsedTime) override;
|
||||
|
||||
double GetPosition() const override;
|
||||
double GetVelocity() const override;
|
||||
double GetAcceleration() const override;
|
||||
double GetCurrent() const override;
|
||||
|
||||
protected:
|
||||
double m_maxSpeed;
|
||||
double m_voltagePercentage{0};
|
||||
double m_position{0};
|
||||
double m_velocity{0};
|
||||
|
||||
static constexpr double kMaxExpectedVoltage = 12;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,23 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class MotorSim {
|
||||
public:
|
||||
virtual double GetPosition() const = 0;
|
||||
virtual double GetVelocity() const = 0;
|
||||
virtual double GetAcceleration() const = 0;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,30 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LowFiSim/EncoderSim.h"
|
||||
#include "Simulation/EncoderSim.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class WpiEncoderSim : public EncoderSim {
|
||||
public:
|
||||
explicit WpiEncoderSim(int index);
|
||||
|
||||
void SetPosition(double position) override;
|
||||
void SetVelocity(double velocity) override;
|
||||
|
||||
protected:
|
||||
frc::sim::EncoderSim m_encoderSimulator;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
@@ -0,0 +1,36 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "LowFiSim/MotorModel/MotorModel.h"
|
||||
#include "LowFiSim/MotorSim.h"
|
||||
#include "Simulation/PWMSim.h"
|
||||
|
||||
namespace frc {
|
||||
namespace sim {
|
||||
namespace lowfi {
|
||||
|
||||
class WpiMotorSim : public MotorSim {
|
||||
public:
|
||||
explicit WpiMotorSim(int index, MotorModel& motorModelSimulator);
|
||||
|
||||
void Update(double elapsedTime);
|
||||
double GetPosition() const override;
|
||||
double GetVelocity() const override;
|
||||
double GetAcceleration() const override;
|
||||
|
||||
private:
|
||||
MotorModel& m_motorModelSimulation;
|
||||
frc::sim::PWMSim m_pwmSimulator;
|
||||
|
||||
static constexpr double kDefaultVoltage = 12.0;
|
||||
};
|
||||
|
||||
} // namespace lowfi
|
||||
} // namespace sim
|
||||
} // namespace frc
|
||||
Reference in New Issue
Block a user