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.
Diff: main.cpp
- Revision:
- 2:4d280faa7d59
- Parent:
- 1:4a358f08c963
- Child:
- 3:f56810dbc1ce
--- a/main.cpp Sun Nov 15 14:51:28 2020 +0000
+++ b/main.cpp Sun Nov 15 15:07:08 2020 +0000
@@ -50,10 +50,25 @@
Serial xbee(USBTX, USBRX);
#endif
-/*タイマー関係設定*/
-Ticker pwm;
+
+/* WatchDogTimer関係 */
+Ticker tick_WDT;
+const double TIME_WDT = 2.0; // [sec] : WDTの周期設定
+bool flag_WDT = 0;
+void WDT_int(){
+ if(flag_WDT == 1){ // 一定時間反応がなかったためスラスター,ポンプのパワーオフ.
+ sluster_power = 0;
+ pump_power = 0;
+ }
+ flag_WDT = 1;
+}
+void WDT_init(){
+ tick_WDT.attach(&WDT_int, TIME_WDT);
+}
+
/* PWM出力用割り込み関数 */
+Ticker pwm;
void myPWM(void)
{
static int t = 0;
@@ -74,6 +89,7 @@
/* xbee or usb シリアル受信時実行関数 */
void SerialReceive(void)
{
+ flag_WDT = 0; // シリアルの信号を受け取るたびにWDTのフラグを折る.
char message = xbee.getc();
while(xbee.readable()) // bufferを綺麗に
xbee.getc();
@@ -116,6 +132,7 @@
}
+
/* メイン文 */
int main()
{
@@ -128,6 +145,7 @@
xbee_nreset = 1; // xBee nreset
xbee.baud(9600);
xbee.attach(SerialReceive,Serial::RxIrq);
+ WDT_init();
// start motion
wait(1);