Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ doc.fls
doc.log
doc.out
.DS_Store

__pychache__
.pyc
Empty file added code/arduino/lidar/README.md
Empty file.
12 changes: 12 additions & 0 deletions code/arduino/lidar/lidar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "lidar.h"

Lidar::Lidar(): { }

Lidar::get_distance_cm(float volts) {
measured_value = (0,008271 + 939,6*volts)/(1 - 3,398*volts + 17,339*volts^2);
return measured_value;
}

Lidar::get_pin() {
return analog_pin;
}
15 changes: 15 additions & 0 deletions code/arduino/lidar/lidar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef LIDAR_H
#define LIDAR_H

#include <Arduino.h>

class Lidar {
public:
Lidar();
static float get_distance_cm(float volts);

private:
static const int analog_pin = 0;
};

#endif
26 changes: 26 additions & 0 deletions code/arduino/lidar/lidar.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <Wire.h>
#include "lidar.h"

const byte SLAVE_ADDRESS = 0x07;

Lidar lidar();

void setup() {
Serial.begin(9600);

Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receive_i2c_data);
Wire.onRequest(send_i2c_data);
}

void loop() {
analogRead(lidar.get_pin());
lidar.get_distance_cm(measured_value);
delay(60)
}

void receive_i2c_data(int byteCount) {
}

void send_i2c_data() {
}
21 changes: 21 additions & 0 deletions code/raspberrypi/lidar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from i2c import I2C
from enum import IntEnum

class Command(IntEnum):
Measure = 1
Start = 2
Stop = 3

class Lidar(I2C):
def __init__(self, address):
super(Lidar, self).__init__(address)

def measure(self):
self.send(Command.Measure)
return self.receive()

def start(self):
self.send(Command.Start)

def stop(self):
self.send(Command.Stop)