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.
ikarashiMDC.h@2:75153205d6e8, 2017-08-22 (annotated)
- Committer:
- WAT34
- Date:
- Tue Aug 22 01:44:17 2017 +0000
- Revision:
- 2:75153205d6e8
- Parent:
- 1:5e8014a1adbd
- Child:
- 3:615ccca78f67
documented;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| WAT34 | 0:314f2bed3958 | 1 | #ifndef IKARASHIMDC_H |
| WAT34 | 0:314f2bed3958 | 2 | #define IKARASHIMDC_H |
| WAT34 | 0:314f2bed3958 | 3 | |
| WAT34 | 0:314f2bed3958 | 4 | #include "mbed.h" |
| WAT34 | 0:314f2bed3958 | 5 | |
| WAT34 | 2:75153205d6e8 | 6 | #define LAP 0 |
| WAT34 | 2:75153205d6e8 | 7 | #define SM 1 |
| WAT34 | 2:75153205d6e8 | 8 | /** Ikarashi MDC class |
| WAT34 | 2:75153205d6e8 | 9 | * MDC libraly |
| WAT34 | 2:75153205d6e8 | 10 | *Example : |
| WAT34 | 2:75153205d6e8 | 11 | *@code |
| WAT34 | 2:75153205d6e8 | 12 | *#include "mbed.h" |
| WAT34 | 2:75153205d6e8 | 13 | *#include "ikarashiMDC.h" |
| WAT34 | 2:75153205d6e8 | 14 | *Serial serial(PC_10,PC_11); |
| WAT34 | 2:75153205d6e8 | 15 | *DigitalOut serialcontrol(D2); |
| WAT34 | 2:75153205d6e8 | 16 | * |
| WAT34 | 2:75153205d6e8 | 17 | *ikarashiMDC ikarashi[]{ |
| WAT34 | 2:75153205d6e8 | 18 | * ikarashiMDC(&serialcontrol,2,2,SM,&serial), |
| WAT34 | 2:75153205d6e8 | 19 | * ikarashiMDC(&serialcontrol,2,3,LAP,&serial), |
| WAT34 | 2:75153205d6e8 | 20 | *}; |
| WAT34 | 2:75153205d6e8 | 21 | *PwmOut pwm(LED1); |
| WAT34 | 2:75153205d6e8 | 22 | * |
| WAT34 | 2:75153205d6e8 | 23 | *int main() { |
| WAT34 | 2:75153205d6e8 | 24 | * serial.baud(115200); |
| WAT34 | 2:75153205d6e8 | 25 | * float i = -1; |
| WAT34 | 2:75153205d6e8 | 26 | * while(1) { |
| WAT34 | 2:75153205d6e8 | 27 | * ikarashi[0].setSpeed(i); |
| WAT34 | 2:75153205d6e8 | 28 | * ikarashi[1].setSpeed(i); |
| WAT34 | 2:75153205d6e8 | 29 | * i += 0.01; |
| WAT34 | 2:75153205d6e8 | 30 | S* pwm = fabs(i); |
| WAT34 | 2:75153205d6e8 | 31 | * wait_ms(20); |
| WAT34 | 2:75153205d6e8 | 32 | * if(i >= 1) i = -1; |
| WAT34 | 2:75153205d6e8 | 33 | * } |
| WAT34 | 2:75153205d6e8 | 34 | *} |
| WAT34 | 2:75153205d6e8 | 35 | *@endcode |
| WAT34 | 2:75153205d6e8 | 36 | **/ |
| WAT34 | 1:5e8014a1adbd | 37 | class ikarashiMDC |
| WAT34 | 2:75153205d6e8 | 38 | { |
| WAT34 | 0:314f2bed3958 | 39 | public: |
| WAT34 | 2:75153205d6e8 | 40 | /** Create ikarashiMDC inctance |
| WAT34 | 2:75153205d6e8 | 41 | * @param address of cs pin for rs485 |
| WAT34 | 2:75153205d6e8 | 42 | * @param addr for MDC |
| WAT34 | 2:75153205d6e8 | 43 | * @param ch for motor |
| WAT34 | 2:75153205d6e8 | 44 | * @param mdc mode (LAP or SM) |
| WAT34 | 2:75153205d6e8 | 45 | * @param address of serial object |
| WAT34 | 2:75153205d6e8 | 46 | **/ |
| WAT34 | 2:75153205d6e8 | 47 | ikarashiMDC(DigitalOut* serialcontrol,uint8_t taddr,uint8_t tmotorNum,bool tmode,Serial *tserial); |
| WAT34 | 2:75153205d6e8 | 48 | |
| WAT34 | 2:75153205d6e8 | 49 | /** drive motor |
| WAT34 | 2:75153205d6e8 | 50 | * @param speed of motor -1 to 1 |
| WAT34 | 2:75153205d6e8 | 51 | **/ |
| WAT34 | 2:75153205d6e8 | 52 | int setSpeed(const double& speed); |
| WAT34 | 2:75153205d6e8 | 53 | |
| WAT34 | 0:314f2bed3958 | 54 | protected: |
| WAT34 | 0:314f2bed3958 | 55 | uint8_t addr; |
| WAT34 | 0:314f2bed3958 | 56 | uint8_t motorNum; |
| WAT34 | 2:75153205d6e8 | 57 | bool mode; |
| WAT34 | 0:314f2bed3958 | 58 | Serial* serial; |
| WAT34 | 2:75153205d6e8 | 59 | DigitalOut *serialControl; |
| WAT34 | 0:314f2bed3958 | 60 | |
| WAT34 | 0:314f2bed3958 | 61 | }; |
| WAT34 | 2:75153205d6e8 | 62 | void estop(Serial *serial); |
| WAT34 | 1:5e8014a1adbd | 63 | |
| WAT34 | 0:314f2bed3958 | 64 | #endif |