The main purpose of this project is to control DC motors in open loop, in order to set speed and direction in real time. One MCU and one H-bridge are used to achieve this. PC and MCU communicates writing each other custom packets. Basically, the idea is this:
- PC to MCU serial communication to set the motor parameters.
- MCU to PC serial communication to check the motor status.
- PWM generation
- Periodically send status-packets with a timer based ISR
- Receive setting-packets with UART based ISR
- Open, set and close serial communication using unix API
- Multithreading (1 sender thread, 1 listener thread)
- Graphic Unit Interface with ncurses
- Option flags handling
- AVR atmega2560
- DC motor
- Battery pack (6V, 2850mAh)
- L298N H-bridge
- OS: Ubuntu 16.04
- Language: C
- PC compiler: gcc (version 5.4.0)
- MCU compiler: avr-gcc (version 4.9.2)
- GUI lib: ncurses.h
Firts of all, make sure you have installed ncurses library. If not, type:
sudo apt-get install libncurses5-dev libncursesw5-dev
To upload AVR code in your microcontroller you need avr-gcc:
sudo apt-get install gcc-avr binutils-avr gdb-avr avr-libc avrdude
AVR code can be compiled and uploaded typing :
cd avr
make
make dc_control.hex
sudo addgroup <your username> dialout
cd ..
Pc-side code can be found in "serial" directory. Run Makefile in order to compile and create the executable:
cd serial
make
After that, you are ready to run the program.
Pc-side code can be found in "serial" directory. Run Makefile in order to compile and create the executable:
./main
Main can be launched with different optional flags:
./main -l
Enable linear interpolation on avr. With this flag enabled motor direction change smoothly.
./main -f
Force avr re-upload/restart.
./main -d
Debuf mode (deprecated). Used for communication testing, GUI disabled.
- design overall software workflow
- packet data structure
- PWM generation: motor now work properly
- UART basic functions
- timer based ISR (send status every 1 second)
- UART ISR (reading incoming packet)
- handshaking routine
- test new features: works as expected (with cutecom)
- start working on pc side
- set termios struct parameters
- read() and write() syscall
- makefile
- transmission fixes (avr side)
- handshake protocol
- serial packet_t structure
- serial functions (readPacket() and writePacket())
- packet_t data manipulation functions
- fixes on avr side
- fixes on readPacket() and writePacket()
- listener thread for blocking read
- mutex synch
- main testing: some bugs, but works
- fix bug #2
- linear interpolation for smooth speed changes
- testing different handshake protocols
- choose the definitive handshake
- add option flag -s to enable linear interpolation on avr
- add option flag -f to force avr re-upload
- cleaning: remove useless stuff
- fixing linear interpolation