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.
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.
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()
andDisplay::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, seeRemoteControl::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
- use
- 2 servos
- UART console command interface (115200 Baud with 8N1 configuration)
- 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)
Note for Atom IDE users: When installed via Atom package, Bash (Shell) used in the terminal currently does not seem to recognise the command platformio
; use pio
instead. (State as of May 2019)
- Install PlatformIO core as described here
- can be skipped, if using VS Code IDE with PlatformIO extension
- can be skipped, if using Atom IDE with package platformio-ide
- if you don't want to use PlatformIO core, see manual build for setup
- Clone this git repository:
git clone https://github.com/tsandmann/ctbot-atmega
- Change to cloned repo:
cd ctbot-atmega
- 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
- Commandline build:
-
Build project
- Commandline:
platformio 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
) - Atom: Select project folder in sidebar -> Menu
PlatformIO
->Build
or shortcut (Alt+Ctrl+B
)
- Commandline:
-
Upload firmware image
- Flash
firmware.hex
(located in folder.pioenvs/1284p16m/
) using avrdude as described here.- todo: update for use of platformio upload target
- Flash
-
Use a terminal program (e.g. minicom) or telnet to connect
- If you use minicom:
- goto
Serial port setup
settings and setSerial Device
to your serial device,Bps/Par/Bits
to115200 8N1
andHardware Flow Control
toNo
as well asSoftware Flow Control
toNo
- goto
Screen and keyboard
settings and setAdd carriage return
toYes
- goto
- If you use a WiPort:
telnet [IP_ADDRESS] 10002
- to switch to line mode echo press
CTRL + ]
and entermode line
- to disable local character press
CTRL + ]
and entermode -litecho
- to switch to line mode echo press
- If you use minicom:
-
Have fun with the command line interface
- type
help
to get a list and description of available commands
- type
-
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 justset speed
) to stop
-
Press play on remote control get a little easter egg on the command line interface :) or I/II to shutdown the bot :(
- Hard coded usage of timer0
- Uart buffer space not adjustable
- ...
- If you use the ATmega with a 20 MHz clock, set
board_build.f_cpu
in platformio.ini to20000000UL
- For a c't-Bot with the hardware SPI patch, set
CtBotConfig::ENC_L_USE_PC5
in ctbot_config.h totrue
- To build the documentation with Doxygen:
doxygen Doxyfile
- PlantUML has to be installed, to build the UML diagrams
- documentation is located here: doc/html/index.html
- documentation is highly incomplete
- Conventions:
- indentation is done by 4 (four) spaces for each level, never ever use tabs (
\t
|HT
) - follow the C++ Core Guidelines. There are two really worth seeing talks about it: Bjarne Stroustrup "Writing Good C++14" and Herb Sutter "Writing Good C++14... By Default"
- Documentation is done with Doxygen, use Doxygen style 1
- at least all public members should be documented
- every task's implementation (mainly its
run()
method) should be modeled by an UML sequence diagram, e.g. as for CtBot::run()
- More to come soon
- indentation is done by 4 (four) spaces for each level, never ever use tabs (
- ...
- This is currently untested
- 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).
- 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
- Add the following subdirectories to your compiler include path:
src/
lib/cpputils_avr/src/
lib/pid/
lib/rc5/
lib/ulibcpp/src/
- 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) - Necessary linker flags:
-mmcu=atmega1284p -Wl,--gc-sections -flto -fuse-linker-plugin -lm
(if you link withavr-g++
) - Create an intel-hex file for avrdude with:
avr-objcopy -O ihex -R .eeprom YOUR_OUTPUT.elf YOUR_OUTPUT.hex
Branch | Build status |
---|---|
master |