Embedded Systems projects of Robotics Engineering at the University of Genoa.
The buggy used is a Mikroe Buggy.
All the code was developed in MPLAB X IDE v6.20 using XC16 Compiler. The bootloader used is mikroBootloader USB HID while for serial communication HTERM.
- Simulate an algorithm that needs 7 ms for its execution, and needs to work at 100 Hz. This is to emulate a real world scenario.
- Acquire the three magnetometer axes at 25 Hz (set the data rate to 0b110 in the 0x4C register).
- Do the average of the last 5 measurements.
- Send it to the UART at 5 Hz using the protocol
$MAG,x,y,z*, where x is the average value on the x-axis, y is the average value of the y-axis, and z is the average z-axis value. - Compute the angle to the magnetic North using atan2(y avg,x avg).
- Send the computed angle at 5 Hz using the message
$YAW,x*, where x is the angle in degrees.
This project implements a basic control system for an autonomous ground vehicle (buggy). The firmware is responsible for processing movement commands, controlling motors, handling obstacle detection, and monitoring the battery.
-
Runs at 1 kHz frequency.
-
Controls motors and reads the IR sensor at 1 kHz.
-
Starts in "Wait for Start" mode:
- Motors are off.
- LED A0 and indicators blink at 1 Hz.
-
Transition to "Execute" Mode:
- Pressing button RE8 moves the system to "Execute" mode.
- The buggy processes movement commands received via UART.
Commands follow the format:
$PCCMD,x,t*
Where:
x= Motion type- 1 → Forward motion
- 2 → Counterclockwise rotation
- 3 → Clockwise rotation
- 4 → Backward motion
t= Duration (milliseconds)
The system stores commands in a FIFO queue (max 10 commands).
If the queue is full, it sends an error message:
$MACK,0*
If no commands are available, the buggy remains in the "Execute" state but stops moving.
Uses four PWM signals (10 kHz) for motor control. Pin assignments:
| Motion | Pin | Signal |
|---|---|---|
| Left wheels forward | RD2 | left_pwm > 0 |
| Left wheels backward | RD1 | left_pwm < 0 |
| Right wheels forward | RD4 | right_pwm > 0 |
| Right wheels backward | RD3 | right_pwm < 0 |
- IR sensor prevents the buggy from getting closer than 20 cm to obstacles.
- Located on Mikrobus 1 or 2 (front of buggy).
- Uses AN14/AN15 for reading and RB9/RA3 for enabling.
- Battery voltage is read from AN11.
- Uses a voltage divider (200kΩ + 100kΩ resistors).
-
Command Interface & Data Logging via UART → RS232.
-
The microcontroller sends the following data:
-
Battery voltage (1 Hz):
$MBATT,v_batt* -
Distance sensor reading (10 Hz):
$MDIST,distance* -
Uses RD0 (TX) and RD11 (RX).
| Function | Pin |
|---|---|
| Left-side lights | RB8 |
| Right-side lights | RF1 |
| Brakes | RF0 |
| Low-intensity lights | RG1 |
| Beam headlights | RA7 |
| Battery sensing | AN11 |
| Left PWM (backward) | RD1 |
| Left PWM (forward) | RD2 |
| Right PWM (backward) | RD3 |
| Right PWM (forward) | RD4 |
| IR sensor voltage | AN14/AN15 |
| IR sensor enable | RB9/RA3 |
| UART TX | RD0 |
| UART RX | RD11 |
