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 encoderKRAI Motor_new
odometriKRAI/odometriKRAI.cpp@0:49e87dcad299, 2021-06-18 (annotated)
- Committer:
- Yolandataniaa
- Date:
- Fri Jun 18 11:04:08 2021 +0000
- Revision:
- 0:49e87dcad299
nambah buat eksternal
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Yolandataniaa | 0:49e87dcad299 | 1 | /*************************************************************************** |
| Yolandataniaa | 0:49e87dcad299 | 2 | * Title : Library untuk odometri base |
| Yolandataniaa | 0:49e87dcad299 | 3 | * Name : odometriKrai.cpp |
| Yolandataniaa | 0:49e87dcad299 | 4 | * Version : 1.0 |
| Yolandataniaa | 0:49e87dcad299 | 5 | * Author : Oktavianus Irvan Sitanggang EL 18 |
| Yolandataniaa | 0:49e87dcad299 | 6 | * Date : 17 Desember 2019 |
| Yolandataniaa | 0:49e87dcad299 | 7 | * Description: |
| Yolandataniaa | 0:49e87dcad299 | 8 | * |
| Yolandataniaa | 0:49e87dcad299 | 9 | * Library ini digunakan untuk melakukan perhitungan posisi robot |
| Yolandataniaa | 0:49e87dcad299 | 10 | * |
| Yolandataniaa | 0:49e87dcad299 | 11 | * |
| Yolandataniaa | 0:49e87dcad299 | 12 | ***************************************************************************/ |
| Yolandataniaa | 0:49e87dcad299 | 13 | |
| Yolandataniaa | 0:49e87dcad299 | 14 | /******************************* library ***********************************/ |
| Yolandataniaa | 0:49e87dcad299 | 15 | |
| Yolandataniaa | 0:49e87dcad299 | 16 | #include "odometriKRAI.h" |
| Yolandataniaa | 0:49e87dcad299 | 17 | #include "mbed.h" |
| Yolandataniaa | 0:49e87dcad299 | 18 | |
| Yolandataniaa | 0:49e87dcad299 | 19 | |
| Yolandataniaa | 0:49e87dcad299 | 20 | |
| Yolandataniaa | 0:49e87dcad299 | 21 | #ifndef PHI |
| Yolandataniaa | 0:49e87dcad299 | 22 | #define PHI 3.14159265359 |
| Yolandataniaa | 0:49e87dcad299 | 23 | #endif |
| Yolandataniaa | 0:49e87dcad299 | 24 | |
| Yolandataniaa | 0:49e87dcad299 | 25 | #ifndef D_RODA |
| Yolandataniaa | 0:49e87dcad299 | 26 | #define D_RODA 0.06 |
| Yolandataniaa | 0:49e87dcad299 | 27 | #endif |
| Yolandataniaa | 0:49e87dcad299 | 28 | /*************************** inisiasi class *******************************/ |
| Yolandataniaa | 0:49e87dcad299 | 29 | odometriKRAI::odometriKRAI(TIM_TypeDef *_TIMEncX, TIM_TypeDef *_TIMEncY, PinName SDA, PinName SCL) |
| Yolandataniaa | 0:49e87dcad299 | 30 | : encX(_TIMEncX), encY(_TIMEncY), kompass(SDA, SCL, 0xC0) { |
| Yolandataniaa | 0:49e87dcad299 | 31 | position.x = 0; // initiate all Value |
| Yolandataniaa | 0:49e87dcad299 | 32 | position.y = 0; |
| Yolandataniaa | 0:49e87dcad299 | 33 | position.teta = 0; |
| Yolandataniaa | 0:49e87dcad299 | 34 | kompass.compassResetOffsetValue(); |
| Yolandataniaa | 0:49e87dcad299 | 35 | } |
| Yolandataniaa | 0:49e87dcad299 | 36 | |
| Yolandataniaa | 0:49e87dcad299 | 37 | |
| Yolandataniaa | 0:49e87dcad299 | 38 | /*************************** definisi fungsi ******************************/ |
| Yolandataniaa | 0:49e87dcad299 | 39 | |
| Yolandataniaa | 0:49e87dcad299 | 40 | /* update position from base */ |
| Yolandataniaa | 0:49e87dcad299 | 41 | void odometriKRAI::updatePosition(void){ |
| Yolandataniaa | 0:49e87dcad299 | 42 | float xTemp = encX.getPulses(1); /* butuh 1.5us */ |
| Yolandataniaa | 0:49e87dcad299 | 43 | float yTemp = encY.getPulses(1); /* butuh 1.5us */ |
| Yolandataniaa | 0:49e87dcad299 | 44 | |
| Yolandataniaa | 0:49e87dcad299 | 45 | kompass.compassUpdateValue(); /* ??? */ |
| Yolandataniaa | 0:49e87dcad299 | 46 | position.teta = kompass.compassValue(); |
| Yolandataniaa | 0:49e87dcad299 | 47 | position.x += (xTemp*PHI*D_RODA/4000)*cos(position.teta) + (yTemp*PHI*D_RODA/4000)*-sin(position.teta); /* butuh 4.5 us */ |
| Yolandataniaa | 0:49e87dcad299 | 48 | position.y += (xTemp*PHI*D_RODA/4000)*sin(position.teta) + (yTemp*PHI*D_RODA/4000)*cos(position.teta); /* butuh 4.5 us */ |
| Yolandataniaa | 0:49e87dcad299 | 49 | |
| Yolandataniaa | 0:49e87dcad299 | 50 | } |
| Yolandataniaa | 0:49e87dcad299 | 51 | |
| Yolandataniaa | 0:49e87dcad299 | 52 | /* to reset all the position */ |
| Yolandataniaa | 0:49e87dcad299 | 53 | void odometriKRAI::resetOdom(void){ |
| Yolandataniaa | 0:49e87dcad299 | 54 | position.x = 0; // initiate all Value |
| Yolandataniaa | 0:49e87dcad299 | 55 | position.y = 0; |
| Yolandataniaa | 0:49e87dcad299 | 56 | position.teta = 0; |
| Yolandataniaa | 0:49e87dcad299 | 57 | |
| Yolandataniaa | 0:49e87dcad299 | 58 | kompass.compassResetOffsetValue(); |
| Yolandataniaa | 0:49e87dcad299 | 59 | } |
| Yolandataniaa | 0:49e87dcad299 | 60 | |
| Yolandataniaa | 0:49e87dcad299 | 61 | |
| Yolandataniaa | 0:49e87dcad299 | 62 |