Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-dev-f303 FastPWM3
Revision 50:9d762c5d05c3, committed 2021-03-29
- Comitter:
- shaorui
- Date:
- Mon Mar 29 07:08:14 2021 +0000
- Parent:
- 48:f083ea9d1d03
- Commit message:
- suojin
Changed in this revision
--- a/Calibration/calibration.cpp Thu Jan 09 01:42:00 2020 +0000
+++ b/Calibration/calibration.cpp Mon Mar 29 07:08:14 2021 +0000
@@ -16,7 +16,8 @@
printf("\n\r Checking phase ordering\n\r");
float theta_ref = 0;
float theta_actual = 0;
- float v_d = .15f; //Put all volts on the D-Axis
+ //float v_d = .45f;
+ float v_d = .10f; //Put all volts on the D-Axis
float v_q = 0.0f;
float v_u, v_v, v_w = 0;
float dtc_u, dtc_v, dtc_w = .5f;
@@ -88,7 +89,8 @@
int raw_b[n] = {0};
float theta_ref = 0;
float theta_actual = 0;
- float v_d = .15f; // Put volts on the D-Axis
+ //float v_d = .45f;
+ float v_d = .10f; // Put volts on the D-Axis
float v_q = 0.0f;
float v_u, v_v, v_w = 0;
float dtc_u, dtc_v, dtc_w = .5f;
--- a/Config/hw_config.h Thu Jan 09 01:42:00 2020 +0000 +++ b/Config/hw_config.h Mon Mar 29 07:08:14 2021 +0000 @@ -6,6 +6,8 @@ #define PIN_W PA_8 #define ENABLE_PIN PA_11 // Enable gate drive pin #define LED PC_5 // LED Pin +#define BRAKE1 PA_4 //brake1 pin +#define BRAKE2 PA_6 //brake2 pin #define I_SCALE 0.02014160156f // Amps per A/D Count #define V_SCALE 0.00884f // Bus volts per A/D Count #define DTC_MAX 0.95f // Max phase duty cycle
--- a/Config/motor_config.h Thu Jan 09 01:42:00 2020 +0000 +++ b/Config/motor_config.h Mon Mar 29 07:08:14 2021 +0000 @@ -2,13 +2,16 @@ #define MOTOR_CONFIG_H #define R_PHASE 0.105f //Ohms +//#define R_PHASE 0.310f //Ohms 200N Joint #define L_D 0.00003f //Henries #define L_Q 0.00003f //Henries //#define KT .075f //N-m per peak phase amp, = WB*NPP*3/2 #define KT .08f #define NPP 21 //Number of pole pairs -//#define GR 1.0f -#define GR 49.0f //Gear ratio +//#define GR 1.0f +#define GR 49.0f +//#define GR 89.0f //Gear ratio +//#define GR 151.0f //Gear ratio //#define KT_OUT 0.45f //KT*GR #define KT_OUT 4.0f #define WB 0.0024f //Webers.
--- a/FlashWriter/FlashWriter.cpp Thu Jan 09 01:42:00 2020 +0000
+++ b/FlashWriter/FlashWriter.cpp Mon Mar 29 07:08:14 2021 +0000
@@ -13,7 +13,7 @@
}
void FlashWriter::open() {
- FLASH_Unlock();
+ FLASH_Unlock();//Unlocks the FLASH control register access
FLASH_ClearFlag( FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
FLASH_EraseSector(__SECTORS[__sector], VoltageRange_3);
__ready = true;
--- a/hw_setup.cpp Thu Jan 09 01:42:00 2020 +0000
+++ b/hw_setup.cpp Mon Mar 29 07:08:14 2021 +0000
@@ -13,6 +13,8 @@
GPIOC->MODER |= (1 << 10); // set pin 5 to be general purpose output for LED
gpio->enable = new DigitalOut(ENABLE_PIN);
+ gpio->brake1=new DigitalIn(BRAKE1);
+ gpio->brake2=new DigitalIn(BRAKE2);
gpio->pwm_u = new FastPWM(PIN_U);
gpio->pwm_v = new FastPWM(PIN_V);
gpio->pwm_w = new FastPWM(PIN_W);
--- a/main.cpp Thu Jan 09 01:42:00 2020 +0000
+++ b/main.cpp Mon Mar 29 07:08:14 2021 +0000
@@ -52,7 +52,8 @@
volatile int count = 0;
volatile int state = REST_MODE;
volatile int state_change;
-
+volatile int brake_state=1;
+int reg_count=0;
void onMsgReceived() {
//msgAvailable = true;
@@ -147,6 +148,10 @@
void print_encoder(void){
printf(" Mechanical Angle: %f Electrical Angle: %f Raw: %d\n\r", spi.GetMechPosition(), spi.GetElecPosition(), spi.GetRawPosition());
+ for(reg_count=0;reg_count<=263;reg_count++)
+ {
+ printf("%d %d\n\r",reg_count,__int_reg[reg_count]);
+ }
wait(.05);
}
@@ -211,15 +216,27 @@
commutate(&controller, &observer, &gpio, controller.theta_elec); // Run current loop
controller.timeout += 1;
- /*
- count++;
- if(count == 4000){
- printf("%.4f\n\r", controller.dtheta_mech);
- count = 0;
- }
- */
-
+ if(brake_state)
+ {
+ if(gpio.brake1->read()==0||gpio.brake2->read()==0)
+ {
+ printf("2\n\r");
+ controller.i_d_ref = 0;
+ controller.i_q_ref = 0;
+ controller.kp = 0;
+ controller.kd = 0;
+ controller.t_ff = 0;
+ brake_state=0;
+ state_change = 0;
+ gpio.enable->write(0);
+ gpio.led->write(0);
+ }
+ }
+ if(gpio.brake1->read()==1&&gpio.brake2->read()==1)
+ {
+ brake_state=1;
+ }
}
break;
case SETUP_MODE:
@@ -395,6 +412,11 @@
while(1) {
-
+ if(state==MOTOR_MODE)
+ {
+ printf("%.3f\n\r",controller.theta_mech );
+ wait(1);
+
+ }
}
}
--- a/structs.h Thu Jan 09 01:42:00 2020 +0000
+++ b/structs.h Mon Mar 29 07:08:14 2021 +0000
@@ -9,6 +9,8 @@
typedef struct{
DigitalOut *enable;
DigitalOut *led;
+ DigitalIn *brake1;//shaorui add for braking
+ DigitalIn *brake2;//shaorui add for braking
FastPWM *pwm_u, *pwm_v, *pwm_w;
} GPIOStruct;