Skip to content

Commit

Permalink
delete println
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenagaraev committed May 17, 2017
1 parent 0355fe1 commit ee7bcc1
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 68 deletions.
1 change: 0 additions & 1 deletion code/Arduino/CommandsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

CommandsController::CommandsController()
{
servoController.init();
}

void CommandsController::handle(ConnectingDevice *device, String command)
Expand Down
38 changes: 18 additions & 20 deletions code/Arduino/CommandsEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@


enum ControllerEnum {
movementControllerID = '\001',
movementControllerID = '\001',
sensorsControllerID = '\002',
servoControllerID = '\003'
};

enum SensorsEnum {
distance_sensor_1 = '\001',
distance_sensor_2 = '\002',
distance_sensor_3 = '\003',
distance_sensor_4 = '\004',
distance_sensor_5 = '\005',
distance_sensor_all = '\006',

line_sensor_1 = '\007',
line_sensor_2 = '\008',
line_sensor_3 = '\009',
line_sensor_4 = '\010',
line_sensor_5 = '\011',
line_sensor_all = '\012'
distance_sensor = '\001', //get value from single distance senceor
distance_sensor_all = '\002', //get value from all distance senceors
line_sensor = '\003', //get value from single line senceor
line_sensor_all = '\004' //get value from all line senceors
};


Expand All @@ -32,16 +23,23 @@ enum MoveEnum {
stop = '\005', //stop
forward_speed = '\006', //move forward with established speed
forward_time = '\007', //move forward while established time
back_speed = '\008', //move back with established speed
track_set_speed = '\009' //choose track and set passed speed
back_speed = '\010', //move back with established speed
track_set_speed = '\011' //choose track and set passed speed
};

enum TrackDiraction {
forward_direction = true,
back_direction = false
forward_direction = true, //rotation of track in forward diration
back_direction = false //rotation of track in backword diration
};

enum TrackID {
left_track = 0,
right_track = 1
left_track = 0, //left track id
right_track = 1 //right track id
};

enum ServoCommands {
set_horizontal_angle = '\001', //set horizontal angle of servo
set_vertical_angle = '\002', //set vertical angle of servo
set_horiz_vertical_angles = '\003', //set horizontal and verticalse angles of servo
get_coodrinates = '\004', //get current angels of horizontal and vertical servos
};
1 change: 0 additions & 1 deletion code/Arduino/ConnectingDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ void ConnectingDevice::send(String data)

bool ConnectingDevice::isActive()
{
(*this).send("lol");
if ((*device).available()) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion code/Arduino/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Constants::Constants()
servo_horizontal_pin = 34;
servo_vertical_pin = 35;

commands_delimetr = '\255';
commands_delimetr = ';';
}


Expand Down
12 changes: 12 additions & 0 deletions code/Arduino/MainController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ int* MainController::parse_command(String command, int begin, char delimetr, int
arr[i] = command.substring(begin, delimetrPos).toInt();
begin = delimetrPos + 1;
command = command.substring(begin, command.length());
begin = 0;
}
}
return arr;
Expand All @@ -22,6 +23,17 @@ int MainController::parse_command(String command, int begin, int end) {
return command.substring(begin, end).toInt();
}


String MainController::intArrayToString(int* array, int size) {
String str = "";
for (int i = 0; i < size; i++) {
str += String(array[i]);
str += ";";
}
return str;
}


MainController::~MainController() {

}
2 changes: 2 additions & 0 deletions code/Arduino/MainController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ class MainController
MainController();
int* parse_command(String command, int begin, char delimetr, int paramsLength);
int parse_command(String command, int begin, int end);

String intArrayToString(int*, int);
~MainController();
};
4 changes: 3 additions & 1 deletion code/Arduino/MovementController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ void MovementController::exec(ConnectingDevice *device, String command) {
move_back(parse_command(command, 2, command.length()));
break;
case track_set_speed:
choose_track_set_speed(parse_command(command, 2, constants.commands_delimetr), 2);
choose_track_set_speed(parse_command(command, 2, constants.commands_delimetr, 2));
break;
default:
break;
}

}


Expand All @@ -67,6 +68,7 @@ void MovementController::move_forward(int speed, int time_ms) {
left_track_control(forward_direction, speed);
right_track_control(forward_direction, speed);
delay(time_ms);
stop_moving();
}

void MovementController::move_back() {
Expand Down
40 changes: 4 additions & 36 deletions code/Arduino/SensorsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,14 @@ SensorsController::SensorsController()
void SensorsController::exec(ConnectingDevice *device, String command) {
switch (command[1])
{
case distance_sensor_1:
device->send(String(getDistance(1)));
break;
case distance_sensor_2:
device->send(String(getDistance(2)));
break;
case distance_sensor_3:
device->send(String(getDistance(3)));
break;
case distance_sensor_4:
device->send(String(getDistance(4)));
break;
case distance_sensor_5:
device->send(String(getDistance(5)));
case distance_sensor:
device->send(String(getDistance(parse_command(command, 2, command.length()))));
break;
case distance_sensor_all:
device->send(intArrayToString(getDistanceAll(), countDistanceSensors));
break;
case line_sensor_1:
device->send(String(getLine(1)));
break;
case line_sensor_2:
device->send(String(getLine(2)));
break;
case line_sensor_3:
device->send(String(getLine(3)));
break;
case line_sensor_4:
device->send(String(getLine(4)));
break;
case line_sensor_5:
device->send(String(getLine(5)));
case line_sensor:
device->send(String(getLine(parse_command(command, 2, command.length()))));
break;
case line_sensor_all:
device->send(intArrayToString(getLineAll(), countLineSensors));
Expand All @@ -66,14 +42,6 @@ void SensorsController::exec(ConnectingDevice *device, String command) {
}
}

String SensorsController::intArrayToString(int* array, int size) {
String str = "";
for (int i = 0; i < size; i++) {
str += String(array[i]);
}
return str;
}

void SensorsController::chooseLineSensor(int number) {
switch (number) {
case 1:
Expand Down
1 change: 0 additions & 1 deletion code/Arduino/SensorsController.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class SensorsController: public MainController
int getLine(int);
int* getLineAll();

String intArrayToString(int*, int);
~SensorsController();
};

38 changes: 35 additions & 3 deletions code/Arduino/ServoController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,57 @@ ServoController::ServoController()
void ServoController::init() {
horizontalServo.attach(constants.servo_horizontal_pin);
verticalServo.attach(constants.servo_vertical_pin);
horizontalServo.write(0);
verticalServo.write(0);
}

void ServoController::exec(ConnectingDevice* device, String command) {

switch (command[1])
{
case set_horizontal_angle:
setHorizontalAngle(parse_command(command, 2, command.length()));
break;
case set_vertical_angle:
setVerticalAngle(parse_command(command, 2, command.length()));
break;
case set_horiz_vertical_angles:
setHorizontalAndVerticalAngle(parse_command(command, 2, constants.commands_delimetr, 2));
break;
case get_coodrinates:
device->send(intArrayToString(getCoordinates(), 2));
break;
default:
break;
}
}

void ServoController::setHorizontalAngle(int angle) {

horizontalServo.write(angle);
delay(20);
}

void ServoController::setVerticalAngle(int angle) {
verticalServo.write(angle);
delay(20);
}

void ServoController::setHorizontalAndVerticalAngle(int angleX, int angleY) {
horizontalServo.write(angleX);
verticalServo.write(angleY);
delay(20);
}

int* ServoController::getCoordinates() {
int* arr = new int[2];
arr[0] = getHorizontalAngel();
arr[1] = getVerticalAngel();
return arr;
}

void ServoController::setHorizontalAndVerticalAngle(int* arr) {
horizontalServo.write(arr[0]);
verticalServo.write(arr[1]);
delay(200);
}

int ServoController::getHorizontalAngel() {
Expand All @@ -38,7 +71,6 @@ int ServoController::getVerticalAngel() {
return verticalServo.read();
}


ServoController::~ServoController()
{
}
5 changes: 4 additions & 1 deletion code/Arduino/ServoController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#include <Servo.h>
#include "Constants.h"
#include "ConnectingDevice.h"
#include "MainController.h"

class ServoController
class ServoController : public MainController
{
private:
Servo horizontalServo;
Expand All @@ -17,8 +18,10 @@ class ServoController
void setHorizontalAngle(int angle);
void setVerticalAngle(int angle);
void setHorizontalAndVerticalAngle(int angleX, int angleY);
void setHorizontalAndVerticalAngle(int* arr);
int getHorizontalAngel();
int getVerticalAngel();
int* getCoordinates();
~ServoController();
};

15 changes: 12 additions & 3 deletions code/Arduino/trackPlatform.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
#include "WiFi.h"
#include "SoftwareSerial.h"
#include "CommandsController.h"
#include "ServoController.h"

Constants constants;
Bluetooth bluetooth(constants.bluetooth_RX, constants.bluetooth_TX, constants.bluetooth_serial_speed);
WiFi wifi(constants.wifi_RX, constants.wifi_TX, constants.wifi_serial_speed);
ConnectingDevice *device;
CommandsController controller;
ServoController servoController;

bool connected = false;

void setup()
{
servoController.init();

while (!connected) {
if (bluetooth.isActive()) {
connected = true;
Expand All @@ -28,7 +32,12 @@ void setup()
}

void loop()
{
delay(90); //for sending commands from mobile
controller.handle(device, device->read());
{
delay(100); //for sending commands from mobile
String command = device->read();
if (command[0] == servoControllerID) {
servoController.exec(device, command);
} else {
controller.handle(device, device->read());
}
}

0 comments on commit ee7bcc1

Please sign in to comment.