-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce9466b
commit 3d4637b
Showing
6 changed files
with
173 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Created by 钱晨 on 3/16/22. | ||
// This file contains some feature enabling masks. | ||
// | ||
|
||
#ifndef META_INFANTRY_HARDWARE_CONF_H | ||
#define META_INFANTRY_HARDWARE_CONF_H | ||
|
||
#if !defined(ENABLE_VISION) || defined(__DOXYGEN__) | ||
#define ENABLE_VISION FALSE | ||
#endif | ||
|
||
#if !defined(ENABLE_REFEREE) || defined(__DOXYGEN__) | ||
#define ENABLE_REFEREE TRUE | ||
#endif | ||
|
||
#if !defined(ENABLE_SUBPITCH) || defined(__DOXYGEN__) | ||
#define ENABLE_SUBPITCH FALSE | ||
#endif | ||
|
||
#if !defined(ENABLE_CAPACITOR) || defined(__DOXYGEN__) | ||
#define ENABLE_CAPACITOR TRUE | ||
#endif | ||
|
||
#if !defined(ENABLE_USB_SHELL) || defined(__DOXYGEN__) | ||
#define ENABLE_USB_SHELL TRUE | ||
#endif | ||
|
||
#endif //META_INFANTRY_HARDWARE_CONF_H |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Created by Wu Feiyang on 2023/7/11. | ||
// | ||
|
||
/** | ||
* @brief This is example code to use the Rudder Interface. | ||
*/ | ||
|
||
#include "hal.h" | ||
#include "ch.hpp" | ||
#include "rudder_interface.h" | ||
|
||
|
||
int main(){ | ||
halInit(); | ||
chibios_rt::System::init(); | ||
// nullptr means using the default configuration, which is advised | ||
Rudder rudder1(&PWMD4,nullptr,0,Rudder::MG995); | ||
|
||
rudder1.start(); | ||
rudder1.set_rudder_angle(90); | ||
while(1){ | ||
chThdSleepMilliseconds(2000); | ||
rudder1.set_rudder_angle(0); | ||
chThdSleepMilliseconds(2000); | ||
rudder1.set_rudder_angle(90); | ||
chThdSleepMilliseconds(2000); | ||
rudder1.set_rudder_angle(180); | ||
chThdSleepMilliseconds(2000); | ||
rudder1.set_rudder_angle(90); | ||
|
||
} | ||
} | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Created by Wu Feiyang on 2023/7/11. | ||
// | ||
#include "rudder_interface.h" | ||
|
||
|
||
/** | ||
* @brief Constructor of the rudder | ||
* | ||
* @param[in] driver pointer to a @p PWMDriver object | ||
* @param[in] config pointer to a @p PWMConfig object | ||
* @param[in] channel PWM channel of the rudder. Note that 0 stand for channel 1 and vice versa. | ||
* @param[in] rudderType type of the rudder | ||
* | ||
* @api | ||
*/ | ||
Rudder::Rudder(PWMDriver *driver, PWMConfig *config, pwmchannel_t channel,rudderType_t rudderType) { | ||
if(config == nullptr){ | ||
config_ = &pwm_default_config; | ||
}else{ | ||
config_ = config; | ||
} | ||
driver_ = driver; | ||
channel_ = channel; | ||
rudderType_ = rudderType; | ||
} | ||
|
||
Rudder::~Rudder() { | ||
pwmStop(driver_); | ||
} | ||
void Rudder::start() { | ||
pwmStart(driver_,config_); | ||
} | ||
|
||
void Rudder::set_rudder_angle(int angle) { | ||
int percentage = 0; | ||
if(rudderType_ == MG995){ | ||
/** | ||
* MG995: 0.5ms - 0 degrees | ||
* 1.0ms - 45 degrees | ||
* 1.5ms - 90 degrees | ||
* 2.5ms - 180 degrees | ||
*/ | ||
// 180 - 2000 | ||
percentage = angle * 2000 / 180 + 500; | ||
} | ||
pwmEnableChannel(driver_,channel_,PWM_PERCENTAGE_TO_WIDTH(driver_, percentage)); | ||
} | ||
void Rudder::stop() { | ||
pwmDisableChannel(driver_,channel_); | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// Created by Wu Feiyang on 2023/7/11. | ||
// | ||
|
||
#ifndef META_RUDDER_INTERFACE_H | ||
#define META_RUDDER_INTERFACE_H | ||
#include "ch.hpp" | ||
#include "hal.h" | ||
#include "hal_pwm.h" | ||
|
||
class Rudder{ | ||
public: | ||
typedef enum{ | ||
MG995, | ||
RUDDER_TYPE_CNT | ||
}rudderType_t; | ||
|
||
Rudder(PWMDriver* driver,PWMConfig* config,pwmchannel_t channel, rudderType_t rudderType); | ||
~Rudder(); | ||
void start(); | ||
void stop(); | ||
void set_rudder_angle(int angle); | ||
|
||
private: | ||
PWMConfig pwm_default_config = { | ||
10000, // frequency 10000Hz | ||
100, // 10 ms, 1/10000s * 100 = 0.01s = 10ms | ||
nullptr, | ||
{ | ||
{PWM_OUTPUT_ACTIVE_HIGH, nullptr}, // it's all CH1 for current support boards | ||
{PWM_COMPLEMENTARY_OUTPUT_DISABLED, nullptr}, | ||
{PWM_COMPLEMENTARY_OUTPUT_DISABLED, nullptr}, | ||
{PWM_COMPLEMENTARY_OUTPUT_DISABLED, nullptr} | ||
}, | ||
0, | ||
0 | ||
}; | ||
PWMDriver * driver_; | ||
PWMConfig * config_; | ||
pwmchannel_t channel_; | ||
rudderType_t rudderType_; | ||
}; | ||
|
||
#endif //META_RUDDER_INTERFACE_H |