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
Revision 1:1e5da28e18ba, committed 2021-11-16
- Comitter:
- duncan_120
- Date:
- Tue Nov 16 06:34:39 2021 +0000
- Parent:
- 0:56821d19bd29
- Commit message:
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Nov 10 11:53:49 2021 +0000
+++ b/main.cpp Tue Nov 16 06:34:39 2021 +0000
@@ -16,7 +16,7 @@
#define pi 3.14159f //(is defined for) changing unit from rpm to rad/s
/////////////////////////////////////////////////////// you need to modify first
-#define VELOCITY_CMD -12.0f // unit:voltage
+#define VELOCITY_CMD 12.0f // unit:voltage
///////////////////////////////////////////////////////
#define INPUT_VOLTAGE 12.0f
#define PWM_FREQUENCY 1.0f // (unit : kHz) you may need to change. Recommand don't exceed 100.0 (100 kHz)
@@ -46,6 +46,7 @@
float dutycycle = PWM_STOP;
float you_need_to_do = 0.5;
short preEncoderPositionA = 0;
+int flag = 0;
void step_command();
void position_control();
@@ -113,14 +114,16 @@
if(button_state == true){
ReadVelocity();
command = VELOCITY_CMD;
-// pc.printf("%.3f, %.3f\r\n",command, velocityA);
+ pc.printf("%.3f, %.3f\r\n",command, velocityA);
motor_drive(command,0);
- }else{
+ }
+ else{
+ ReadVelocity();
dutycycle = PWM_STOP;
TIM1->CCR1 = CCR_value(dutycycle);
TIM1->CCR2 = CCR_value(dutycycle);
-
-// pc.printf("%.3f, %.3f\r\n",command, velocityA);
+ pc.printf("1.8,%.3f\r\n",velocityA);
+
}
#endif
@@ -136,27 +139,31 @@
short pEncoderPositionA;
EncoderPositionA = TIM2->CNT ;
- EncoderPositionB = TIM3->CNT ;
+ EncoderPositionB = TIM3->CNT ;
+
+
// if you want count to zero you can do it
// TIM2->CNT = 0;
// TIM3->CNT = 0;
/////////////////////////////////////////////////////// maybe you need to do something here
- pEncoderPositionA = EncoderPositionA - preEncoderPositionA;
+
+ pEncoderPositionA = EncoderPositionA - preEncoderPositionA;
+
//pc.printf("EPA = %d\r, preEPA = %d\r, pEA = %d\r, V = ", EncoderPositionA, preEncoderPositionA, pEncoderPositionA);
if(pEncoderPositionA < 0){
pEncoderPositionA = -pEncoderPositionA;
}
- you_need_to_do = dt*60;
+ //you_need_to_do = dt*64;
preEncoderPositionA = EncoderPositionA;
///////////////////////////////////////////////////////
- velocityA = pEncoderPositionA/you_need_to_do;
+ velocityA = pEncoderPositionA/(dt*64/60);
// please refer to PPT. (then you will find out you may need to add some variables)
velocityB = EncoderPositionB/you_need_to_do;
- pc.printf("%.4f\r\n",velocityA);
+ //pc.printf("%.4f\r\n",velocityA);
}