I’ve still got no idea what i’m going to name it. If you’ve got an idea in for the name, feel free to leave it in the comments. Actually on that note, If you’re reading this PLEASE leave a comment. I’ve had A LOT of bot traffic lately so i’m starting to really crack down on who’s a real reader or a bot.
So as you can see in the video above, I’ve gotten all 3 components working. I can use either joystick axis to control either the left or right servo independently. The potentiometer controls the value that is sent to the esc. As you can see by the code the esc signal is just a servo.write command. The controller code is identical to the last “Plane” post with the exception that the code mapped from the pot goes to 170 instead of 225. This is because I switched from a analogWrite() to a servo.write() signal.
Vehicle Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
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; Servo esc; int esc_pwm = 6; int left_servo_pos; int right_servo_pos; int current; int prophot = 2; int SER_Pin = 8; //pin 14 on the 75HC595 int RCLK_Pin = 9; //pin 12 on the 75HC595 int SRCLK_Pin = 10; //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]; void setup(){ lcd.begin(16, 2); left_servo.attach(3); right_servo.attach(5); esc.attach(6); pinMode(prophot, INPUT); pinMode(esc_pwm, OUTPUT); current = 0; pinMode(SER_Pin, OUTPUT); pinMode(RCLK_Pin, OUTPUT); pinMode(SRCLK_Pin, OUTPUT); for(int i = 0; i < 180; i += 1){ esc.write(i); Serial.println(i); delay(15); } esc.write(0); clearRegisters(); writeRegisters(); Serial.begin(9600); //changing this to other speeds has not been tested using this meathod } void loop() { setRegisterPin(1, HIGH); writeRegisters(); 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)); setRegisterPin(1, HIGH); writeRegisters(); left_servo.write(left_servo_pos); setRegisterPin(1, LOW); writeRegisters(); lcd.setCursor(0, 1); right_servo_pos = atoi(subStr(serialbuf, ",", 2)); setRegisterPin(3, HIGH); writeRegisters(); right_servo.write(right_servo_pos); setRegisterPin(3, LOW); writeRegisters(); if (digitalRead(prophot) == HIGH){ esc.write(atoi(subStr(serialbuf, ",", 3))); } if (digitalRead(prophot) == LOW){ esc.write(0); } } } } // 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; } 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; } void spinto(int target) { setRegisterPin(3, HIGH); writeRegisters(); while(current > target){ //Serial.println(current); esc.write(current); delay(15); current--; } while(current < target){ //Serial.println(current); esc.write(current); delay(15); current++; } setRegisterPin(3, LOW); writeRegisters(); } //esologic.com //Thanks to http://arduino.cc/forum/index.php?topic=119429 |
I’ve also been starting to think about how i’m going to take this thing to the next stage. The parts list still exists here: https://docs.google.com/spreadsheet/ccc?key=0AqD_oicSxsvmdFlPU1VPSkt6aHpoa0hqSEgwdDE2RGc if you want to check out what i’ve done so far. I’m starting to consider materials to make the body out of. Right now the main contendor is making a frame out of aluminum dowels welded together. I’ve got a friend who can weld aluminum so assembling the frame won’t be an issue. If I go with this option, i’ll be able to cleanly mount things to the vehicle itself, and not have to worry about things splitting or cracking. It will also be heavier than if I were to go with an all foam body.
I’ve also been considering what i’m going to get for a camera for this thing. As one of the goals for this was to be able to take really nice areal videos. I’ve tentatively landed on a camera called the HackHD. The thing that’s most attractive about it is that it can do 1080p video capture AND composite video output at the same time. This is great because my original plan was to have 2 cameras – one for HD video capture, and one to transmit back to my computer. The only problem is it’s price. I could easily just hack one of those HD keychain cameras to make it operable via micro controller – but I would need to use two cameras which could be cheaper after all but powering two separate cameras would be pretty difficult.
I need to wirelessly communicate with the vehicle as well. If you look through some of the videos on my old youtube channel you can see a little RC tank that communicated via bluetooth, so I’ve got a shred of experience with homebrew wireless. Again, I’ve tentatively landed on a solution. I’ve concluded that using an Xbee system would be the most flexible while maintaining stability. It can be used as a long-range serial TxRx pipe which is what i’m prototyping with now, so the whole code’s built around that. I’d be using the XBee 1mW Wire Antenna – Series 1 (802.15.4) for the transmitter, as it’s easy to power and has an omnidirectional antenna with a range of 1 mile. While I may not be flying a mile away, I’d like to have the flexibility. I could fly in the woods, in the snow, or in the fog. To connect the xbee to the Arduino I’d probably use the SainSmart XBee USB Adapter because it’s got the UART broken out. I could use the same board to connect it to the pc as well. I could make the whole system work for around 72 dollars, which is a little high but I really want it to work well.
I’ll cover powering it in another post, but I think the next thing I get is going to be the wireless stuff. I’ve been thinking a lot about how i’m going to proto a moving vehicle, I’m thinking of some kind of fan-boat thing. Or a 3 wheeled fan propelled car.
I’m not a robot.
Good to see! Thanks for checking me out man!