nambah buat eksternal

Dependencies:   mbed encoderKRAI Motor_new

Committer:
Yolandataniaa
Date:
Mon Jun 21 07:48:27 2021 +0000
Revision:
1:bbe0769f00e9
Parent:
0:49e87dcad299
revisi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Yolandataniaa 0:49e87dcad299 1 /*
Yolandataniaa 0:49e87dcad299 2 * adopted from
Yolandataniaa 0:49e87dcad299 3 * CMPS03 by: Aarom Berk
Yolandataniaa 0:49e87dcad299 4 *
Yolandataniaa 0:49e87dcad299 5 * Bismillahirahmanirrahim
Yolandataniaa 0:49e87dcad299 6 */
Yolandataniaa 0:49e87dcad299 7
Yolandataniaa 0:49e87dcad299 8 #ifndef CMPS12_KRAI_H
Yolandataniaa 0:49e87dcad299 9 #define CMPS12_KRAI_H
Yolandataniaa 0:49e87dcad299 10
Yolandataniaa 0:49e87dcad299 11 /**
Yolandataniaa 0:49e87dcad299 12 * Includes
Yolandataniaa 0:49e87dcad299 13 */
Yolandataniaa 0:49e87dcad299 14 #include "mbed.h"
Yolandataniaa 0:49e87dcad299 15
Yolandataniaa 0:49e87dcad299 16 #define CMPS_DEFAULT_I2C_ADDRESS 0xC0
Yolandataniaa 0:49e87dcad299 17 //set register kompas
Yolandataniaa 0:49e87dcad299 18 #define SOFTWARE_REVISION_REG 0x0
Yolandataniaa 0:49e87dcad299 19 #define COMPASS_BEARING_WORD_REG 0x2
Yolandataniaa 0:49e87dcad299 20 #define COMPASS_PITCH_WORD_REG 0x4
Yolandataniaa 0:49e87dcad299 21 #define COMPASS_ROLL_WORD_REG 0x5
Yolandataniaa 0:49e87dcad299 22
Yolandataniaa 0:49e87dcad299 23 /** Interface to read compass using I2C communciation
Yolandataniaa 0:49e87dcad299 24 * compass type : CMPS 12
Yolandataniaa 0:49e87dcad299 25 */
Yolandataniaa 0:49e87dcad299 26 class CMPS12_KRAI {
Yolandataniaa 0:49e87dcad299 27
Yolandataniaa 0:49e87dcad299 28 I2C* i2c;
Yolandataniaa 0:49e87dcad299 29 int i2cAddress;
Yolandataniaa 0:49e87dcad299 30
Yolandataniaa 0:49e87dcad299 31 public:
Yolandataniaa 0:49e87dcad299 32
Yolandataniaa 0:49e87dcad299 33 /** Create CMPS12 inteface
Yolandataniaa 0:49e87dcad299 34 *
Yolandataniaa 0:49e87dcad299 35 *
Yolandataniaa 0:49e87dcad299 36 * @param sda mbed pin to use for I2C SDA
Yolandataniaa 0:49e87dcad299 37 * @param scl mbed pin to use for I2C SCL
Yolandataniaa 0:49e87dcad299 38 * @param address I2C address of this device.
Yolandataniaa 0:49e87dcad299 39 */
Yolandataniaa 0:49e87dcad299 40 CMPS12_KRAI(PinName sda, PinName scl, int address);
Yolandataniaa 0:49e87dcad299 41
Yolandataniaa 0:49e87dcad299 42 /** Membaca revisi dari kompas
Yolandataniaa 0:49e87dcad299 43 *
Yolandataniaa 0:49e87dcad299 44 */
Yolandataniaa 0:49e87dcad299 45 char readSoftwareRevision(void);
Yolandataniaa 0:49e87dcad299 46
Yolandataniaa 0:49e87dcad299 47 /** Membaca nilai dari kompas
Yolandataniaa 0:49e87dcad299 48 *
Yolandataniaa 0:49e87dcad299 49 * Range nilai 0 - 3599
Yolandataniaa 0:49e87dcad299 50 */
Yolandataniaa 0:49e87dcad299 51 int getAngle(void);
Yolandataniaa 0:49e87dcad299 52
Yolandataniaa 0:49e87dcad299 53 /** Membaca nilai sudut pitch dari kompas
Yolandataniaa 0:49e87dcad299 54 *
Yolandataniaa 0:49e87dcad299 55 * Range nilai 0 - 3599
Yolandataniaa 0:49e87dcad299 56 */
Yolandataniaa 0:49e87dcad299 57 int getPitch(void);
Yolandataniaa 0:49e87dcad299 58
Yolandataniaa 0:49e87dcad299 59 /** Membaca nilai sudut roll dari kompas
Yolandataniaa 0:49e87dcad299 60 *
Yolandataniaa 0:49e87dcad299 61 * Range nilai (+/-90)
Yolandataniaa 0:49e87dcad299 62 */
Yolandataniaa 0:49e87dcad299 63 int getRoll(void);
Yolandataniaa 0:49e87dcad299 64
Yolandataniaa 0:49e87dcad299 65 /** Kalibrasi kompas
Yolandataniaa 0:49e87dcad299 66 *
Yolandataniaa 0:49e87dcad299 67 */
Yolandataniaa 0:49e87dcad299 68 void calibrate(void);
Yolandataniaa 0:49e87dcad299 69
Yolandataniaa 0:49e87dcad299 70 /** Stop calibrate
Yolandataniaa 0:49e87dcad299 71 *
Yolandataniaa 0:49e87dcad299 72 */
Yolandataniaa 0:49e87dcad299 73 void stopCalibrate(void);
Yolandataniaa 0:49e87dcad299 74
Yolandataniaa 0:49e87dcad299 75 int getAccelX(void);
Yolandataniaa 0:49e87dcad299 76
Yolandataniaa 0:49e87dcad299 77 void compassResetOffsetValue();
Yolandataniaa 0:49e87dcad299 78 /**
Yolandataniaa 0:49e87dcad299 79 * Reset offset value from compass, set the initial condition from compass to be reference theta
Yolandataniaa 0:49e87dcad299 80 *
Yolandataniaa 0:49e87dcad299 81 */
Yolandataniaa 0:49e87dcad299 82
Yolandataniaa 0:49e87dcad299 83 void compassUpdateValue();
Yolandataniaa 0:49e87dcad299 84 /**
Yolandataniaa 0:49e87dcad299 85 * Update value from compass using theta reference
Yolandataniaa 0:49e87dcad299 86 */
Yolandataniaa 0:49e87dcad299 87
Yolandataniaa 0:49e87dcad299 88 float compassValue();
Yolandataniaa 0:49e87dcad299 89 /**
Yolandataniaa 0:49e87dcad299 90 * Get the compass value, theta will be in degree from -180 to 180
Yolandataniaa 0:49e87dcad299 91 */
Yolandataniaa 0:49e87dcad299 92
Yolandataniaa 0:49e87dcad299 93 private :
Yolandataniaa 0:49e87dcad299 94 float _offset_compass_value;
Yolandataniaa 0:49e87dcad299 95 float _theta_origin;
Yolandataniaa 0:49e87dcad299 96 float _theta_offset;
Yolandataniaa 0:49e87dcad299 97
Yolandataniaa 0:49e87dcad299 98 };
Yolandataniaa 0:49e87dcad299 99
Yolandataniaa 0:49e87dcad299 100 #endif /* CMPS_KRAI_H */