forked from bitcraze/crazyflie-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flashed to CF controlling Cherokey-Rover
off of commit: commit 2107af2 Merge: e9e84fd 8b51f61 Author: Arnaud Taffanel <[email protected]> Date: Fri Apr 6 08:51:45 2018 +0200 Merge pull request bitcraze#303 from USC-ACTLab/high-level-traj High-level commander: trajectory upload and exec.
- Loading branch information
Showing
2 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* || ____ _ __ | ||
* +------+ / __ )(_) /_______________ _____ ___ | ||
* | 0xBC | / __ / / __/ ___/ ___/ __ `/_ / / _ \ | ||
* +------+ / /_/ / / /_/ /__/ / / /_/ / / /_/ __/ | ||
* || || /_____/_/\__/\___/_/ \__,_/ /___/\___/ | ||
* | ||
* Crazyflie control firmware | ||
* | ||
* Copyright (C) 2016 Bitcraze AB | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, in version 3. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* crazycar.c - Deck driver for the Crazyflie 2.0 Crazycar deck | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <stdlib.h> | ||
#include "stm32fxxx.h" | ||
|
||
#include "deck.h" | ||
|
||
#include "FreeRTOS.h" | ||
#include "timers.h" | ||
#include "uart2.h" | ||
#include "debug.h" | ||
#include "log.h" | ||
|
||
static int logIdRoll; | ||
static int logIdPitch; | ||
|
||
/* Template data for controlling the Skeleton bot */ | ||
static char data[] = {'S', 'S', '0', '0', 0x0A}; | ||
|
||
/* Create output string for sending to the Skeleton bot */ | ||
void carSetControl(float roll, float pitch) | ||
{ | ||
float f = pitch / 30.0; | ||
float t = roll / 60.0; | ||
|
||
float m1 = f + t; | ||
float m2 = f - t; | ||
|
||
if (m1 > 1.0) | ||
m1 = 1.0; | ||
if (m1 < -1) | ||
m1 = -1; | ||
|
||
if (m2 > 1.0) | ||
m2 = 1.0; | ||
if (m2 < -1) | ||
m2 = -1; | ||
|
||
if (m1 > 0) | ||
{ | ||
data[0] = 'F'; | ||
data[2] = (int)(m1 * 10) + '0'; | ||
} else { | ||
data[0] = 'B'; | ||
data[2] = (int)(m1 * -10) + '0'; | ||
} | ||
|
||
if (m2 > 0) | ||
{ | ||
data[1] = 'F'; | ||
data[3] = (int)(m2 * 10) + '0'; | ||
} else { | ||
data[1] = 'B'; | ||
data[3] = (int)(m2 * -10) + '0'; | ||
} | ||
} | ||
|
||
|
||
/* Send commands to Skeleton bot at 10Hz */ | ||
static xTimerHandle timer; | ||
static void ctrlTimer(xTimerHandle timer) | ||
{ | ||
carSetControl(logGetFloat(logIdRoll), logGetFloat(logIdPitch)); | ||
uart2SendData(sizeof(data), (uint8_t*)data); | ||
} | ||
|
||
/* Initialize the deck driver */ | ||
static void crazycarDeckInit(DeckInfo *info) | ||
{ | ||
logIdRoll = logGetVarId("ctrltarget", "roll"); | ||
logIdPitch = logGetVarId("ctrltarget", "pitch"); | ||
|
||
uart2Init(19200); | ||
timer = xTimerCreate( "ctrlTimer", M2T(100), | ||
pdTRUE, NULL, ctrlTimer ); | ||
xTimerStart(timer, 100); | ||
} | ||
|
||
static const DeckDriver crazycar_deck = { | ||
.vid = 0xBC, | ||
.pid = 0x00, | ||
.name = "bcCrazycar", | ||
|
||
.usedPeriph = DECK_USING_UART2, | ||
.usedGpio = DECK_USING_TX2 | DECK_USING_RX2, | ||
|
||
.init = crazycarDeckInit | ||
}; | ||
|
||
DECK_DRIVER(crazycar_deck); | ||
|