https://github.com/dsm/demir_firmware
DEMIR is a firmware for brushed dc motor with position control.
https://github.com/dsm/demir_firmware
arduino atmega328p brushed-motor control motor pid polynomial
Last synced: about 1 month ago
JSON representation
DEMIR is a firmware for brushed dc motor with position control.
- Host: GitHub
- URL: https://github.com/dsm/demir_firmware
- Owner: dsm
- License: mit
- Created: 2025-05-06T08:10:30.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-05-24T09:04:58.000Z (about 1 year ago)
- Last Synced: 2025-06-05T23:08:14.761Z (12 months ago)
- Topics: arduino, atmega328p, brushed-motor, control, motor, pid, polynomial
- Language: C++
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DEMIR (Dynamically Enhanced Motor Intelligence for Robots)
A sophisticated closed-loop motor driver platform designed for precise robotic control applications.
## π Overview
DEMIR is an advanced motor control system developed as a final year engineering project. It combines hardware and software to deliver high-precision motor control with intelligent feedback mechanisms.
### Key Features
- **Closed-loop Control**: Encoder-based PID position controller
- **Profile Generation**: Smooth motion profiles for precise movements
- **Multi-motor Support**: Control up to 4 motors simultaneously
- **Real-time Communication**: UART/Serial interface for commands
- **Hardware Integration**: Built around ATmega328P microcontroller and VNH7070 motor driver
## π§ Hardware Specifications
- **Microcontroller**: ATmega328P (Arduino UNO compatible)
- **Motor Driver**: VNH7070 H-bridge driver
- **Encoder Support**: Quadrature encoder input
- **Communication**: UART (9600 baud default)
- **Power Supply**: 12V DC input for motors
- **Operating Voltage**: 5V logic level
## π Software Features
### Motion Control
- **PID Controller**: Tunable proportional, integral, and derivative gains
- **Velocity Profiling**: Configurable acceleration and deceleration ramps
- **Position Accuracy**: High-precision positioning with encoder feedback
- **Real-time Monitoring**: Live position and velocity feedback
### Communication Protocol
- Serial command interface
- Status reporting
- Parameter configuration
- Emergency stop functionality
## π Project Structure
```
.
βββ .github
β βββ workflows
β βββ build.yml
βββ include
β βββ board
β β βββ DEMIRv1
β β βββ hardware.h
β β βββ pins_DEMIRv1.h
β βββ com_def.h
β βββ conf.h
β βββ controller.h
β βββ encoder.h
β βββ Motion.h
β βββ motor.h
β βββ MotorDriver.h
β βββ PID.h
β βββ PLANNER.h
β βββ README
β βββ SerialParser.h
β βββ SerialSolver.h
β βββ vnh7070.h
βββ src
β βββ com_def.cpp
β βββ controller.cpp
β βββ encoder.cpp
β βββ main.cpp
β βββ Motion.cpp
β βββ motor.cpp
β βββ MotorDriver.cpp
β βββ PID.cpp
β βββ PLANNER.cpp
β βββ README
β βββ SerialParser.cpp
β βββ SerialSolver.cpp
β βββ vnh7070.cpp
βββ .clang-format
βββ .gitignore
βββ .travis.yml
βββ LICENSE
βββ platformio.ini
βββ README.md
```
## π οΈ Building and Installation
### Prerequisites
- Arduino IDE or Arduino CLI
- ATmega328P compatible board (Arduino UNO)
- C++14 compatible compiler
### Build Instructions
1. **Clone the repository**:
```bash
git clone https://github.com/dsm/demir_firmware.git
cd demir_firmware
```
2. **Using Arduino IDE**:
- Open `src/main.cpp` in Arduino IDE
- Select Arduino UNO board
- Upload to your device
3. **Using Arduino CLI**:
```bash
arduino-cli compile --fqbn arduino:avr:uno --build-property "compiler.cpp.extra_flags=-std=c++14"
arduino-cli upload --fqbn arduino:avr:uno --port /dev/ttyUSB0
```
## βοΈ Configuration
### Motor Settings
Configure motor parameters in `include/conf.h`:
```cpp
#define MOTORS 4 // Number of motors (1-4)
#define ENCODER_PPR 1024 // Pulses per revolution
#define MAX_VELOCITY 1000 // Maximum velocity (pulses/sec)
#define PID_KP 2.0 // Proportional gain
#define PID_KI 0.1 // Integral gain
#define PID_KD 0.05 // Derivative gain
```
### Communication Settings
- **Baud Rate**: 9600 (configurable)
- **Data Format**: 8N1
- **Flow Control**: None
## π‘ Command Protocol
### Basic Commands
- `M P` - Move motor to position
- `M V` - Set motor velocity
- `M S` - Stop motor
- `STATUS` - Get system status
- `RESET` - Emergency reset
### Example Usage
```
M1 P1000 # Move motor 1 to position 1000
M2 V500 # Set motor 2 velocity to 500
STATUS # Get current status
```
## π Monitoring and Debugging
### Status Information
The system provides real-time feedback including:
- Current position for each motor
- Target position
- Current velocity
- PID error values
- System status
### Debug Output
Enable debug mode in configuration for detailed logging:
```cpp
#define DEBUG_MODE 1
```
## π§ͺ Testing
### Unit Tests
Run automated tests using the GitHub Actions workflow:
- Compilation verification
- Code linting
- Memory usage analysis
### Manual Testing
1. Connect motors and encoders
2. Upload firmware
3. Use serial monitor for command testing
4. Verify position accuracy and response
## π€ Contributing
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## π Performance Metrics
- **Position Accuracy**: Β±1 encoder pulse
- **Response Time**: <10ms for position commands
- **Maximum Update Rate**: 1kHz control loop
- **Memory Usage**: ~26% of ATmega328P flash memory
## π§ Troubleshooting
### Common Issues
1. **Motor not moving**: Check power supply and wiring
2. **Position drift**: Verify encoder connections
3. **Communication errors**: Check baud rate and serial settings
4. **Compilation errors**: Ensure C++14 support is enabled
### Debug Steps
1. Enable debug output
2. Monitor serial communication
3. Check hardware connections
4. Verify configuration parameters
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## π¨βπ» Author
**[Muhammet ΕΓΌkrΓΌ Demir]** - Final Year Engineering Project
## π Acknowledgments
- Arduino community for excellent development tools
- VNH7070 documentation and support
- University advisors and project mentors
---
**Note**: This project is part of a final year engineering project and is actively under development. Features and documentation are continuously being improved.