Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
146 lines (124 sloc) 8.27 KB

c't-Bot ATmega framework

This is a very basic framework for the c't-Bot with an ATmega1284P controller. It is licensed under the terms of the GPLv3 license.

Summary

This code was created for testing a new and simplified design of the c't-Bot software framework. The basic idea is to have a modular structured framework implemented in C++ built on modern language features. Although it doesn't use the Arduino software framework for some reasons (see below), there are many similarities to an Arduino program, such as the usage of external libraries, etc.

Notice

Consider this as experimental code. If it breaks, you get to keep both pieces.

Differences against the original c't-Bot software framework

  • programming language: using C++ instead of C to have

    • object oriented programming,
    • a strict modular structure,
    • banishment of macros, #define, #ifdef and other unsafe stuff of the last century.
  • PlatformIO build system, because of:

    • independence of IDE and environment, just use what you like for editing and building the code.
    • works on common Linux distributions, macOS, Windows.
    • simple and minimalistic tool setup, you just have to install PlatformIO Core (see below).
    • it is an open source project.
    • ...
  • consistently reduced functionality

    • no behaviors available
    • support for basic components only
      • UART console command interface (115200 Baud with 8N1 configuration)
        • connect with USB-2-Bot adapter and terminal program like minicom or WiPort and telnet
        • type help + [ENTER] the get a list of supported commands
      • LEDs: Leds::on(), Leds::off(), Leds::set() implemented, see leds.h
      • LCD: Display::print() and Display::printf() implemented, see display.h
      • standard sensors (excluding mouse sensor), raw sensor values are reported on LC display or via console
      • remote control (HQ RC Univers 29 only in standard setup, see RemoteControl::RemoteControl() in remote_control.cpp for mapped keys)
      • motors with speed control
        • use set speed [LEFT] [RIGHT] to set speed of left / right wheel as percentage values (negative values to drive backwards)
        • alternatively use remote control to increase / decrease speed of wheels, see Usage
        • ToDo: PID calibration has to be done / fine tuned
      • 2 servos
    • ATmega1284P support only
    • simple test cases implemented (see tests.h for details)
      • LedTest: chaser lights
      • LcdTest: prints some nice stuff on the LC display
      • EnaTest: activates ENAs one by one in an endless loop
      • SensorLcdTest: displays all sensor information like the 'sensor display screen' of the original c't-Bot software (see SensorLcdTest::run() in tests.cpp for details)

Setup

  1. install PlatformIO core as described here
  2. clone this git repository: git clone https://github.com/tsandmann/ctbot-atmega
  3. change to cloned repo: cd ctbot-atmega
  4. initialize build system for...
    • commandline build: platformio init
    • VS Code project: platformio init --ide vscode
    • Eclipse CDT project: platformio init --ide eclipse
    • any other environment supported by PlatformIO

Usage

  1. build project

    • commandline: plaformio run
    • VS Code: use “Build” button on the PlatformIO toolbar or shortcut (ctrl/cmd+alt+b)
    • Eclipse CDT: Project -> Build Project or shortcut (ctrl/cmd+b)
  2. upload firmware image

    • flash firmware.hex (located in folder .pioenvs/1284p16m/) using avrdude as described here.
      • todo: update for use of platformio upload target
  3. use a terminal program (e.g. minicom) or telnet to connect

    • if you use minicom:
      • goto Serial port setup settings and set Serial Device to your serial device, Bps/Par/Bits to 115200 8N1 and Hardware Flow Control to No as well as Software Flow Control to No
      • goto Screen and keyboard settings and set Add carriage return to Yes
    • if you use a WiPort: telnet [IP_ADDRESS] 10002
      • to switch to line mode echo press CTRL + ] and enter mode line
      • to disable local character press CTRL + ] and enter mode -litecho
  4. have fun with the command line interface

    • type help to get a list and description of available commands
  5. cruise around with the c't-Bot using

    • your remote control: arrow keys for forward, backward, left, right and power button for stop
    • the command line interface: set speed 30 30 for 30% of max speed on both wheels, set speed 0 0 (or just set speed) to stop
  6. press play on remote control get a little easter egg on the command line interface :) or I/II to shutdown the bot :(

Why it doesn't use the Arduino software framework

  • hard coded usage of timer0
  • uart buffer space not adjustable
  • ...

Notices

Manual Build

  1. this is currently untested
  2. install a C++ compiler for the avr architecture, e.g. avr-g++ with avr-libc. It has to be capable to compile at least C++14 (no further libraries are needed).
  3. compile the following files from these subdirectories of the project:
    • src/*.cpp
    • lib/cpputils_avr/src/*.cpp
    • lib/pid/*.cpp
    • lib/rc5/*.cpp
    • lib/ulibcpp/src/*.cpp
    • lib/ulibcpp/src/abi/abi.cpp
  4. add the following subdirectories to your compiler include path:
    • src/
    • lib/cpputils_avr/src/
    • lib/pid/
    • lib/rc5/
    • lib/ulibcpp/src/
  5. further necessary compiler flags: -fno-exceptions -fno-threadsafe-statics -fpermissive -std=gnu++14 -Os -Wall -ffunction-sections -fdata-sections -flto -mmcu=atmega1284p -Wextra -DF_CPU=16000000UL (at least these are tested and known to work)
  6. necessary linker flags: -mmcu=atmega1284p -Wl,--gc-sections -flto -fuse-linker-plugin -lm (if you link with avr-g++)
  7. create an intel-hex file for avrdude with: avr-objcopy -O ihex -R .eeprom YOUR_OUTPUT.elf YOUR_OUTPUT.hex
You can’t perform that action at this time.