Skip to content

Commit

Permalink
Merge pull request #6 from oroca/develop
Browse files Browse the repository at this point in the history
merge from develop
  • Loading branch information
hancheol-cho authored Feb 6, 2019
2 parents e2f4c4b + 24c2f58 commit 3be38d7
Show file tree
Hide file tree
Showing 77 changed files with 11,454 additions and 2,703 deletions.
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"files.associations": {
"initializer_list": "cpp",
"list": "cpp",
"vector": "cpp",
"xhash": "cpp",
"xstring": "cpp",
"xutility": "cpp"
}
}
92 changes: 92 additions & 0 deletions examples/Floor/LineTrace/LineTrace.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include <EduBot.h>


EduBot edubot;

int step_speed = 90;

void setup() {
// put your setup code here, to run once:

edubot.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly
int x = 0;
int y = 0;
int sen[4];
static uint8_t mode = 0;
static int line_pos = 0;


edubot.lcd.clearDisplay();


sen[0] = edubot.floor_sensor.getRightOut();
sen[1] = edubot.floor_sensor.getRightIn();
sen[2] = edubot.floor_sensor.getLeftIn();
sen[3] = edubot.floor_sensor.getLeftOut();


if (mode == 0)
{
edubot.lcd.printf(0, 16*0, "%d", sen[0]);
edubot.lcd.printf(0, 16*1, "%d", sen[1]);
edubot.lcd.printf(0, 16*2, "%d", sen[2]);
edubot.lcd.printf(0, 16*3, "%d", sen[3]);
}
else if (mode == 1)
{
for (int i=0; i<4; i++)
{
sen[i] = map(sen[i], 0, 255, 1, 60);
edubot.lcd.fillRect(11 + 32*i, 64-sen[i], 10, sen[i], WHITE);
}

line_pos = (sen[1]-sen[2])/1;

edubot.lcd.fillRect(64- 5 + line_pos, 4, 10, 4, WHITE);


int left_speed;
int right_speed;

left_speed = step_speed - line_pos*2;
right_speed = step_speed + line_pos*2;

if ( sen[1] < 2 && sen[2] < 2)
{
left_speed = 0;
right_speed = 0;
}

edubot.led.leftBright(0, sen[2], 0);
edubot.led.rightBright(0, sen[1], 0);

if (edubot.tof_L.distance_mm < 60 || edubot.tof_R.distance_mm < 80)
{
left_speed = 0;
right_speed = 0;
}
edubot.motor.setSpeed(left_speed, right_speed);

}
else
{
edubot.motor.setSpeed(0, 0);
edubot.lcd.printf(0, 0 , "L %d mm", edubot.tof_L.distance_mm);
edubot.lcd.printf(0, 16, "R %d mm", edubot.tof_R.distance_mm);
}
edubot.lcd.display();

delay(1);

if (edubot.buttonGetPressed() == true)
{
while(edubot.buttonGetPressed() == true);

mode++;
mode %= 3;
}
}
67 changes: 67 additions & 0 deletions examples/Floor/readFloor/readFloor.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <EduBot.h>


EduBot edubot;



void setup() {
// put your setup code here, to run once:

edubot.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly
int x = 0;
int y = 0;
int sen[4];
static uint8_t mode = 0;



edubot.lcd.clearDisplay();


sen[0] = edubot.floor_sensor.getRightOut();
sen[1] = edubot.floor_sensor.getRightIn();
sen[2] = edubot.floor_sensor.getLeftIn();
sen[3] = edubot.floor_sensor.getLeftOut();


if (mode == 0)
{
edubot.lcd.printf(0, 16*0, "%d", sen[0]);
edubot.lcd.printf(0, 16*1, "%d", sen[1]);
edubot.lcd.printf(0, 16*2, "%d", sen[2]);
edubot.lcd.printf(0, 16*3, "%d", sen[3]);
}
else if (mode == 1)
{
for (int i=0; i<4; i++)
{
sen[i] = map(sen[i], 0, 255, 1, 60);
edubot.lcd.fillRect(32*i, 64-sen[i], 10, sen[i], WHITE);
}
edubot.lcd.fillRect(64- 5 + (sen[1]-sen[2])/1, 4, 10, 4, WHITE);
}
else
{
edubot.lcd.printf(0, 0 , "L %d mm", edubot.tof_L.distance_mm);
edubot.lcd.printf(0, 16, "R %d mm", edubot.tof_R.distance_mm);
}
edubot.lcd.display();

delay(50);

if (edubot.buttonGetPressed() == true)
{
while(edubot.buttonGetPressed() == true);

mode++;
mode %= 2;
}
Serial.print(edubot.tof_L.distance_mm);
Serial.print(" ");
Serial.println(edubot.tof_R.distance_mm);
}
29 changes: 25 additions & 4 deletions examples/NeoPixel/LedFade/LedFade.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,34 @@ void setup() {
// put your setup code here, to run once:

edubot.begin(115200);

}

void loop() {
// put your main code here, to run repeatedly
static uint8_t led_bright = 0;
static int led_dir = 1;
static int led_dir = 1;
static int led_index = 0;


if (led_index == 0)
{
edubot.led.leftBright(led_bright, 0, 0);
edubot.led.rightBright(led_bright, 0, 0);
}
else if(led_index == 1)
{
edubot.led.leftBright(0, led_bright, 0);
edubot.led.rightBright(0, led_bright, 0);
}
else
{
edubot.led.leftBright(0, 0, led_bright);
edubot.led.rightBright(0, 0, led_bright);
}


edubot.led.leftBright(led_bright, 0, 0);
edubot.led.rightBright(0, 0, led_bright);

led_bright += led_dir;

if (led_bright == 255)
Expand All @@ -27,6 +46,8 @@ void loop() {
if (led_bright == 0)
{
led_dir = 1;
led_index++;
led_index %= 3;
}
delay(2);
}
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=OROCA-EduBot
version=0.0.3
version=0.0.4
author=OROCA
license=Apache-2.0
maintainer=Baram([email protected])
Expand Down
54 changes: 45 additions & 9 deletions src/EduBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@




void taskUpdate( void *pvParameters );

void taskUpdate(void *pvParameters)
Expand All @@ -24,7 +25,6 @@ void taskUpdate(void *pvParameters)
}
}


EduBot::EduBot(void)
{
}
Expand Down Expand Up @@ -55,36 +55,44 @@ bool EduBot::begin(int baud)
// for Unser Button
pinMode(0, INPUT_PULLUP);

adcInfoInit();
adcInfoEnable(VBAT);

ret = lcd.begin();

lcd.println(EDUBOT_VER_STR);

ret = printInitLog("Audio Init", audio.begin());
ret = printInitLog("IR Remote Init", ir_remote.begin());
ret = printInitLog("IMU Init", imu.begin());
ret = printInitLog("Motor Init", motor.begin());
ret = printInitLog("Motor Init", motor.begin());
ret = printInitLog("LED Init", led.begin());

floor_sensor.begin();

pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);

digitalWrite(D6, HIGH);
digitalWrite(D7, LOW);

digitalWrite(D6, LOW);
digitalWrite(D7, HIGH);
delay(10);

ret = printInitLog("TOF R Init", tof_R.begin());
ret = printInitLog("TOF L Init", tof_L.begin());
if (ret == true)
{
tof_R.setAddress(0x01);
tof_L.setAddress(0x10);
}


digitalWrite(D6, HIGH);
digitalWrite(D7, HIGH);
delay(10);

ret = printInitLog("TOF L Init", tof_L.begin());
ret = printInitLog("TOF R Init", tof_R.begin());
if (ret == true)
{
tof_L.setAddress(0x02);
//tof_L.setAddress(0x02);
}

lcd.display();
Expand All @@ -103,6 +111,9 @@ bool EduBot::begin(int baud)
, 1 // Priority
, NULL
, 1);


//ble.begin("OROCA EduBot");

return true;
}
Expand Down Expand Up @@ -150,9 +161,11 @@ bool EduBot::update(void)
imu.update();
}
tof_L.update();
tof_R.update();
tof_R.update();
}

adcInfoUpdate();

return true;
}

Expand All @@ -169,4 +182,27 @@ void EduBot::ledOff(void)
void EduBot::ledToggle(void)
{
digitalWrite(13, !digitalRead(13));
}

bool EduBot::buttonGetPressed(void)
{
if (digitalRead(0) == 0)
{
return true;
}
else
{
return false;
}
}

uint8_t EduBot::batteryGetVoltage(void)
{
uint16_t value;

value = adcInfoReadRaw(VBAT);

value = 72 * value / 4095; // 3.6V * x / 4095

return value;
}
12 changes: 11 additions & 1 deletion src/EduBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
#include "./driver/hangul/PHan_Lib.h"
#include "./driver/vl53l0x/VL53L0X.h"
#include "./driver/ir_remote/ir_remote.h"

#include "./driver/ble/ble.h"
#include "./driver/neopixel/neopixel.h"
#include "./driver/adc_info/adc_info.h"
#include "./driver/floor/floor.h"


#define EDUBOT_VER_STR "EduBot V190201R1"
#define EDUBOT_VER_STR "EduBot V190201R2"

#define EDUBOT_OK 0
#define EDUBOT_ERR_INIT_IMU 1
Expand All @@ -45,16 +49,22 @@ class EduBot
// for Extention Board
IrRemote ir_remote;
OLed lcd;
BLE ble;
NeoPixel led;
VL53L0X tof_L;
VL53L0X tof_R;
Floor floor_sensor;

bool begin(int baud);
bool update(void);

void ledOn(void);
void ledOff(void);
void ledToggle(void);

bool buttonGetPressed(void);
uint8_t batteryGetVoltage(void);

private:
bool printInitLog(const char *str_msg, bool ret);

Expand Down
Loading

0 comments on commit 3be38d7

Please sign in to comment.