Commit 0871f6b0 authored by Arnaud Cadot's avatar Arnaud Cadot

- Added KJ strat [WIP]

parent 5303167f
*.cmd
*.cbTemp
*.jpg
*.JPG
......
#ifndef KJ2016TEMPO_H
#define KJ2016TEMPO_H
/**
* @brief Runs the strategy for Krabi Junior 2016
*
* No odometry or feedback this year on this bot. It's fully temporised and driven by continuous servos.
*/
class KJ2016Tempo
{
unsigned int LEFT_SERVO_ID;
unsigned int RIGHT_SERVO_ID;
public:
/**
* @brief Runs the strategy
*/
static void run(bool isYellow);
~KJ2016Tempo();
private:
void enginesStart();
void enginesStop();
void turn90(bool toLeft);
void move(int distance);
void wasteTime(unsigned int time);
KJ2016Tempo(unsigned int leftServoID, unsigned int rightServoID);
};
#endif // KJ2016TEMPO_H
......@@ -21,9 +21,9 @@ public:
// Mettez toutes vos initialisations de PIN dans la fonction "initialisation"
// On l'appellera ensuite dans le main au tout début pour tout initialiser d'un coup
virtual void initGPIO();
void initRotaryEncoders();
virtual void initActionneurs();
};
......
This diff is collapsed.
#include "KJ2016Tempo.h"
#include "interfaceServosNumeriques.h"
#include "actionneurs/fishingNet.h"
KJ2016Tempo::KJ2016Tempo(unsigned int leftServoID, unsigned int rightServoID): LEFT_SERVO_ID(leftServoID), RIGHT_SERVO_ID(rightServoID)
{}
KJ2016Tempo::~KJ2016Tempo()
{
enginesStop();
}
void KJ2016Tempo::run(bool isYellow)
{
/** ID for the driving servos **/
/* Left and right is relative to the starting position */
const unsigned int SERVO_ONE_ID = 0;
const unsigned int SERVO_TWO_ID = 1;
KJ2016Tempo KJ(isYellow?SERVO_ONE_ID:SERVO_TWO_ID, isYellow?SERVO_TWO_ID:SERVO_ONE_ID);
/** KJ Strategy **/
KJ.move(100); // Leave the start area
KJ.turn90(true); // First turn (now heading toward the tanks)
KJ.move(500); // Drive into the wall
KJ.move(-50); // Back up for the turn
KJ.turn90(false); // Second turn (now parallel the tanks)
KJ.move(200); // Drive along the wall to the tanks
FishingNet::getSingleton()->deploy(); // Deploy the arm
FishingNet::getSingleton()->lowerNet(); // Deploy the net in the tank
KJ.move(100); // Drag the net in the tank
FishingNet::getSingleton()->raiseNet(); // Raise the net
FishingNet::getSingleton()->raiseArm(); // Raise the arm a little (to avoid the tank's sides
KJ.move(100); // Get to the target area
FishingNet::getSingleton()->deploy(); // Lower the arm a bit
FishingNet::getSingleton()->lowerNet(); // Lower the net
}
void KJ2016Tempo::enginesStart()
{
ServosNumeriques::changeContinuousRotationMode(LEFT_SERVO_ID, true);
ServosNumeriques::changeContinuousRotationMode(RIGHT_SERVO_ID, true);
}
void KJ2016Tempo::enginesStop()
{
ServosNumeriques::changeContinuousRotationMode(LEFT_SERVO_ID, false);
ServosNumeriques::changeContinuousRotationMode(RIGHT_SERVO_ID, false);
}
void KJ2016Tempo::turn90(bool toLeft)
{
const float correctionFactor = 1.0f;
const unsigned int servoOne = toLeft?LEFT_SERVO_ID:RIGHT_SERVO_ID;
const unsigned int servoTwo = toLeft?RIGHT_SERVO_ID:LEFT_SERVO_ID;
const unsigned int speed = 0x0100;
enginesStart();
ServosNumeriques::moveAtSpeed(0x0400 - speed, servoOne);
ServosNumeriques::moveAtSpeed(0x0400 + speed, servoTwo);
wasteTime(static_cast<unsigned int>( 1/((float)speed) * correctionFactor));
enginesStop();
}
void KJ2016Tempo::move(int distance)
{
const float correctionFactor = 1.f;
unsigned int speed = 0x0100;
speed = (distance>0)?speed:-speed;
enginesStart();
ServosNumeriques::moveAtSpeed(0x0400 + speed, LEFT_SERVO_ID);
ServosNumeriques::moveAtSpeed(0x0400 + speed, RIGHT_SERVO_ID);
wasteTime(static_cast<unsigned int>((float)distance / (float)speed * correctionFactor));
enginesStop();
}
void KJ2016Tempo::wasteTime(unsigned int time)
{
for(unsigned int i=0; i<time; ++i); //Meh
}
......@@ -23,8 +23,8 @@ void InitKrabiJunior::setYellow()
void InitKrabiJunior::initRotaryEncoders()
{
#ifdef ROBOTHW
rcd = new QuadratureCoderHandler(TIM4, GPIOB, GPIO_Pin_6, GPIOB, GPIO_Pin_7, GPIO_AF_TIM4, GPIO_PinSource6, GPIO_PinSource7);
rcg = new QuadratureCoderHandler(TIM1, GPIOA, GPIO_Pin_8, GPIOA, GPIO_Pin_9, GPIO_AF_TIM1, GPIO_PinSource8, GPIO_PinSource9);
// rcd = new QuadratureCoderHandler(TIM4, GPIOB, GPIO_Pin_6, GPIOB, GPIO_Pin_7, GPIO_AF_TIM4, GPIO_PinSource6, GPIO_PinSource7);
// rcg = new QuadratureCoderHandler(TIM1, GPIOA, GPIO_Pin_8, GPIOA, GPIO_Pin_9, GPIO_AF_TIM1, GPIO_PinSource8, GPIO_PinSource9);
#endif
}
......@@ -59,7 +59,5 @@ void InitKrabiJunior::initGPIO()
#ifdef ROBOTHW
Tirette tirette(GPIOA, GPIO_Pin_10);
QuadratureCoderHandler* rcd = new QuadratureCoderHandler(TIM4, GPIOB, GPIO_Pin_6, GPIOB, GPIO_Pin_7, GPIO_AF_TIM4 ,GPIO_PinSource6, GPIO_PinSource7);
QuadratureCoderHandler* rcg = new QuadratureCoderHandler(TIM1, GPIOA, GPIO_Pin_8, GPIOA, GPIO_Pin_9, GPIO_AF_TIM1 ,GPIO_PinSource8, GPIO_PinSource9);
#endif
}
......@@ -25,13 +25,17 @@ extern "C" void SysTick_Handler()
}
#endif
#ifndef STM32F40_41xxx
Odometrie::odometrie->update();
//StrategieV2::update();
Tourelle::getSingleton()->update();
Asservissement::asservissement->update();
#endif
}
#ifdef ROBOTHW
......
#include "hardware/remote.h"
#include "initKrabiJunior.h"
#include "initkrabi.h"
#if defined(STM32F40_41xxx)
#include "initKrabiJunior.h"
#include "KJ2016Tempo.h"
#elif defined(STM32F10X_CL)
#include "initkrabi.h"
#endif
#define NVIC_CCR ((volatile unsigned long *)(0xE000ED14))
......@@ -14,7 +20,10 @@ int main()
#if defined(STM32F40_41xxx) // H405
InitKrabiJunior initKJ;
initKJ.init();
//initKJ.init(); // Not this year - we are NOT using odometry, strategiev2, etc, so it's best not to init them at all
initKJ.initClock();
initKJ.initGPIO();
initKJ.initActionneurs(); // For servos
#elif defined(STM32F10X_CL) // H107
InitKrabi initKrabi;
initKrabi.init();
......@@ -22,6 +31,11 @@ int main()
Remote::getSingleton()->waitForConnection();
/** Action sequencing for KJ **/
#ifdef STM32F40_41xxx
KJ2016Tempo::run(initKJ.isYellow());
#endif
while(1);
return 0;
......
......@@ -75,7 +75,7 @@ StrategieV2::StrategieV2(bool yellow)
sharpsToCheck[i] = false;
#if defined(STM32F40_41xxx) || defined(STM32F10X_MD) // H405
actionsToDo[0] = (MediumLevelAction*) new KrabiJunior2016(yellow);
//actionsToDo[0] = (MediumLevelAction*) new KrabiJunior2016(yellow);
#else
actionsToDo[0] = (MediumLevelAction*) new Krabi2016(yellow);
#endif
......
_estack = 0x20010000;
MEMORY
{
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K
rom (rx) : ORIGIN = 0x00000000, LENGTH = 256K
}
SECTIONS
{
. = 0x0; /* From 0x00000000 */
.text : {
*(.isr_vector) /* Vector table */
*(.text) /* Program code */
*(.text.*)
*(.rodata) /* Read only data */
*(.rodata.*) /* Read only data */
} >rom
.gnu.linkonce : {
*(.gnu.linkonce.t.*)
*(.gnu.linkonce.r.*)
} >rom
.gnu.linkoncearm : {
*(.gnu.linkonce.armexidx.*)
} >rom
.rel.text :
{
*(.rel.text)
*(.rel.text.*)
*(.rel.gnu.linkonce.t*)
} >rom
__exidx_start=.;
.exidx : {
*(.ARM.exidx*)
}>rom
__exidx_end =.;
.extab : {
*(.ARM.extab*)
}>rom
.sidat : {
_etext = .;
_sidata = _etext; /* Used by the startup in order to initialize the .data section */
} >rom
. = 0x20000000; /* From 0x20000000 */
.data : AT ( _sidata ) {
. = ALIGN(4);
_sdata = .;
*(.data) /* Data memory */
. = ALIGN(4);
_edata = .;
} >ram
.bss : {
. = ALIGN(4);
_sbss = .;
*(.bss) /* Zero-filled run time allocate data memory */
. = ALIGN(4);
_ebss = .;
} >ram
_end = .;
}
/*========== end of file ==========*/
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment