-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit with project description and a basic working MPU6050 c…
…ode in raspberrypi-server.
- Loading branch information
1 parent
c513ec1
commit f8d17be
Showing
6 changed files
with
228 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,27 @@ | ||
Raspcopter | ||
Repository description | ||
========== | ||
|
||
Source code of my Quadcopter drone powered by a Raspberry Pi. | ||
This git repo contains three directories, all of them are related to the same project: A home-made quadcopter running a Raspberry Pi. | ||
|
||
* raspberrypi-server: This software, made in C++ is a flight controller intended to be run on the R-Pi, it basically do three things: | ||
- it collects the values from the accelerometer and gyroscope via i2c (magnetometer and barometer may be added later) | ||
- it filters these values via a Kallman or low-pass filter | ||
- it manages the motors speed via the Pololu Maestro board according to the above values | ||
- it communicates over wifi with one of the two clients below | ||
* android-client: The Android smartphone is a wifi hotspot with whom the R-Pi communicates. An app (in java) will also be made to provide a handy controller. | ||
* laptop-client: This client, written in C++ with Qt is intended to be a complete "ground station" with recorded logs and real-time informations on the quadcopter. The laptop will also connect to the Android smartphone to be on the same local network as the raspberry pi. | ||
|
||
## Used pieces | ||
* 4 Motors: [FC 28-22 Brushless Outrunner 1200kv](vhttp://www.hobbyking.com/hobbyking/store/uh_viewitem.asp?idproduct=5354) | ||
* 4 ESC(Electronic Speed Controllers): [Hobby King 20A ESC 3A UBEC](http://www.hobbyking.com/hobbyking/store/__15202__hobby_king_20a_esc_3a_ubec.html) flashed in a hacky way with [SimonK](http://www.rchacker.com/diy/simonk-esc-firmware-flashing) | ||
* 1 Propellers pack (two of each directions): [Slow Fly Electric Prop 1045SF (4 pc)]( http://www.hobbyking.com/hobbyking/store/__22446__Slow_Fly_Electric_Prop_1045SF_4_pc_.html) | ||
* 1 Frame: [Hobbyking X525 V3 Glass Fiber Quadcopter Frame 600mm](http://www.hobbyking.com/hobbyking/store/__22800__hobbyking_x525_v3_glass_fiber_quadcopter_frame_600mm.html) | ||
* 1 Battery: [Turnigy 2200mAh 3S 20C Lipo Pack](http://www.hobbyking.com/hobbyking/store/__8932__Turnigy_2200mAh_3S_20C_Lipo_Pack.html) | ||
* 1 Battery charger: [Turnigy 2S 3S Balance Charger. Direct 110/240v Input](http://www.hobbyking.com/hobbyking/store/uh_viewitem.asp?idproduct=8247) | ||
|
||
(the pieces above have been commanded at the same time from HobbyKing despit their non-professionalism... I waited this pack a month and a half) | ||
|
||
* An ESC/servos USB communication board: [Micro Maestro 6-Channel USB Servo Controller](http://www.pololu.com/catalog/product/1350) | ||
* A low battery alarm: [Lipo Battery alarm](http://www.ebay.fr/itm/2S-4S-7-4V-14-8V-RC-Lipo-Batterie-Tension-Faible-Testeur-Buzzer-Alarme-autonomie-/130732900168?pt=FR_YO_Jeux_RadioComRobots_VehiculesRadiocommandes&hash=item1e7049bf48) | ||
* Accelerometer and gyroscope: [MPU6050 board](http://www.ebay.fr/itm/MPU-6050-Module-3-Axis-Gyroscope-Accelerometer-Sensor-for-Arduino-DIY-/400487483979?pt=AU_B_I_Electrical_Test_Equipment&hash=item5d3eea0a4b#ht_3042wt_1166) | ||
* Connections: [Some cables used in the SimonK flashing process and in the MPU6050 communication](http://www.ebay.fr/itm/40-Cables-pour-BreadBoard-Femelle-Femele-Arduino-Femalle-Fils-jumper-Wire-/330902593748?pt=FR_YO_MaisonJardin_Bricolage_ElectroniqueComposants&hash=item4d0b54e0d4#ht_2467wt_1406) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* ==================================================================== | ||
* This file is part of Raspcopter. | ||
* | ||
* Copyright (C) 2013 - Florent Revest <florent.revest666@gmail.com> | ||
* Raspcopter is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Raspcopter is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Raspcopter. If not, see <http://www.gnu.org/licenses/>. | ||
* ================================================================== */ | ||
|
||
#include "Accelerometer.h" | ||
|
||
Accelerometer::Accelerometer() | ||
{ | ||
m_isConnected = true; | ||
m_i2cfd = open("/dev/i2c-1", O_RDWR); | ||
if(!m_i2cfd < 0) | ||
m_isConnected = false; | ||
if(ioctl(m_i2cfd, I2C_SLAVE, 0x68) < 0) | ||
m_isConnected = false; | ||
|
||
setRegisterValue(0x6B, 2, 3, 1); // Choose the XGYRO clock | ||
setRegisterValue(0x1B, 4, 2, 1); // Set gyroscopes range to 500 | ||
setRegisterValue(0x1C, 4, 2, 2); // Set accelerometer range to 8 | ||
setRegisterValue(0x6B, 6, 1, 0); // Disable Sleep Mode | ||
} | ||
|
||
Accelerometer::~Accelerometer() | ||
{ | ||
close(m_i2cfd); | ||
setRegisterValue(0x6B, 6, 1, 1); // Disable Sleep Mode | ||
} | ||
|
||
AccelGyroValues Accelerometer::getAccelGyroValues() | ||
{ | ||
AccelGyroValues values; | ||
uint8_t buffer[14]; | ||
getRegisterValue(0x3B, 14, buffer); | ||
|
||
values.ax = (((int16_t)buffer[0]) << 8) | buffer[1]; | ||
values.ay = (((int16_t)buffer[2]) << 8) | buffer[3]; | ||
values.az = (((int16_t)buffer[4]) << 8) | buffer[5]; | ||
values.gx = (((int16_t)buffer[8]) << 8) | buffer[9]; | ||
values.gy = (((int16_t)buffer[10]) << 8) | buffer[11]; | ||
values.gz = (((int16_t)buffer[12]) << 8) | buffer[13]; | ||
|
||
return values; | ||
} | ||
|
||
bool Accelerometer::isConnected() | ||
{ | ||
return m_isConnected; | ||
} | ||
|
||
// These two methods contain some code written by Jeff Rowberg for the I2Cdev" lib | ||
void Accelerometer::setRegisterValue(uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data) | ||
{ | ||
// Read the old value | ||
uint8_t value; | ||
getRegisterValue(regAddr, 1, &value); | ||
|
||
// Mix the new bits with the new ones | ||
uint8_t mask = ((1 << length) - 1) << (bitStart - length + 1); | ||
data <<= (bitStart - length + 1); | ||
data &= mask; | ||
value &= ~(mask); | ||
value |= data; | ||
|
||
// Write the new value to /dev/i2c-1 | ||
uint8_t buffer[2] = {regAddr, value}; // The first octet is the register adress, the second contains the data | ||
write(m_i2cfd, buffer, 2); | ||
} | ||
|
||
void Accelerometer::getRegisterValue(uint8_t regAddr, uint8_t length, uint8_t *data) | ||
{ | ||
if(write(m_i2cfd, ®Addr, 1) != 1) | ||
return; | ||
int8_t count = read(m_i2cfd, data, length); | ||
if (count < 0 || count != 1) | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* ==================================================================== | ||
* This file is part of Raspcopter. | ||
* | ||
* Copyright (C) 2013 - Florent Revest <florent.revest666@gmail.com> | ||
* Raspcopter is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Raspcopter is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Raspcopter. If not, see <http://www.gnu.org/licenses/>. | ||
* ================================================================== */ | ||
|
||
#ifndef _ACCELEROMETER_H_ | ||
#define _ACCELEROMETER_H_ | ||
|
||
#include <linux/i2c-dev.h> | ||
#include <sys/ioctl.h> | ||
#include <sys/types.h> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <stdint.h> | ||
|
||
typedef struct AccelGyroValues { | ||
int16_t ax; | ||
int16_t ay; | ||
int16_t az; | ||
int16_t gx; | ||
int16_t gy; | ||
int16_t gz; | ||
} AccelGyroValues; | ||
|
||
class Accelerometer | ||
{ | ||
public: | ||
Accelerometer(); | ||
~Accelerometer(); | ||
void setRegisterValue(uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data); | ||
void getRegisterValue(uint8_t regAddr, uint8_t length, uint8_t *data); | ||
AccelGyroValues getAccelGyroValues(); | ||
bool isConnected(); | ||
|
||
private: | ||
int m_i2cfd; | ||
bool m_isConnected; | ||
}; | ||
|
||
#endif // _ACCELEROMETER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CC=g++ | ||
CFLAGS=-c -Wall | ||
LDFLAGS= | ||
SOURCES=main.cpp Accelerometer.cpp | ||
OBJECTS=$(SOURCES:.cpp=.o) | ||
EXECUTABLE=server | ||
|
||
all: $(SOURCES) $(EXECUTABLE) | ||
|
||
$(EXECUTABLE): $(OBJECTS) | ||
$(CC) $(LDFLAGS) $(OBJECTS) -o $@ | ||
|
||
.cpp.o: | ||
$(CC) $(CFLAGS) $< -o $@ | ||
|
||
clean: | ||
rm -rf *.o server | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* ==================================================================== | ||
* This file is part of Raspcopter. | ||
* | ||
* Copyright (C) 2013 - Florent Revest <florent.revest666@gmail.com> | ||
* Raspcopter is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Raspcopter is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Raspcopter. If not, see <http://www.gnu.org/licenses/>. | ||
* ================================================================== */ | ||
|
||
#include <iostream> | ||
#include "Accelerometer.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
Accelerometer *accel= new Accelerometer(); // Initialize the MPU6050 | ||
if(accel->isConnected()) | ||
std::cout << "Accelerometer initialisation successful." << std::endl; | ||
else | ||
{ | ||
std::cout << "Accelerometer initialisation error... Abort" << std::endl; | ||
return 1; | ||
} | ||
|
||
while(1) | ||
{ | ||
AccelGyroValues values = accel->getAccelGyroValues(); | ||
std::cout << "accelerometer: " << values.ax << values.ay << values.az << std::endl | ||
<< "gyrometer: " << values.gx << values.gy << values.gz << std::endl; | ||
} | ||
return 0; | ||
} |