Compare commits
6 Commits
9f3f039bb0
...
27733e737a
Author | SHA1 | Date |
---|---|---|
|
27733e737a | |
|
420e49086c | |
|
3c80ada3d7 | |
|
cd937c5e50 | |
|
a2d0072635 | |
|
c9c98375c7 |
9
IO.hpp
9
IO.hpp
|
@ -67,7 +67,7 @@ class IO {
|
||||||
pinMode(PIN_TIRETTE, INPUT_PULLUP);
|
pinMode(PIN_TIRETTE, INPUT_PULLUP);
|
||||||
pinMode(PIN_BUTTON_COLOR, INPUT_PULLUP);
|
pinMode(PIN_BUTTON_COLOR, INPUT_PULLUP);
|
||||||
|
|
||||||
m_code_cell->Motion_RotationRead(m_init_x, m_init_y, m_init_z);
|
initGyroscope();
|
||||||
|
|
||||||
m_initMotors();
|
m_initMotors();
|
||||||
m_initServo();
|
m_initServo();
|
||||||
|
@ -84,6 +84,11 @@ class IO {
|
||||||
return nb_errors;
|
return nb_errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initGyroscope()
|
||||||
|
{
|
||||||
|
m_code_cell->Motion_RotationRead(m_init_x, m_init_y, m_init_z);
|
||||||
|
}
|
||||||
|
|
||||||
int update()
|
int update()
|
||||||
{
|
{
|
||||||
static unsigned long last_color_change_time {0};
|
static unsigned long last_color_change_time {0};
|
||||||
|
@ -122,7 +127,7 @@ class IO {
|
||||||
m_is_tirette_pulled = (digitalRead(PIN_TIRETTE) == HIGH);
|
m_is_tirette_pulled = (digitalRead(PIN_TIRETTE) == HIGH);
|
||||||
m_is_color_blue = is_color_blue;
|
m_is_color_blue = is_color_blue;
|
||||||
|
|
||||||
is_color_blue = (digitalRead(PIN_BUTTON_COLOR) == HIGH);
|
is_color_blue = (digitalRead(PIN_BUTTON_COLOR) == LOW);
|
||||||
|
|
||||||
if(m_is_motor_control_activated)
|
if(m_is_motor_control_activated)
|
||||||
{
|
{
|
||||||
|
|
39
Main.ino
39
Main.ino
|
@ -5,6 +5,10 @@
|
||||||
|
|
||||||
#include "IO.hpp"
|
#include "IO.hpp"
|
||||||
|
|
||||||
|
#define NORMAL_SPEED 2048.0f
|
||||||
|
#define TURNING_SPEED 1500.0f
|
||||||
|
#define ON_STAGE_SPEED 1120.0f
|
||||||
|
|
||||||
// Unit tests activation
|
// Unit tests activation
|
||||||
//#define UNIT_TESTS
|
//#define UNIT_TESTS
|
||||||
|
|
||||||
|
@ -108,43 +112,35 @@ void loop()
|
||||||
case State::WaitingTimer:
|
case State::WaitingTimer:
|
||||||
static unsigned long initial_time = millis();
|
static unsigned long initial_time = millis();
|
||||||
|
|
||||||
//if(millis() - initial_time >= 90000)
|
if(millis() - initial_time >= 87000)
|
||||||
if(millis() - initial_time >= 2000)
|
//if(millis() - initial_time >= 2000)
|
||||||
{
|
{
|
||||||
|
my_IO.initGyroscope();
|
||||||
actual_state = State::ForwardToRamp;
|
actual_state = State::ForwardToRamp;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::ForwardToRamp:
|
case State::ForwardToRamp:
|
||||||
my_IO.motorControlOn();
|
my_IO.motorControlOn();
|
||||||
my_IO.setSpeed(2048.0f);
|
my_IO.setSpeed(2000.0f);
|
||||||
|
|
||||||
if(my_IO.getAngle(Axes::Y) < -5.0f)
|
if(my_IO.getAngle(Axes::Y) < -8.0f)
|
||||||
{
|
{
|
||||||
actual_state = State::ForwardToScene;
|
actual_state = State::ForwardToScene;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::ForwardToScene:
|
case State::ForwardToScene:
|
||||||
my_IO.setSpeed(2048.0f);
|
my_IO.setSpeed(2000.0f);
|
||||||
|
if(my_IO.getAngle(Axes::Y) > -3.5f)
|
||||||
if(my_IO.getAngle(Axes::Y) > -5.0f)
|
|
||||||
{
|
{
|
||||||
|
my_IO.setSpeed(1300.0f);
|
||||||
actual_state = my_IO.isSelectedColorBlue() ? State::Turn90Blue : State::Turn90Yellow;
|
actual_state = my_IO.isSelectedColorBlue() ? State::Turn90Blue : State::Turn90Yellow;
|
||||||
//actual_state = State::Dancing;
|
//actual_state = State::Dancing;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case State::Turn90Blue:
|
case State::Turn90Blue:
|
||||||
my_IO.setDirWithAngularSpeed(-90.0f);
|
|
||||||
|
|
||||||
if(my_IO.getAngle(Axes::Z) < -80.0f)
|
|
||||||
{
|
|
||||||
actual_state = State::ForwardToSceneEdge;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case State::Turn90Yellow:
|
|
||||||
my_IO.setDirWithAngularSpeed(90.0f);
|
my_IO.setDirWithAngularSpeed(90.0f);
|
||||||
|
|
||||||
if(my_IO.getAngle(Axes::Z) >= 80.0f)
|
if(my_IO.getAngle(Axes::Z) >= 80.0f)
|
||||||
|
@ -153,10 +149,19 @@ void loop()
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case State::Turn90Yellow:
|
||||||
|
my_IO.setDirWithAngularSpeed(-90.0f);
|
||||||
|
|
||||||
|
if(my_IO.getAngle(Axes::Z) <= -80.0f)
|
||||||
|
{
|
||||||
|
actual_state = State::ForwardToSceneEdge;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case State::ForwardToSceneEdge:
|
case State::ForwardToSceneEdge:
|
||||||
my_IO.setSpeed(1100.0f);
|
my_IO.setSpeed(1100.0f);
|
||||||
|
|
||||||
if(my_IO.getAngle(Axes::Y) > 5.0f)
|
if(my_IO.getAngle(Axes::Y) > 3.0f)
|
||||||
{
|
{
|
||||||
actual_state = State::Dancing;
|
actual_state = State::Dancing;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue