Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ru racing2019 #1

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
24e4e0e
update
orlygur Apr 29, 2019
56404f6
Kóði fyrir teensyborðin á datalogger WIP bætt við
orlygur Apr 29, 2019
02f290c
code cleanup
orlygur Apr 29, 2019
d190e85
Reyna finna villu, recv -> always false
orlygur Apr 29, 2019
4157546
sends between works !
orlygur Apr 30, 2019
0573266
test
Kristbjorg16 Apr 30, 2019
310a5c1
cleanup
orlygur Apr 30, 2019
88dd6d0
Merge branch 'RURacing2019' of https://github.com/TeamSleipnir2019-20…
orlygur Apr 30, 2019
eec3500
cleanup
orlygur Apr 30, 2019
e05145a
fixing radio to work with strings
orlygur Apr 30, 2019
441044f
quick fix
orlygur Apr 30, 2019
5915c02
code cleanup
orlygur May 1, 2019
0706c77
smá lagfæringar
orlygur May 2, 2019
83f7fde
bætti vid fyrir rpi
Kristbjorg16 May 2, 2019
bd6c609
smá lagfæring
orlygur May 3, 2019
65e1aa9
removing xBee and replacing it with LoRa commands. Still needs send a…
orlygur May 3, 2019
adf294c
fixing for LoRa
orlygur May 3, 2019
5d7053d
baetti vid gps koda
hregggi May 3, 2019
bc5d5ab
breytti analog fyrir fjodrun
hregggi May 5, 2019
a9032ea
cleanup
orlygur May 5, 2019
3fd61a6
Merge branch 'RURacing2019' of https://github.com/TeamSleipnir2019-20…
orlygur May 5, 2019
740de4e
gps er in and functional!
orlygur May 5, 2019
e5ba1c0
gsp works !
orlygur May 6, 2019
f54587b
can now cpy/pst and run.
orlygur May 6, 2019
72eea79
laga output skrá
orlygur May 6, 2019
eaf403c
dikk move, vil fá fleiri línur code commited
orlygur May 6, 2019
0a98a45
IMU
Kristbjorg16 May 6, 2019
d31d939
fra i gaer
orlygur May 7, 2019
4d33a5a
Merge branch 'RURacing2019' of https://github.com/TeamSleipnir2019-20…
orlygur May 7, 2019
215c4f4
Commenta koða og gera hann lesanlegri / fallegri
orlygur May 7, 2019
f7a0ff8
comment and beatify
orlygur May 7, 2019
71dfe0a
rdy for test
orlygur May 7, 2019
4510874
Breytingar a can
Kristbjorg16 May 7, 2019
010fd7f
fjdsaklfæa
orlygur May 7, 2019
48683b3
Merge branch 'RURacing2019' of https://github.com/TeamSleipnir2019-20…
orlygur May 7, 2019
b3e8eae
added simple can bus testfiles
hregggi May 8, 2019
e313231
stuff
orlygur May 8, 2019
fde1ee6
Merge branch 'RURacing2019' of https://github.com/TeamSleipnir2019-20…
orlygur May 8, 2019
c45163f
asfd
orlygur May 8, 2019
e4ca6d5
skrifar gps út í sd kort, laga smá fyrir lcd (nyja logoid) og slikt.
orlygur May 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions CANsimulator/CANTestRec/CANTestRec.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// -------------------------------------------------------------
// CANtest for Teensy 3.6 dual CAN bus
// by Collin Kidder, Based on CANTest by Pawelsky (based on CANtest by teachop)
//
// Both buses are left at default 250k speed and the second bus sends frames to the first
// to do this properly you should have the two buses linked together. This sketch
// also assumes that you need to set enable pins active. Comment out if not using
// enable pins or set them to your correct pins.
//
// This sketch tests both buses as well as interrupt driven Rx and Tx. There are only
// two Tx buffers by default so sending 5 at a time forces the interrupt driven system
// to buffer the final three and send them via interrupts. All the while all Rx frames
// are internally saved to a software buffer by the interrupt handler.
//

#include <FlexCAN.h>

static uint8_t hex[17] = "0123456789abcdef";

// -------------------------------------------------------------
static void hexDump(uint8_t dumpLen, uint8_t *bytePtr)
{
uint8_t working;
while (dumpLen--)
{
working = *bytePtr++;
Serial.write(hex[working >> 4]);
Serial.write(hex[working & 15]);
}
Serial.write('\r');
Serial.write('\n');
}

// -------------------------------------------------------------
void setup(void)
{
// mask.flags.extended = 0;
// mask.flags.remote = 0;
mask.ext = 0;
mask.rtr = 0;
mask.id = 0;

delay(1000);
Serial.begin(9600);
Serial.println("Hello Teensy CAN Recieve Test.");

Can0.begin(500000);
}

// -------------------------------------------------------------
void loop(void)
{
CAN_message_t inMsg;
while (Can0.available())
{
Can0.read(inMsg);
Serial.print("CAN bus 0: ");
hexDump(8, inMsg.buf);
}
delay(20);
Serial.println("Im in a recieving loop.");
}
64 changes: 64 additions & 0 deletions CANsimulator/CANTestSend/CANTestSend.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// -------------------------------------------------------------
// CANtest for Teensy 3.6 dual CAN bus
// by Collin Kidder, Based on CANTest by Pawelsky (based on CANtest by teachop)
//
// Both buses are left at default 250k speed and the second bus sends frames to the first
// to do this properly you should have the two buses linked together. This sketch
// also assumes that you need to set enable pins active. Comment out if not using
// enable pins or set them to your correct pins.
//
// This sketch tests both buses as well as interrupt driven Rx and Tx. There are only
// two Tx buffers by default so sending 5 at a time forces the interrupt driven system
// to buffer the final three and send them via interrupts. All the while all Rx frames
// are internally saved to a software buffer by the interrupt handler.
//

#include <FlexCAN.h>


static CAN_message_t msg;
static uint8_t hex[17] = "0123456789abcdef";


// -------------------------------------------------------------
void setup(void)
{
delay(1000);
Serial.begin(9600);
Serial.println("Hello Teensy CAN Send Test.");

Can0.begin(500000);

msg.ext = 0;
msg.id = 0x100;
msg.len = 8;
msg.buf[0] = 10;
msg.buf[1] = 20;
msg.buf[2] = 0;
msg.buf[3] = 100;
msg.buf[4] = 128;
msg.buf[5] = 64;
msg.buf[6] = 32;
msg.buf[7] = 16;
}


// -------------------------------------------------------------
void loop(void)
{

msg.buf[0]++;
Can0.write(msg);
msg.buf[0]++;
Can0.write(msg);
msg.buf[0]++;
Can0.write(msg);
msg.buf[0]++;
Can0.write(msg);
msg.buf[0]++;
Can0.write(msg);


delay(20);
Serial.println("Im in a sending loop.");
}
97 changes: 60 additions & 37 deletions CANsimulator/CANsimulator.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,73 +18,94 @@ const uint16_t MAX_RPM = 14000;
static CAN_message_t msg1;
static CAN_message_t msg2;

void demo() {
if (reverse) {
if (rpm != 0) {
void demo()
{
if (reverse)
{
if (rpm != 0)
{
rpm -= 25;
Serial.print("RPM : ");
Serial.println(rpm);
}
else {
else
{
oilTemp = random(4730, 4830);
waterTemp = random(4030, 4230);
brakeTemp = random(3730, 4230);
voltage = random(11900, 12900);

if (gear > 0) {
if (gear > 0)
{
gear--;
rpm = 9000;
}
else {
else
{
rpm = 0;
speed = 0;
}
}
}
else {
if (rpm != MAX_RPM) {
else
{
if (rpm != MAX_RPM)
{
rpm += 25;
}
else {
else
{
oilTemp = random(4730, 4830);
waterTemp = random(4030, 4230);
brakeTemp = random(3730, 4230);
voltage = random(11900, 12900);

if (gear < 6) {
if (gear < 6)
{
gear++;
rpm = 2000;
}
else {
else
{
rpm = 13500;
}
}
}

if (reverse) {
if (speed > 0) {
if (speedCount == 15) {
if (reverse)
{
if (speed > 0)
{
if (speedCount == 15)
{
speed--;
speedCount = 0;
}
else {
else
{
speedCount++;
}
}
}
else {
if (speed < 200 && gear != 0) {
if (speedCount == 15) {
else
{
if (speed < 200 && gear != 0)
{
if (speedCount == 15)
{
speed++;
speedCount = 0;
}
else {
else
{
speedCount++;
}
}
}
}

void setup() {

void setup()
{
// Initialize the CAN bus
Can0.begin(500000);
Serial.begin(9600);
Expand All @@ -100,20 +121,20 @@ void setup() {
// CAN message headers
msg1.id = 0x1;
msg1.len = 8;
msg1.flags.extended = 0;
msg1.flags.remote = 0;
//msg1.flags.extended = 0;
//msg1.flags.remote = 0;

msg2.id = 0x2;
msg2.len = 8;
msg2.flags.extended = 0;
msg2.flags.remote = 0;

//msg2.flags.extended = 0;
//msg2.flags.remote = 0;
msg2.ext = 0;
msg2.rtr = 0;
}

void loop() {

void loop()
{
demo();

// CAN message 1 payload
msg1.buf[0] = (uint8_t)rpm;
msg1.buf[1] = rpm >> 8;
Expand All @@ -124,8 +145,8 @@ void loop() {
msg1.buf[6] = (uint8_t)speed;
msg1.buf[7] = 0;

while (!Can0.write(msg1, Can0.getFirstTxBox())) {
}
//while (!Can0.write(msg1, Can0.getFirstTxBox())) {}
Can0.write(msg1, Can0.getFirstTxBox());

// CAN message 2 payload
msg2.buf[0] = (uint8_t)oilTemp;
Expand All @@ -136,14 +157,16 @@ void loop() {
msg2.buf[5] = waterTemp >> 8;
msg2.buf[6] = speed;
msg2.buf[7] = speed >> 8;

while (!Can0.write(msg2, Can0.getLastTxBox())) {
}

if (gear == 6 && rpm == 14000) {
//while (!Can0.write(msg2, Can0.getLastTxBox())){}
Can0.write(msg2, Can0.getLastTxBox());

if (gear == 6 && rpm == 14000)
{
reverse = true;
}
if (reverse && gear == 0 && rpm == 0) {
if (reverse && gear == 0 && rpm == 0)
{
reverse = false;
}

Expand Down
12 changes: 8 additions & 4 deletions ClassLibrary/CanListener.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#include "CanListener.h"

inline float CanListener::CANIntToFloat(uint16_t floatValue) {
inline float CanListener::CANIntToFloat(uint16_t floatValue)
{
return floatValue / 1000.0;
}

inline float CanListener::CANKelvinToFloat(uint16_t kelvinValue) {
inline float CanListener::CANKelvinToFloat(uint16_t kelvinValue)
{
float result = kelvinValue / 10.0;
result = result - 273.15;

return result;
}

bool CanListener::frameHandler(CAN_message_t &frame, int mailbox, uint8_t controller) {
bool CanListener::frameHandler(CAN_message_t &frame, int mailbox, uint8_t controller)
{

switch (frame.id) {
switch (frame.id)
{
case 1:
vehicle.rpm = frame.buf[0] | (frame.buf[1] << 8);
vehicle.voltage = CANIntToFloat(frame.buf[2] | (frame.buf[3] << 8));
Expand Down
3 changes: 2 additions & 1 deletion ClassLibrary/CanListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#include "Vehicle.h"
#include <FlexCAN.h>

class CanListener : public CANListener {
class CanListener : public CANListener
{
public:
// Vehicle class instance
Vehicle vehicle;
Expand Down
4 changes: 2 additions & 2 deletions ClassLibrary/Vehicle.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Vehicle.h"

Vehicle::Vehicle() {
Vehicle::Vehicle()
{
// Initialize car values
rpm = 0;
prevRPM = 1;
Expand Down Expand Up @@ -34,5 +35,4 @@ Vehicle::Vehicle() {
prevCylcontrib4 = 1;
}


Vehicle::~Vehicle() {}
Loading