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.
Fork of CoilGun by
coilgun.h
00001 #ifndef COILGUN_H 00002 #define COILGUN_H 00003 00004 #include "mbed.h" 00005 00006 /** Class for controlling coilgun */ 00007 class Coilgun { 00008 public: 00009 /** Create an instance of the Coilgun connected to specfied pins */ 00010 Coilgun(PinName kickPinName, PinName chipPinName, PinName chargePinName, PinName donePinName); 00011 00012 /** Kick with coilgun */ 00013 void kick(unsigned int kickLength, unsigned int kickDelay, unsigned int chipLength, unsigned int chipDelay); 00014 /** Stop kick */ 00015 void kickEnd(void); 00016 void chipEnd(void); 00017 00018 /** Charge capacitor */ 00019 void charge(void); 00020 /** Stop charging capacitor */ 00021 void chargeEnd(void); 00022 00023 /** Discharge capacitor */ 00024 void discharge(void); 00025 /** Stop discharging */ 00026 void dischargeEnd(void); 00027 00028 /** Read only 00029 * Will be set to true, when charge() is called, 00030 * false, when discharge is called. 00031 * NB! if discharge is interrupted, capacitor may still have some charge on it. 00032 */ 00033 bool isCharged; 00034 00035 private: 00036 enum State {idle, kicking, charging, discharging}; 00037 State state; 00038 00039 unsigned int currentKickLength; 00040 unsigned int currentKickDelay; 00041 unsigned int currentChipLength; 00042 unsigned int currentChipDelay; 00043 00044 DigitalOut kickPin; 00045 DigitalOut chipPin; 00046 DigitalOut chargePin; 00047 InterruptIn donePin; 00048 00049 Timeout kickTimeout; // This will end kicking 00050 Timeout kickDelayTimeout; 00051 Timeout chipTimeout; 00052 Timeout chipDelayTimeout; 00053 00054 bool kickActive; 00055 bool chipActive; 00056 00057 Timeout dischargeTimeout; // This will end discharging 00058 Ticker discharger; // Calls short kicks during discharge 00059 00060 void kickDelayEnd(void); 00061 void chipDelayEnd(void); 00062 00063 void changeState(State new_state); 00064 void dischargeKick(void); 00065 void kick(unsigned int kickLength, unsigned int kickDelay, unsigned int chipLength, unsigned int chipDelay, bool change_state); 00066 }; 00067 00068 #endif
Generated on Wed Jul 13 2022 02:22:10 by
1.7.2
