単体試験用

Dependencies:   mbed

Committer:
minanao
Date:
Thu Dec 09 04:50:48 2021 +0000
Revision:
1:94062f1bb223
Parent:
0:b0c47a96f7cd
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emcu 0:b0c47a96f7cd 1 /*
emcu 0:b0c47a96f7cd 2
emcu 0:b0c47a96f7cd 3
emcu 0:b0c47a96f7cd 4 Servo Motor:
emcu 0:b0c47a96f7cd 5 MG996R - http://www.electronicoscaldas.com/datasheet/MG996R_Tower-Pro.pdf
emcu 0:b0c47a96f7cd 6
emcu 0:b0c47a96f7cd 7 RED - + Vcc from 4,5 to 7,2V
emcu 0:b0c47a96f7cd 8 BLACK - GND
emcu 0:b0c47a96f7cd 9 ORANGE - PWM
emcu 0:b0c47a96f7cd 10
emcu 0:b0c47a96f7cd 11 Duty - example: 1.9 (mS)
emcu 0:b0c47a96f7cd 12 \ /
emcu 0:b0c47a96f7cd 13 \/
emcu 0:b0c47a96f7cd 14 __
emcu 0:b0c47a96f7cd 15 __| |_____________
emcu 0:b0c47a96f7cd 16 ... 20mS......
emcu 0:b0c47a96f7cd 17
emcu 0:b0c47a96f7cd 18 For rotate to right use value 1 for Duty
emcu 0:b0c47a96f7cd 19 For rotate to left use value 5 for Duty
emcu 0:b0c47a96f7cd 20
emcu 0:b0c47a96f7cd 21 Vedere queste spiegazioni:
emcu 0:b0c47a96f7cd 22 http://www.adrirobot.it/servotester/il_servomotore.htm
emcu 0:b0c47a96f7cd 23
emcu 0:b0c47a96f7cd 24
emcu 0:b0c47a96f7cd 25
emcu 0:b0c47a96f7cd 26 NOTE:
emcu 0:b0c47a96f7cd 27
emcu 0:b0c47a96f7cd 28 For rotate to Right (DESTRA) use this command:
emcu 0:b0c47a96f7cd 29 Move(Right);
emcu 0:b0c47a96f7cd 30 For rotate to Left (SINISTRA) use this command:
emcu 0:b0c47a96f7cd 31 Move(Left);
emcu 0:b0c47a96f7cd 32
emcu 0:b0c47a96f7cd 33 You also has the possibility to send a command like below:
emcu 0:b0c47a96f7cd 34 Move(1.5):
emcu 0:b0c47a96f7cd 35
emcu 0:b0c47a96f7cd 36 */
emcu 0:b0c47a96f7cd 37
emcu 0:b0c47a96f7cd 38 #include "mbed.h"
emcu 0:b0c47a96f7cd 39
emcu 0:b0c47a96f7cd 40 DigitalOut Drive(PA_10);
emcu 0:b0c47a96f7cd 41
emcu 0:b0c47a96f7cd 42 #define PWMoff 20 // Waiting for end PWD
emcu 0:b0c47a96f7cd 43 #define Right 1 // Move to Right -> DESTRA or DX
emcu 0:b0c47a96f7cd 44 #define Left 5 // Move to LEFT <- SINISTRA or SX
emcu 0:b0c47a96f7cd 45 #define DLY 1
emcu 0:b0c47a96f7cd 46
emcu 0:b0c47a96f7cd 47 void Move(double);
emcu 0:b0c47a96f7cd 48
emcu 0:b0c47a96f7cd 49 double p=0;
emcu 0:b0c47a96f7cd 50
emcu 0:b0c47a96f7cd 51
emcu 0:b0c47a96f7cd 52 int main()
emcu 0:b0c47a96f7cd 53 {
emcu 0:b0c47a96f7cd 54 int n=0;
emcu 0:b0c47a96f7cd 55
emcu 0:b0c47a96f7cd 56 printf("By: www.emcu.eu - Ver.1.0 \n\r");
emcu 0:b0c47a96f7cd 57
emcu 0:b0c47a96f7cd 58 printf("Rotate all to -> \n\r");
emcu 0:b0c47a96f7cd 59 // Sposta tutto a DX
emcu 0:b0c47a96f7cd 60 for(n=0; n<20; n++)
emcu 0:b0c47a96f7cd 61 Move(Right);
emcu 0:b0c47a96f7cd 62
emcu 0:b0c47a96f7cd 63 wait(DLY);
emcu 0:b0c47a96f7cd 64
emcu 0:b0c47a96f7cd 65 printf("Rotate all to <- \n\r");
emcu 0:b0c47a96f7cd 66 // Sposta tutto a SX
emcu 0:b0c47a96f7cd 67 for(n=0; n<20; n++)
emcu 0:b0c47a96f7cd 68 Move(Left);
emcu 0:b0c47a96f7cd 69
emcu 0:b0c47a96f7cd 70 wait(DLY);
emcu 0:b0c47a96f7cd 71
emcu 0:b0c47a96f7cd 72 printf("Move to 10 times to ->\n\r");
emcu 0:b0c47a96f7cd 73 for(n=0; n<10; n++)
emcu 0:b0c47a96f7cd 74 Move(Right);
emcu 0:b0c47a96f7cd 75
emcu 0:b0c47a96f7cd 76 wait(DLY);
emcu 0:b0c47a96f7cd 77
emcu 0:b0c47a96f7cd 78 printf("END \n\r\n\r");
emcu 0:b0c47a96f7cd 79 }
emcu 0:b0c47a96f7cd 80
emcu 0:b0c47a96f7cd 81
emcu 0:b0c47a96f7cd 82 void Move(double ON)
emcu 0:b0c47a96f7cd 83 {
emcu 0:b0c47a96f7cd 84
emcu 0:b0c47a96f7cd 85 Drive=1;
emcu 0:b0c47a96f7cd 86 wait_ms(ON);
emcu 0:b0c47a96f7cd 87 Drive=0;
emcu 0:b0c47a96f7cd 88 wait_ms(20);
emcu 0:b0c47a96f7cd 89
emcu 0:b0c47a96f7cd 90 }
emcu 0:b0c47a96f7cd 91
emcu 0:b0c47a96f7cd 92
emcu 0:b0c47a96f7cd 93
emcu 0:b0c47a96f7cd 94 /*
emcu 0:b0c47a96f7cd 95
emcu 0:b0c47a96f7cd 96 // Sposta tutto a DX - Move all to RIGHT
emcu 0:b0c47a96f7cd 97 for(n=0; n<200; n++)
emcu 0:b0c47a96f7cd 98 Move(Right);
emcu 0:b0c47a96f7cd 99
emcu 0:b0c47a96f7cd 100 wait(DLY);
emcu 0:b0c47a96f7cd 101
emcu 0:b0c47a96f7cd 102 // Sposta tutto a SX - Move all to LEFT
emcu 0:b0c47a96f7cd 103 for(n=0; n<200; n++)
emcu 0:b0c47a96f7cd 104 Move(Left);
emcu 0:b0c47a96f7cd 105
emcu 0:b0c47a96f7cd 106 wait(DLY);
emcu 0:b0c47a96f7cd 107
emcu 0:b0c47a96f7cd 108 */
emcu 0:b0c47a96f7cd 109
emcu 0:b0c47a96f7cd 110 /*
emcu 0:b0c47a96f7cd 111 p=0.4;
emcu 0:b0c47a96f7cd 112 myservo = p;
emcu 0:b0c47a96f7cd 113 printf("P = %.2f \n\r", p);
emcu 0:b0c47a96f7cd 114 wait(0.2);
emcu 0:b0c47a96f7cd 115 */