Plane | Functioning Plane Output Simulator [Research]

So here are all 3 prongs of the plane code thus far. This sends data to the visual basic program, then to the visual basic program where it gets interpreted and then sent to the plane simulator Arduino. Where it is written to servos and and led.

Arduino Controller:

//Mux control pins</pre>
int s0 = 8;
int s1 = 9;
int s2 = 10;
int s3 = 11;
int SIG_pin = 0;

//Shift Register Pins
int SER_Pin = 5; //pin 14 on the 75HC595
int RCLK_Pin = 6; //pin 12 on the 75HC595
int SRCLK_Pin = 7; //pin 11 on the 75HC595
#define number_of_74hc595s 1 //How many of the shift registers - change this
#define numOfRegisterPins number_of_74hc595s * 8 //do not touch
boolean registers[numOfRegisterPins];

//other pin setup
int joystick_x;
int joystick_y;
int pot_1;

int debug_switch = 4;

void setup(){
 //mux setup
 pinMode(s0, OUTPUT);
 pinMode(s1, OUTPUT);
 pinMode(s2, OUTPUT);
 pinMode(s3, OUTPUT);
 digitalWrite(s0, LOW);
 digitalWrite(s1, LOW);
 digitalWrite(s2, LOW);
 digitalWrite(s3, LOW);

 //shift register setup
 pinMode(SER_Pin, OUTPUT);
 pinMode(RCLK_Pin, OUTPUT);
 pinMode(SRCLK_Pin, OUTPUT);
 pinMode(0, INPUT);
 clearRegisters();
 writeRegisters();

 //other pin setup
 pinMode(debug_switch, INPUT);

 Serial.begin(9600);
}
void loop(){ //start of main loop -------------------------------------------
 delay(25);
 pin_remap();

 if (digitalRead(debug_switch) == HIGH){
 serial_output_debug();
 setRegisterPin(1, HIGH);
 setRegisterPin(2, LOW);
 writeRegisters();
 }

 if (digitalRead(debug_switch) == LOW){
 serial_output();
 setRegisterPin(2, HIGH);
 setRegisterPin(1, LOW);
 writeRegisters();
 }

} //end of main loop --------------------------------------------------------
 //start of logic functions ------------------------------------------------
void serial_output(){
 Serial.print(joystick_x);
 Serial.print(" ");
 Serial.print(joystick_y);
 Serial.print(" ");
 Serial.print(pot_1);

 Serial.println("");
}

void serial_output_debug(){
 Serial.print("Joystick X Axis: ");
 Serial.print(joystick_x);
 Serial.print(" , ");
 Serial.print("Joystick Y Axis: ");
 Serial.print(joystick_y);
 Serial.print(" , ");
 Serial.print("Speed Potentiometer: ");
 Serial.print(pot_1);

 Serial.println("");
}

void pin_remap(){
 joystick_x = map(readMux(15), 0, 1023, 180, 0);
 joystick_y = map(readMux(14), 0, 1023, 0, 180);
 pot_1 = map(readMux(13), 0, 1023, 0, 255);
}
 //end of logic functions --------------------------------------------------
void clearRegisters(){
 for(int i = numOfRegisterPins - 1; i >= 0; i--){
 registers[i] = LOW;
 }
}

void writeRegisters(){
 digitalWrite(RCLK_Pin, LOW);
 for(int i = numOfRegisterPins - 1; i >= 0; i--){
 digitalWrite(SRCLK_Pin, LOW);
 int val = registers[i];
 digitalWrite(SER_Pin, val);
 digitalWrite(SRCLK_Pin, HIGH);
 }
 digitalWrite(RCLK_Pin, HIGH);
}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
 registers[index] = value;
}

int readMux(int channel){
 int controlPin[] = {s0, s1, s2, s3};
 int muxChannel[16][4]={
 {0,0,0,0}, //channel 0
 {1,0,0,0}, //channel 1
 {0,1,0,0}, //channel 2
 {1,1,0,0}, //channel 3
 {0,0,1,0}, //channel 4
 {1,0,1,0}, //channel 5
 {0,1,1,0}, //channel 6
 {1,1,1,0}, //channel 7
 {0,0,0,1}, //channel 8
 {1,0,0,1}, //channel 9
 {0,1,0,1}, //channel 10
 {1,1,0,1}, //channel 11
 {0,0,1,1}, //channel 12
 {1,0,1,1}, //channel 13
 {0,1,1,1}, //channel 14
 {1,1,1,1} //channel 15
 };

//loop through the 4 sig
 for(int i = 0; i < 4; i ++){
 digitalWrite(controlPin[i], muxChannel[channel][i]);
 }

//read the value at the SIG pin
 int val = analogRead(SIG_pin);

//return the value
 return val;
}
<pre>

Arduino Vehicle:

</pre>
const char EOPmarker = '.'; //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

#include <string.h> // we'll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed.

#include <LiquidCrystal.h> //we'll need this for the lcd
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //pins for the lcd, I set it up using the ladyada tutorial.

#include <Servo.h>
Servo left_servo;
Servo right_servo;
int esc_pwm = 6;

int left_servo_pos;
int right_servo_pos;

void setup(){
 lcd.begin(16, 2);
 left_servo.attach(3);
 right_servo.attach(5);
 pinMode(esc_pwm, OUTPUT);

 Serial.begin(9600); //changing this to other speeds has not been tested using this meathod
}

void loop() {
 if (Serial.available() > 0) { //makes sure something is ready to be read
 lcd.clear(); //clears for incoming stuff, won't clear if there isin't data to be read
 static int bufpos = 0; //starts the buffer back at the first position in the incoming serial.read
 char inchar = Serial.read(); //assigns one byte (as serial.read()'s only input one byte at a time
 if (inchar != EOPmarker) { //if the incoming character is not the byte that is the incoming package ender
 serialbuf[bufpos] = inchar; //the buffer position in the array get assigned to the current read
 bufpos++; //once that has happend the buffer advances, doing this over and over again until the end of package marker is read.
 }
 else { //once the end of package marker has been read
 serialbuf[bufpos] = 0; //restart the buff
 bufpos = 0; //restart the position of the buff

 left_servo_pos = atoi(subStr(serialbuf, ",", 1));
 lcd.write("Lft Servo:");
 lcd.write(subStr(serialbuf, ",", 1)); //witres the first bit of content before the first comma (or other seperator) to the lcd
 left_servo.write(left_servo_pos);

 lcd.setCursor(0, 1);

 right_servo_pos = atoi(subStr(serialbuf, ",", 2));
 lcd.write("Rgt Servo:"); //this signifies that the first seperation has occured
 lcd.write(subStr(serialbuf, ",", 2)); //same thing as 2 lines above, but with the second parts. this can be repeated
 right_servo.write(right_servo_pos);

 analogWrite(esc_pwm, atoi(subStr(serialbuf, ",", 3)));
 }
 }
}

// below is just function logic, which I do not fully understand. but it works.
char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

 strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

//esologic.com
//Thanks to http://arduino.cc/forum/index.php?topic=119429

&nbsp;
<pre>

Visual Basic:

https://esologic.com/source/plane/Round_1/vehicle_companion/

Just download those files and you should be able to open them in the vb studio.

Spitting incoming serial data arduino and visual basic

UPDATED CODE HERE


Hello! as you can probably tell, my last post was written in a fury of incoherency, but I needed to get the code out there so it is what it is.

The main focus of this post is to showcase the arduino program. The visual basic in the video is very simple, and there will be much more on that later.

This below program will take a string of characters fed to the arduino and split them into usable parts. This is a very valuable tool for working with serial and arduino. It’s pretty well commented, but if you have any questions, PLEASE leave a comment. I’d love to see some conversation here.

const char EOPmarker = '.'; //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

#include  // we'll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed.

#include  //we'll need this for the lcd
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //pins for the lcd, I set it up using the ladyada tutorial.

void setup(){
 lcd.begin(16, 2);
 Serial.begin(9600); //changing this to other speeds has not been tested using this meathod
}

void loop() {
 if (Serial.available() > 0) { //makes sure something is ready to be read
 lcd.clear(); //clears for incoming stuff, won't clear if there isin't data to be read
 static int bufpos = 0; //starts the buffer back at the first position in the incoming serial.read
 char inchar = Serial.read(); //assigns one byte (as serial.read()'s only input one byte at a time
 if (inchar != EOPmarker) { //if the incoming character is not the byte that is the incoming package ender
 serialbuf[bufpos] = inchar; //the buffer position in the array get assigned to the current read
 bufpos++; //once that has happend the buffer advances, doing this over and over again until the end of package marker is read.
 }
 else { //once the end of package marker has been read
 serialbuf[bufpos] = 0; //restart the buff
 bufpos = 0; //restart the position of the buff
 lcd.write(subStr(serialbuf, ",", 1)); //witres the first bit of content before the first comma (or other seperator) to the lcd. You could also do math or anything else with these. You could use atoi to change them to integers.
 lcd.write("|separator|"); //this signifies that the first seperation has occured
 lcd.write(subStr(serialbuf, ",", 2)); //same thing as 2 lines above, but with the second parts. this can be repeated
 }
 }
}

// below is just function logic, which I do not fully understand. but it works.
char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

//esologic.com
//Thanks to http://arduino.cc/forum/index.php?topic=119429

So for example if you inputted

[code]
123,456.
[/code]

it would output

[code]
123|separator|456
[/code]

to the lcd, or the serial monitor if you tweaked the code.

Now for the code in the video. The only different part about this is that it writes the two values to the servos.


const char EOPmarker = ‘.’; //This is the end of packet marker
char serialbuf[32]; //This gives the incoming serial some room. Change it if you want a longer incoming.

#include // we’ll need this for subString
#define MAX_STRING_LEN 20 // like 3 lines above, change as needed.

#include //we’ll need this for the lcd
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //pins for the lcd, I set it up using the ladyada tutorial.

#include
Servo left_servo;
Servo right_servo;

int left_servo_pos;
int right_servo_pos;
void setup(){
lcd.begin(16, 2);
left_servo.attach(2);
right_servo.attach(3);
Serial.begin(9600); //changing this to other speeds has not been tested using this meathod
}

void loop() {
if (Serial.available() > 0) { //makes sure something is ready to be read
lcd.clear(); //clears for incoming stuff, won’t clear if there isin’t data to be read
static int bufpos = 0; //starts the buffer back at the first position in the incoming serial.read
char inchar = Serial.read(); //assigns one byte (as serial.read()’s only input one byte at a time
if (inchar != EOPmarker) { //if the incoming character is not the byte that is the incoming package ender
serialbuf[bufpos] = inchar; //the buffer position in the array get assigned to the current read
bufpos++; //once that has happend the buffer advances, doing this over and over again until the end of package marker is read.
}
else { //once the end of package marker has been read
serialbuf[bufpos] = 0; //restart the buff
bufpos = 0; //restart the position of the buff

left_servo_pos = atoi(subStr(serialbuf, “,”, 1));
lcd.write(“Left Servo:”);
lcd.write(subStr(serialbuf, “,”, 1)); //witres the first bit of content before the first comma (or other seperator) to the lcd
left_servo.write(left_servo_pos);

lcd.setCursor(0, 1);

right_servo_pos = atoi(subStr(serialbuf, “,”, 2));
lcd.write(“Right Servo:”); //this signifies that the first seperation has occured
lcd.write(subStr(serialbuf, “,”, 2)); //same thing as 2 lines above, but with the second parts. this can be repeated
right_servo.write(right_servo_pos);
}
}
}

// below is just function logic, which I do not fully understand. but it works.
char* subStr (char* input_string, char *separator, int segment_number) {
char *act, *sub, *ptr;
static char copy[MAX_STRING_LEN];
int i;

strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

sub = strtok_r(act, separator, &ptr);
if (sub == NULL) break;
}
return sub;
}

//esologic.com
//Thanks to http://arduino.cc/forum/index.php?topic=119429

Splitting Strings Arduino

UPDATED CODE HERE


 

Hello!

Today I ordered parts for the proto phase of the plane.

This is a bit of code i’ve found that’s usefully for splitting strings in the arduino C

</pre>
#include <string.h>
#define MAX_STRING_LEN 20

char *inputstring1 = "one,two,three,four,five,six,seven,eight,nine,ten"; //this is the string that will be split. this can be changed!
char *p, *i;
int x;

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

void loop () {
 for (int x = 1; x <= 10; x++) {
 Serial.println(subStr(inputstring1, ",", x));
 delay(1000);
 }
}

char* subStr (char* input_string, char *separator, int segment_number) {
 char *act, *sub, *ptr;
 static char copy[MAX_STRING_LEN];
 int i;

 strcpy(copy, input_string);

for (i = 1, act = copy; i <= segment_number; i++, act = NULL) {

 sub = strtok_r(act, separator, &ptr);
 if (sub == NULL) break;
 }
 return sub;
}

//esologic.com

Plane | Project [Declaration]

Ever since I posted this back in January I’ve been collecting ideas and information on how to make something like the craft pictured in the video and related ones.

The tenative parts list can be found here, but there’s an analog accelerometer, an esc + brushless motor combo, and a battery array so far.

As for wireless, that’s the one area of this project that I’ve done no research on at all. I’m probably going to use a long range bluetooth serial connection, or an xbee serial connection. No matter what it’s going to be serial, as that’s what I’m most familiar with.

So far I’ve proto’d the controller and written the framework for the visual basic program and some of the controller arduino side of the program.

Here’s the video of what I’ve done so far, as you can see the trackbar visualizes reallly nicely. and i’m using the split function and my knowledge of arrays to separate x and y resistance values from the joystick:

http://youtu.be/qTN9DqKTL9M

 

As you can probably also tell, there’s no name for the project yet, if you think of something let me know!

 

Research Link Repo:

http://www.open-electronics.org/mma7455l-three-axis-digital-output-accelerometer/

http://hackaday.com/2012/02/10/using-a-cheap-accelerometer-with-arduino-comes-with-a-catch/

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1263756306 //Wii as accelerometer.