Skip to content

Commit

Permalink
Flashed to CF controlling Cherokey-Rover
Browse files Browse the repository at this point in the history
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
sayboltm committed May 30, 2018
1 parent ca2cc9b commit 8c210d8
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ PROJ_OBJ += filter.o cpuid.o cfassert.o eprintf.o crc.o num.o debug.o
PROJ_OBJ += version.o FreeRTOS-openocd.o
PROJ_OBJ_CF2 += configblockeeprom.o crc_bosch.o
PROJ_OBJ_CF2 += sleepus.o
# Added for crazycar
PROJ_OBJ_CF2 += crazycar.o
CFLAGS += -DDECK_FORCE=bcCrazycar

# Libs
PROJ_OBJ_CF2 += libarm_math.a
Expand Down Expand Up @@ -282,8 +285,8 @@ CFLAGS += -MD -MP -MF $(BIN)/dep/$(@).d -MQ $(@)
#Permits to remove un-used functions and global variables from output file
CFLAGS += -ffunction-sections -fdata-sections
# Prevent promoting floats to doubles
CFLAGS += -Wdouble-promotion

#CFLAGS += -Wdouble-promotion
# REMOVED FOR CRAZYCAR LOL

ASFLAGS = $(PROCESSOR) $(INCLUDES)
LDFLAGS = --specs=nano.specs $(PROCESSOR) -Wl,-Map=$(PROG).map,--cref,--gc-sections,--undefined=uxTopUsedPriority
Expand Down Expand Up @@ -403,3 +406,4 @@ include tools/make/targets.mk

unit:
rake unit "DEFINES=$(CFLAGS)" "FILES=$(FILES)"

116 changes: 116 additions & 0 deletions src/deck/drivers/src/crazycar.c
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);

0 comments on commit 8c210d8

Please sign in to comment.