-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from rogy-AquaLab/rename_schneider2
scheider→machine
- Loading branch information
Showing
3 changed files
with
136 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
#ifndef OMNIBOAT_R_INCLUDED | ||
#define OMNIBOAT_R_INCLUDED | ||
|
||
#include <array> | ||
|
||
#include "mbed.h" | ||
|
||
#include "device/input.hpp" | ||
#include "device/output.hpp" | ||
#include "packet/input.hpp" | ||
#include "packet/output.hpp" | ||
#include "service/service.hpp" | ||
|
||
namespace omniboat { | ||
|
||
/** | ||
* @brief モータへの出力を計算するクラス | ||
*/ | ||
class Schneider { | ||
public: | ||
Schneider(); | ||
Schneider(const Schneider&) = delete; | ||
Schneider(Schneider&&) = default; | ||
auto operator=(const Schneider&) -> Schneider& = delete; | ||
auto operator=(Schneider&&) -> Schneider& = default; | ||
~Schneider(); | ||
void debug(); | ||
|
||
/** | ||
* @brief 1ステップ毎にモータへの入力値を計算する関数 | ||
*/ | ||
void one_step(); | ||
void init(); | ||
|
||
// TODO: | ||
// これ実装されてないのでコメントアウト | ||
// commit `f50fb9b` 参照 | ||
// /** | ||
// * @brief 機体を停止させる関数 | ||
// */ | ||
// void flip_shneider(); | ||
|
||
private: | ||
// flip_shneider と同様 | ||
// /** | ||
// * @brief ボタンが押されたときに機体を停止させる関数(割り込み処理) | ||
// */ | ||
// void ticker_flip(); | ||
|
||
device::InputModules input_modules; | ||
device::OutputModules output_modules; | ||
service::Service service; | ||
}; | ||
|
||
} // namespace omniboat | ||
|
||
#endif | ||
#ifndef OMNIBOAT_R_INCLUDED | ||
#define OMNIBOAT_R_INCLUDED | ||
|
||
#include <array> | ||
|
||
#include "mbed.h" | ||
|
||
#include "device/input.hpp" | ||
#include "device/output.hpp" | ||
#include "packet/input.hpp" | ||
#include "packet/output.hpp" | ||
#include "service/service.hpp" | ||
|
||
namespace omniboat { | ||
|
||
/** | ||
* @brief モータへの出力を計算するクラス | ||
*/ | ||
class Machine { | ||
public: | ||
Machine(); | ||
Machine(const Machine&) = delete; | ||
Machine(Machine&&) = default; | ||
auto operator=(const Machine&) -> Machine& = delete; | ||
auto operator=(Machine&&) -> Machine& = default; | ||
~Machine(); | ||
void debug(); | ||
|
||
/** | ||
* @brief 1ステップ毎にモータへの入力値を計算する関数 | ||
*/ | ||
void one_step(); | ||
void init(); | ||
|
||
// TODO: | ||
// これ実装されてないのでコメントアウト | ||
// commit `f50fb9b` 参照 | ||
// /** | ||
// * @brief 機体を停止させる関数 | ||
// */ | ||
// void flip_shneider(); | ||
|
||
private: | ||
// flip_shneider と同様 | ||
// /** | ||
// * @brief ボタンが押されたときに機体を停止させる関数(割り込み処理) | ||
// */ | ||
// void ticker_flip(); | ||
|
||
device::InputModules input_modules; | ||
device::OutputModules output_modules; | ||
service::Service service; | ||
}; | ||
|
||
} // namespace omniboat | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
#include <algorithm> | ||
#include <chrono> | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <thread> | ||
#include <utility> | ||
|
||
#include "rtos.h" | ||
|
||
#include "schneider_model.hpp" | ||
#include "trace.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace omniboat { | ||
|
||
using trace::LedId; | ||
|
||
/** | ||
* @brief z軸周りの慣性モーメント | ||
* @note もっと正確な値の方がいいかも | ||
*/ | ||
constexpr float inertia_z = 1; | ||
/** | ||
* @brief ステップ幅 | ||
*/ | ||
constexpr float step_width_a = 0.1; | ||
|
||
Schneider::Schneider() : | ||
input_modules({A4, A5}, A6, {D4, D5}), output_modules({PB_4, PA_11}, {PA_9, PA_10}), service() { | ||
trace::toggle(LedId::First); | ||
trace::toggle(LedId::Second); | ||
trace::toggle(LedId::Third); | ||
printf("start up\n"); | ||
this->output_modules.init(); | ||
} | ||
|
||
Schneider::~Schneider() { | ||
trace::toggle(LedId::First); | ||
} | ||
|
||
void Schneider::init() { | ||
this->service.init(); | ||
const bool whoami = this->input_modules.mpu_whoami(); | ||
if (whoami) { | ||
printf("WHOAMI succeeded\n"); | ||
} else { | ||
printf("WHOAMI failed\n"); | ||
} | ||
} | ||
|
||
inline auto map_joy(const std::pair<float, float>& joy) -> std::array<float, 3> { | ||
// ジョイスティックの中心値 | ||
constexpr float joy_center = 0.5F; | ||
// [2]はrot | ||
return {(joy.first - joy_center) * 2, (joy.second - joy_center) * 2, 0}; | ||
} | ||
|
||
void Schneider::one_step() { | ||
const packet::InputValues input = this->input_modules.read(); | ||
const packet::OutputValues output = this->service.call(input); | ||
this->output_modules.write(output); | ||
trace::toggle(LedId::Third); | ||
} | ||
|
||
void Schneider::debug() { | ||
// printf("ave=%f\n",ave_[0]/ave_[1]); | ||
// printf("motor=%f,%f\n",q[0],q[1]); | ||
// printf("servo=%f,%f\n",q[2],q[3]); | ||
// printf("volume=%f\n",volume.read()); | ||
// printf("gyro[2]=%f\n",gyro[2]); | ||
// printf("\n"); | ||
} | ||
|
||
} // namespace omniboat | ||
#include <algorithm> | ||
#include <chrono> | ||
#include <cmath> | ||
#include <cstdio> | ||
#include <thread> | ||
#include <utility> | ||
|
||
#include "rtos.h" | ||
|
||
#include "machine.hpp" | ||
#include "trace.hpp" | ||
#include "utils.hpp" | ||
|
||
namespace omniboat { | ||
|
||
using trace::LedId; | ||
|
||
/** | ||
* @brief z軸周りの慣性モーメント | ||
* @note もっと正確な値の方がいいかも | ||
*/ | ||
constexpr float inertia_z = 1; | ||
/** | ||
* @brief ステップ幅 | ||
*/ | ||
constexpr float step_width_a = 0.1; | ||
|
||
Machine::Machine() : | ||
input_modules({A4, A5}, A6, {D4, D5}), output_modules({PB_4, PA_11}, {PA_9, PA_10}), service() { | ||
trace::toggle(LedId::First); | ||
trace::toggle(LedId::Second); | ||
trace::toggle(LedId::Third); | ||
printf("start up\n"); | ||
this->output_modules.init(); | ||
} | ||
|
||
Machine::~Machine() { | ||
trace::toggle(LedId::First); | ||
} | ||
|
||
void Machine::init() { | ||
this->service.init(); | ||
const bool whoami = this->input_modules.mpu_whoami(); | ||
if (whoami) { | ||
printf("WHOAMI succeeded\n"); | ||
} else { | ||
printf("WHOAMI failed\n"); | ||
} | ||
} | ||
|
||
inline auto map_joy(const std::pair<float, float>& joy) -> std::array<float, 3> { | ||
// ジョイスティックの中心値 | ||
constexpr float joy_center = 0.5F; | ||
// [2]はrot | ||
return {(joy.first - joy_center) * 2, (joy.second - joy_center) * 2, 0}; | ||
} | ||
|
||
void Machine::one_step() { | ||
const packet::InputValues input = this->input_modules.read(); | ||
const packet::OutputValues output = this->service.call(input); | ||
this->output_modules.write(output); | ||
trace::toggle(LedId::Third); | ||
} | ||
|
||
void Machine::debug() { | ||
// printf("ave=%f\n",ave_[0]/ave_[1]); | ||
// printf("motor=%f,%f\n",q[0],q[1]); | ||
// printf("servo=%f,%f\n",q[2],q[3]); | ||
// printf("volume=%f\n",volume.read()); | ||
// printf("gyro[2]=%f\n",gyro[2]); | ||
// printf("\n"); | ||
} | ||
|
||
} // namespace omniboat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
#include "schneider_model.hpp" | ||
#include "machine.hpp" | ||
#include "trace.hpp" | ||
|
||
auto main() -> int { | ||
trace::init(); | ||
omniboat::Schneider schneider; | ||
schneider.init(); | ||
schneider.debug(); | ||
omniboat::Machine machine; | ||
machine.init(); | ||
machine.debug(); | ||
while (true) { | ||
trace::toggle(trace::LedId::First); | ||
schneider.one_step(); | ||
machine.one_step(); | ||
// wait(1); | ||
} | ||
} |