From 34efd24ba1df171396576272b398dbbb45fe8a8a Mon Sep 17 00:00:00 2001 From: kanja Date: Tue, 17 Sep 2013 00:34:02 +0900 Subject: [PATCH] =?utf8?q?ETBalanceRunner:=20Reset()=E3=81=8C=E3=81=86?= =?utf8?q?=E3=81=BE=E3=81=8F=E5=8B=95=E3=81=8F=E3=82=88=E3=81=86=E3=81=AB?= =?utf8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ETBalanceRunner.cpp | 12 +++++++++--- ETBalanceRunner.h | 1 + ETBalanceRunnerTest/balancertestmain.cpp | 7 +++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ETBalanceRunner.cpp b/ETBalanceRunner.cpp index 659d899..47d2855 100644 --- a/ETBalanceRunner.cpp +++ b/ETBalanceRunner.cpp @@ -10,15 +10,21 @@ extern "C" { namespace ecrobot{ ETBalanceRunner::ETBalanceRunner(Motor& motorL, Motor& motorR, GyroSensor& gyro, Nxt& nxt) - : m_motorL(motorL), m_motorR(motorR), m_gyro(gyro), m_nxt(nxt), m_gyrooffset(610), m_bException(false), m_msec(0) + : m_motorL(motorL), m_motorR(motorR), m_gyro(gyro), m_nxt(nxt), + m_bInitialized(false), m_gyrooffset(610), m_bException(false), m_msec(0) { - balance_init(); } ETBalanceRunner::~ETBalanceRunner(void) { } void ETBalanceRunner::Run(int forward, int turn) { + if(!m_bInitialized){ + balance_init(); + m_motorL.reset(); + m_motorR.reset(); + m_bInitialized = true; + } S8 r,l; balance_control(forward,0,m_gyro.get(),m_gyrooffset,m_motorL.getCount(),m_motorR.getCount(),m_nxt.getBattMv(),&l,&r); JudgeException(l,r); @@ -49,7 +55,7 @@ void ETBalanceRunner::Stop() } void ETBalanceRunner::Reset() { - balance_init(); + m_bInitialized = false; m_bException = false; m_msec = 0; } diff --git a/ETBalanceRunner.h b/ETBalanceRunner.h index 1777639..91a6f00 100644 --- a/ETBalanceRunner.h +++ b/ETBalanceRunner.h @@ -13,6 +13,7 @@ class ETBalanceRunner : public Runner Motor& m_motorR; GyroSensor& m_gyro; Nxt& m_nxt; + bool m_bInitialized; int m_gyrooffset; bool m_bException; int m_msec; diff --git a/ETBalanceRunnerTest/balancertestmain.cpp b/ETBalanceRunnerTest/balancertestmain.cpp index dd674d7..ff97c2a 100644 --- a/ETBalanceRunnerTest/balancertestmain.cpp +++ b/ETBalanceRunnerTest/balancertestmain.cpp @@ -110,6 +110,13 @@ TASK(TaskMain) TASK(Task4ms) { + if(touch.isPressed()){ + runner.Stop(); + runner.Reset(); + ActivateTask(TaskMain); + TerminateTask(); + return; + } runner.Run(150,0); tailcontroler.Control(); -- 2.11.0