Skip to content

Commit

Permalink
main implementing
Browse files Browse the repository at this point in the history
  • Loading branch information
danlkv committed Jan 22, 2018
1 parent fb36811 commit 2c38e84
Show file tree
Hide file tree
Showing 20 changed files with 2,960 additions and 254 deletions.
1 change: 1 addition & 0 deletions ADXL345/Accel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../i2c/i2cmaster.h"
#include "../TWI/twimaster.h"
#include "../USART/USART.h"
#include <stdio.h>


#define WRITE 0
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRJ=motors
PRJ=main
SRC=$(PRJ).cpp

CFLAGS=-c -Wall
Expand Down
8 changes: 7 additions & 1 deletion Motors/Motors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ ISR(TIMER1_COMPB_vect){
}
else{
val +=OneMs+sped[idx]*(2000/256.0/256.);
UDR0 = val>>8;
char str[10];
USART uart;
sprintf(str,"%d,",sped[idx]);
uart.put_str(str);
//UDR0 = val>>8;
//UDR0 = sped[0]>>8;
//UDR0 = sped[0];

if(idx==0){
TCNT1H=0; // Reset Timer every 20ms
Expand Down
2 changes: 2 additions & 0 deletions Motors/Motors.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <avr/io.h>
#include <avr/delay.h>
#include <stdlib.h>
#include "../USART/USART.h"
#include <stdio.h>

extern "C" void TIMER1_COMPA_vect(void) __attribute__ ((signal));

Expand Down
Binary file modified Motors/Motors.o
Binary file not shown.
Binary file modified accel.elf
Binary file not shown.
514 changes: 363 additions & 151 deletions accel.hex

Large diffs are not rendered by default.

Binary file modified accel.o
Binary file not shown.
Binary file added capture.log
Binary file not shown.
18 changes: 18 additions & 0 deletions flash_log.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#make flash

rm ~/capture.log
echo "Now listening to /dev/ttyUSB0"
touch ~/capture.log
(stty 38400 cs8 -ixon; cat) < /dev/ttyUSB0 > ~/capture.log &
echo "Waiting for board to start..."
LCNT=100
ln=`wc -l < ~/capture.log`
echo "$ln Lines read"
while [ $ln -lt $LCNT ]
do
ln=$(wc -l < ~/capture.log)
echo "$ln Lines read"
sleep 1s
done
kst2 ~/capture.log -f -1 -n 505 -P P1 -y 1 -y 3 -y 4 -P P2 -y 2 -s1

69 changes: 69 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#define F_CPU 16000000L
#include "Motors/Motors.h"
#include "USART/USART.h"
#include "ADXL345/Accel.h"

#include <avr/delay.h>
#include <string.h>
#include <avr/io.h>
#include <stdio.h>

int main(void){
char raw[6];
float a[3];
unsigned int speed, _spped;
float roll, _roll,pitch,_pitch,mod,_mod;
float al = 0.1;
char strnum [8];
char str[10];
USART uart;
Accel acc;
acc.Enter_meas_mode();
Motors motors;
motors.ConfPins();

_delay_ms(1000);
motors.Calibrate();
DDRD |= (1<<DDD2);

while(1){
PORTD = 1<<2;
acc.GetAccels(a);
mod = sqrt(a[0]*a[0]+a[1]*a[1]+a[2]*a[2]);
roll = atan2(a[1], a[2]) * 180/3.14;
pitch = atan2(-a[0], sqrt(a[1]*a[1] + a[2]*a[2])) * 180/3.14;
mod = _mod*(1-al) +al*mod;
_mod = mod;
pitch = _pitch*(1-al) +al*pitch;
_pitch = pitch;
for (short i = 0;i<MCNT;i++){
speed = (0x3040-(int)(pitch*(0x5030/70)));
motors.SpeedsVals[i]=speed;
// UDR0 = motors.SpeedsVals[0]>>8;
}
sprintf(str,"%d,%d,%d,%d\n",speed/100,((int)(25*mod)),(int)(10*pitch),(int)(50*a[0]));
uart.put_str(str);

/*
itoa(speed,str,10);
uart.put_str(" speed:");
uart.put_str(str);
_delay_ms(2);
dtostrf(mod,6,4,str);
uart.put_str(" mod:");
uart.put_str(str);
dtostrf(roll,6,4,str);
uart.put_str(" roll:");
uart.put_str(str);
dtostrf(pitch,6,4,str);
uart.put_str(" pitch:");
uart.put_str(str);
uart.put_str("\n");
*/
PORTD = 0<<2;
_delay_ms(30);
}
}
Binary file added main.elf
Binary file not shown.
Loading

0 comments on commit 2c38e84

Please sign in to comment.