Arduino Joystick Controller
- Войдите на сайт для отправки комментариев
Пт, 15/08/2014 - 04:03
Случайно наткнулся та вот такую прожку для андроид:
https://play.google.com/store/apps/details?id=com.andico.control.joystic...
Вот видео из ссылки:
https://www.youtube.com/watch?v=kwv1UAA8cJY
Вот ссылка на сам проект:
https://sites.google.com/site/bluetoothrccar/home/6-Joystick-Control
Так вот, если тупо взять код со странички и вставить в IDE то среда ругает мол не знаю того-то того-то...
Сам проект интересный, помогите разобраться, ато просто кнопками рулить не интересно, как тут на видео:
блин вот ну не новичек же. по хрустальному шару гадать на что там среда ругаеться?
и гадать какой именно код вы используете? андроид отсылает буковки по блютусу. ловите буковки и реагируйте на них.
#include <Servo.h> #include <L293.h> #define pinForward 8 #define pinBack 7 #define pinSpeedForwardBack 6 #define pinFrontLights 2 #define pinBackLights 3 #define pinFrontSteering 10 //L293(pinForward, pinBack, pinFwdBakVel); L293 redCar(pinForward,pinBack,pinSpeedForwardBack); Servo leftRight; byte commands[4] = { 0x00,0x00,0x00,0x00}; byte prevCommands[4] = { 0x01,0x01,0x01,0x01}; //Variables will be used to determine the frequency at which the sensor readings are sent //to the phone, and when the last command was received. unsigned long timer0 = 2000; //Stores the time (in millis since execution started) unsigned long timer1 = 0; //Stores the time when the last sensor reading was sent to the phone unsigned long timer2 = 0; //Stores the time when the last command was received from the phone //14 byte payload that stores the sensor readings byte three[14] = { 0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xcc}; //Constant used to caculate the 9V battery voltage (9.04 mV per step) float stepSize = 9.04; //The union allows you to declare a customized data type, in this case it can be either //a float or a byte array of size 4. What we need is to store a float which is 4 //bytes long and retrieve each of the 4 bytes separately. union u_sensor0{ byte a[4]; float b; } sensor0; union u_sensor1{ byte c[4]; float d; } sensor1; int i = 0; void setup() { Serial.begin(115200); pinMode(pinFrontLights, OUTPUT); pinMode(pinBackLights, OUTPUT); leftRight.attach(pinFrontSteering); } void loop() { if(Serial.available()==4){ timer2 = millis(); //Store the time when last command was received memcpy(prevCommands,commands,4); //Storing the received commands commands[0] = Serial.read(); //Direction commands[1] = Serial.read(); //Speed commands[2] = Serial.read(); //Angle commands[3] = Serial.read(); //Lights and buttons states /* Since the last byte yields the servo's angle (between 0-180), it can never be 255. At times, the two previous commands pick up incorrect values for the speed and angle. Meaning that they get the direction correct 100% of the time but sometimes get 255 for the speed and 255 for the angle. */ if((commands[2]<=0xb4)&&((commands[0]<=0xf5)&&(commands[0]>=0xf1))){ //Make sure that the command received involves controlling the car's motors (0xf1,0xf2,0xf3) if(commands[0] <= 0xf3){ if(commands[0] == 0xf1){ //Check if the move forward command was received if(prevCommands[0] != 0xf1){ //Change pin state to move forward only if previous state was not move forward redCar.forward_1W(commands[1]); //Serial.println("Updated direction FWD"); } } else if(commands[0] == 0xf2){ //Check if the move back command was received if(prevCommands[0] != 0xf2){ //Change pin state to move back only if previous state was not move back redCar.back_1W(commands[1]); //Serial.println("Updated direction BAK"); } } else{ //Check if the stop command was received if(prevCommands[0] != 0xf3){ //Change pin state to stop only if previous state was not stop redCar.stopped_1W(); //Serial.println("Updated direction STP"); } } //Change speed only if new speed is not equal to the previous speed if(prevCommands[1] != commands[1]){ redCar.setSpeed_1W(commands[1]); //Serial.println("Updated speed"); } //Steer front wheels only if the new angle is not equal to the previous angle if(prevCommands[2] != commands[2]){ leftRight.write(commands[2]); //Serial.println("Updated angle"); } } else if(commands[0] == 0xf5){ if(prevCommands[0] != 0xf5){ //Stop everything redCar.stopped_1W(); digitalWrite(pinFrontLights,LOW); digitalWrite(pinBackLights,LOW); } } else{ //Here you put the code that will control the tilt pan (commands[0] == 0xf4) } //Check the front/back lights and other toggles if(prevCommands[3] != commands[3]){ //Serial.println(commands[3],BIN); //Change the light/button states // _______________________________________________ //command[3] = | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | binary // |_____|_____|_____|_____|_____|_____|_____|_____| //Buttons ----> Front Back Horn A B C D E //Front lights if((bitRead(prevCommands[3],7))!=(bitRead(commands[3],7))){ if(bitRead(commands[3],7)){ digitalWrite(pinFrontLights,HIGH); } else{ digitalWrite(pinFrontLights,LOW); } } //Back lights if((bitRead(prevCommands[3],6))!=(bitRead(commands[3],6))){ if(bitRead(commands[3],6)){ digitalWrite(pinBackLights,HIGH); } else{ digitalWrite(pinBackLights,LOW); } } //Horn (using front lights to test) if((bitRead(prevCommands[3],5))!=(bitRead(commands[3],5))){ if(bitRead(commands[3],5)){ digitalWrite(pinFrontLights,HIGH); } else{ digitalWrite(pinFrontLights,LOW); } } } } else{ //Resetting the Serial port (clearing the buffer) in case the bytes are not being read in correct order. Serial.end(); Serial.begin(9600); } } else{ timer0 = millis(); //Get the current time (millis since execution started) if((timer0 - timer2)>400){ //Check if it has been 400ms since we received last command //More tan 400ms have passed since last command received, car is out of range. Therefore //Stop the car and turn lights off redCar.stopped_1W(); digitalWrite(pinFrontLights,LOW); digitalWrite(pinBackLights,LOW); } if((timer0 - timer1)>=477){ //Check if it has been 477ms since sensor reading were sent //Calculate the 9V's voltage by multiplying the step size by the step number (analogRead(0)) //This value will be in mV, which is why it's multiplied by 0.001 to convert into Volts. sensor0.b = (analogRead(0) * stepSize) * 0.001; //Break the sensor0 float into four bytes for transmission three[1] = sensor0.a[0]; three[2] = sensor0.a[1]; three[3] = sensor0.a[2]; three[4] = sensor0.a[3]; //Get sensor 2's reading sensor1.d = analogRead(1); //Break the sensor1 float into four bytes for transmission three[5] = sensor1.c[0]; three[6] = sensor1.c[1]; three[7] = sensor1.c[2]; three[8] = sensor1.c[3]; //Get the remaining reading from the analog inputs three[9] = map(analogRead(2),0,1023,0,255); three[10] = map(analogRead(3),0,1023,0,255); three[11] = map(analogRead(4),0,1023,0,255); three[12] = map(analogRead(5),0,1023,0,255); //Send the six sensor readings Serial.write(three,14); //Store the time when the sensor readings were sent timer1 = millis(); } } }Ругаеццо вот так:
ммм тебя там чего инопланетяне похитили? и ты так просиш что бы мы тебе спасателей по ИП выслали?
тоесть сам ты не догоняешь про необходимость библиотек?
https://sites.google.com/site/bluetoothrccar/home/6-Joystick-Control
Там внизу есть библиотека, скачал самую первую в списке, добавил в IDE, перезагрузил IDE, открываю пример, жму компилировать и вижу тоже самое.
https://sites.google.com/site/bluetoothrccar/home/6-Joystick-Control
Там внизу есть библиотека, скачал самую первую в списке, добавил в IDE, перезагрузил IDE, открываю пример, жму компилировать и вижу тоже самое.
насколько я понимаю L293 это шильд. и нафиг тебе вообще библиотеки то?читай буковки в блютуса и делай танцы как тебе нравиться.
я чет не пойму, враги украли украли твой акаунт?
Да игрался я с буковками:
https://www.youtube.com/watch?v=RZbMbpXcUVY
Не интересно, более интересней когда как стик на джойстике от приставки, чтобы можно было управлять тягой а не просто вкл/выкл.
ПО прикольное что в ссылке в первом посте, даже можно смотреть что там от МК приходит...
Вот этот проект посмотрите, управление машинкой с андроида. Джойстик, кнопки, все что хотите можете в интерфейс управления добавить. Джойстик можно завязать на аксель. Так же и обратная связь.
http://remotexy.com/ru/examples/car/
http://www.youtube.com/watch?v=Cjxzi5NaizY
У меня стояк на это видео, надо попробовать.
Вот только дорого.
Не то чтобы там не было за что платить, просто у меня такая концепция, недорого, несложно и быстро.
просто у меня такая концепция, недорого, несложно и быстро.
ну дык а чего вы тогда жалуетесь что оно не шибко качественно? все так сказать в рамках концепции :)
ребятки фигней страдаете
чтобы пультом поуправлять привязываете себя к чужому апликашену к дорогому гироскопопултейшену
я тоже во все это игрался Eclise-ом на Android 2.3.4 ...4.0.5
Даже сейчас на проекте CatBotTray "подносе" висит рабочий дуплексный NRF24L01+
ребятки дарю быстрое независимое обучаемое мое решение дистанционного управления на ~1024 команды.
1 Берем люой свободный пульт ИК
2 втыкаем батарейки
3 втыкаем usb чтобы видеть каким кодам обучать наш робот.
4 вливаем мой код
5 подмениваем #define бла-бла-бла на обнаруженные коды с нашего ИК пульта из мусорки.
//art100 to write catbot 20140820 IR Usonic DCmotors #include <IRremote.h> #include <Servo.h> //pins-------------------------------- #define USTR1 A4//ultrasonic sensor #define USEC1 A5//ultrasonic sensor #define SERV1 3// #define MOT11 4//motor r #define MOT12 5//motor PWM r #define MOT21 6//motor PWM l #define MOT22 7//motor l #define IRIN1 8// IR receiver to Arduino //consts--------------------------------------- #define FORWARD 0xFFBA45 // #define LEFT 0xFF1AE5 // #define OK 0xFF9A65 // #define RIGHT 0xFF5AA5 // #define REVERSE 0xFFAA55 // #define ARM1 0xFF3AC5 // virtual #define ARM2 0xFF7A85 // menu #define ARM3 0xFF2AD5 // setup #define ARM4 0xFF6A95 // skip #define NUM0 0xFF9867 // 0 #define NUM1 0xFF30CF // 1 #define NUM2 0xFFB04F // 2 #define NUM3 0xFF708F // 3 #define NUM4 0xFF08F7 // 4 #define NUM5 0xFF8877 // 5 #define NUM6 0xFF48B7 // 6 #define NUM7 0xFF28D7 // 7 #define NUM8 0xFFA857 // 8 #define NUM9 0xFF6897 // 9 IRrecv irrecv(IRIN1); //IR create instance of 'irrecv' decode_results results; //IR Servo ServoHead1; // usb------------------------------ int commandusb = 0; // //----------------------------------------------- void setup(){ Serial.begin(9600);//test ServoHead1.attach(SERV1); ServoHead1.write(80); irrecv.enableIRIn(); // Start the IR receiver } //=================================================================== void loop(){ //IR-------------------------------------------------------------------------------- if(irrecv.decode(&results)){ //Check if the remote control is sending a signal if(results.value== NUM3){ } // test if(results.value== NUM4){ } // test if(results.value== NUM5){ } // test if(results.value== NUM6){ } // test if(results.value== NUM7){ } // test if(results.value== NUM8){ } // test if(results.value== NUM0){ digitalWrite(MOT11, LOW);digitalWrite(MOT12, LOW);digitalWrite(MOT21, LOW);digitalWrite(MOT22, LOW); } // test if(results.value== OK){ digitalWrite(MOT11, LOW);digitalWrite(MOT12, LOW);digitalWrite(MOT21, LOW);digitalWrite(MOT22, LOW); } // stop test if(results.value==FORWARD){ } if(results.value==REVERSE){ } Serial.println(results.value, HEX);//test обучение irrecv.resume(); // receive the next value // } }//if(irrecv.decode(&results)){ //IR-------------------------------------------------------------------------------- } //===================================================================Вы eclipse поднимать умеете? Садитесь вам 2.
Плять мне кто-нибудь кодом поделться для робота обьезжающего препятствия
Вот свободный пульт от двд какой-то уже обучил и "поднос" ездит.