Skip to content

Commit

Permalink
rudder modificaion
Browse files Browse the repository at this point in the history
  • Loading branch information
Raventhatfly committed Aug 2, 2023
1 parent 165cee6 commit 75a8b8a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
14 changes: 7 additions & 7 deletions dev/board_pin/rm_board_2018_a/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
#define GPIOD_PIN10 10U
#define GPIOD_PIN11 11U
#define RUDDER 12U
#define GPIOD_LED3 13U
#define RUDDER2 13U
#define GPIOD_LED5 14U
#define GPIOD_LED6 15U

Expand Down Expand Up @@ -676,7 +676,7 @@
PIN_MODE_INPUT(GPIOD_PIN10) | \
PIN_MODE_INPUT(GPIOD_PIN11) | \
PIN_MODE_ALTERNATE(RUDDER) | \
PIN_MODE_OUTPUT(GPIOD_LED3) | \
PIN_MODE_ALTERNATE(RUDDER2) | \
PIN_MODE_OUTPUT(GPIOD_LED5) | \
PIN_MODE_OUTPUT(GPIOD_LED6))
#define VAL_GPIOD_OTYPER (PIN_OTYPE_PUSHPULL(GPIOD_CAN1_RX) | \
Expand All @@ -692,7 +692,7 @@
PIN_OTYPE_PUSHPULL(GPIOD_PIN10) | \
PIN_OTYPE_PUSHPULL(GPIOD_PIN11) | \
PIN_OTYPE_PUSHPULL(RUDDER) | \
PIN_OTYPE_PUSHPULL(GPIOD_LED3) | \
PIN_OTYPE_PUSHPULL(RUDDER2) | \
PIN_OTYPE_PUSHPULL(GPIOD_LED5) | \
PIN_OTYPE_PUSHPULL(GPIOD_LED6))
#define VAL_GPIOD_OSPEEDR (PIN_OSPEED_HIGH(GPIOD_CAN1_RX) | \
Expand All @@ -708,7 +708,7 @@
PIN_OSPEED_HIGH(GPIOD_PIN10) | \
PIN_OSPEED_HIGH(GPIOD_PIN11) | \
PIN_OSPEED_HIGH(RUDDER) | \
PIN_OSPEED_HIGH(GPIOD_LED3) | \
PIN_OSPEED_HIGH(RUDDER2) | \
PIN_OSPEED_HIGH(GPIOD_LED5) | \
PIN_OSPEED_HIGH(GPIOD_LED6))
#define VAL_GPIOD_PUPDR (PIN_PUPDR_PULLUP(GPIOD_CAN1_RX) | \
Expand All @@ -724,7 +724,7 @@
PIN_PUPDR_PULLUP(GPIOD_PIN10) | \
PIN_PUPDR_PULLUP(GPIOD_PIN11) | \
PIN_PUPDR_FLOATING(RUDDER) | \
PIN_PUPDR_FLOATING(GPIOD_LED3) | \
PIN_PUPDR_FLOATING(RUDDER2) | \
PIN_PUPDR_FLOATING(GPIOD_LED5) | \
PIN_PUPDR_FLOATING(GPIOD_LED6))
#define VAL_GPIOD_ODR (PIN_ODR_HIGH(GPIOD_CAN1_RX) | \
Expand All @@ -740,7 +740,7 @@
PIN_ODR_HIGH(GPIOD_PIN10) | \
PIN_ODR_HIGH(GPIOD_PIN11) | \
PIN_ODR_LOW(RUDDER) | \
PIN_ODR_LOW(GPIOD_LED3) | \
PIN_ODR_LOW(RUDDER2) | \
PIN_ODR_LOW(GPIOD_LED5) | \
PIN_ODR_LOW(GPIOD_LED6))
#define VAL_GPIOD_AFRL (PIN_AFIO_AF(GPIOD_CAN1_RX, 9U) | \
Expand All @@ -756,7 +756,7 @@
PIN_AFIO_AF(GPIOD_PIN10, 0U) | \
PIN_AFIO_AF(GPIOD_PIN11, 0U) | \
PIN_AFIO_AF(RUDDER, 2U) | \
PIN_AFIO_AF(GPIOD_LED3, 0U) | \
PIN_AFIO_AF(RUDDER2, 2U) | \
PIN_AFIO_AF(GPIOD_LED5, 0U) | \
PIN_AFIO_AF(GPIOD_LED6, 0U))

Expand Down
27 changes: 18 additions & 9 deletions dev/interface/rudder/rudder_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@


/**
* @brief Constructor of the rudder. TO learn how to use this interface, please refer to the unit
* test.
* @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] 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;
if(config == nullptr && rudderType == MG995){
config_ = &mg995_pwm_default_config;
}else if(config == nullptr && rudderType == AFD30T60MG){
config_ = &afd30t60mg_default_config;
}
driver_ = driver;
channel_ = channel;
Expand All @@ -30,6 +29,7 @@ Rudder::~Rudder() {
pwmStop(driver_);
}
void Rudder::start() {
config_->channels[channel_].mode = PWM_OUTPUT_ACTIVE_HIGH;
pwmStart(driver_,config_);
}

Expand All @@ -44,11 +44,20 @@ void Rudder::set_rudder_angle(int angle) {
*/
// 180 - 2000
percentage = angle * 2000 / 180 + 500;
}else if(rudderType_ == AFD30T60MG){
/**
*
*/
// 120 - 4000
angle = angle * 120 / 150; // I don't know what is wrong, but the angle needs remapping.
percentage = angle * 4000 / 120 + 3000;
}
pwmEnableChannel(driver_,channel_,PWM_PERCENTAGE_TO_WIDTH(driver_, percentage));
}
void Rudder::stop() {
pwmDisableChannel(driver_,channel_);
pwmStop(driver_);
config_->channels[channel_].mode = PWM_COMPLEMENTARY_OUTPUT_DISABLED;
}


29 changes: 23 additions & 6 deletions dev/interface/rudder/rudder_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Created by Wu Feiyang on 2023/7/11.
//

#ifndef META_RUDDER_INTERFACE_H
#define META_RUDDER_INTERFACE_H
#ifndef EXPLORER_RUDDER_INTERFACE_H
#define EXPLORER_RUDDER_INTERFACE_H
#include "ch.hpp"
#include "hal.h"
#include "hal_pwm.h"
Expand All @@ -12,6 +12,7 @@ class Rudder{
public:
typedef enum{
MG995,
AFD30T60MG,
RUDDER_TYPE_CNT
}rudderType_t;

Expand All @@ -22,23 +23,39 @@ class Rudder{
void set_rudder_angle(int angle);

private:
PWMConfig pwm_default_config = {
PWMConfig mg995_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}, // 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
0,
};
PWMConfig afd30t60mg_default_config = {
10000, // frequency 1000000Hz,1us
30, // 3ms
nullptr,
{
{PWM_COMPLEMENTARY_OUTPUT_DISABLED, 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
#endif //EXPLORER_RUDDER_INTERFACE_H

0 comments on commit 75a8b8a

Please sign in to comment.