/** * Domino bot that tracks line and builds domino pieces * * Author: Jan Dvořák z Vozerovic * E-mail: dvorkaman@gmail.com * Web: dvorkaman.asp2.cz * Created: 2014 */ /* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Libraries #include "stdio.h" #define _define_bool_ 0x01 #include "libSystem.c" #include "libSystemTime.c" #include "libGPIO.c" #include "libPWM.c" #include "libPWMTone.c" #include "libUSART.c" #include "libAnalog.c" #include "libMotor.c" #include "libServo.c" #include "libUtils.c" #include "libXbeeApi.c" #include "libRemote.c" #include "libEXTI.c" #include "libSensors.c" // Defines #define ANALOG_INPUTS 3 #define LEVER_IN 0x00 #define LEVER_OUT 0xA0 #define SELECTOR_1 0x20 #define SELECTOR_2 0x6B #define SELECTOR_3 0xB6 #define BELT_SPEED 100 // % #define STEER_SPEED 60 // % #define BARRIER_SPEED 100 // % #define DRIVE_SPEED 70 // % #define LEVER_MOVE_TIME 1000 // ms #define SELECTOR_MOVE_TIME 500 // ms #define BELT_MOVE_TIME 2400 // ms #define BARRIER_MOVE_AFTER_BELT 2000 // ms #define BARRIER_UP_TIME 1500 // ms #define BARRIER_DOWN 1700 // ms #define BARRIER_KEEP_UP_TIME 500 // ms #define STEER_TIME 250 // ms #define STEER_AVAILABLE_TIME 10 // ms #define LINE_TRESHOLD (1000 >> ANALOG_FILTER_INGORE_LSB) // units #define DRIVE_TIME 200 // ms // Structs typedef struct { // 0 = available // 1 = move command // 2 = lever in // 3 = lever out // 4 = selector moving uint8_t mode; uint8_t selected; // 1 - 4 uint8_t direction; // 0 = increment; 1 = decrement systemTime nextStepTime; } selectorUnitStruct; typedef struct { // 0 = available // 1 = rotating uint8_t mode; systemTime offTime; } beltUnitStruct; typedef struct { // 0 = available // 1 = waiting to move // 2 = moving up // 3 = waiting to move down // 4 = moving down uint8_t mode; systemTime nextStepTime; } barrierUnitStruct; typedef struct { // 0 = available // 1 = rotating // 2 = waiting to be available uint8_t mode; // 0 = keep // 1 = left // 2 = right uint8_t dir; uint8_t lastDir; systemTime offTime; } steerStruct; typedef struct { // 0 = available // 1 = driving uint8_t mode; systemTime offTime; } driveUnitStruct; // Headers void initializePeriherals(void); void clearPeriherals(void); void processLineValues(BitAction left, BitAction middle, BitAction right); BitAction parseLineValue(uint16_t value); void selectorDebug(void); void checkDebug(void); void selectorLoop(void); void beltLoop(void); void barrierLoop(void); void steerLoop(void); void driveLoop(void);