Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Michelangelo Guarise
Published

Carmadillo: Android Controlled UDOO Rover

Build a rover and control it with your Android phone.

Full instructions provided4,993
Carmadillo: Android Controlled UDOO Rover

Things used in this project

Hardware components

Old RC car
×1
Arduino Motor Shield
http://arduino.cc/en/Main/ArduinoMotorShieldR3
×1
UDOO Camera Module
UDOO Camera Module
×1
Stepped motors
×2
UDOO DUAL
UDOO DUAL
A Wifi-enabled model is required
×1
Android device
Android device
×1

Story

Read more

Code

code.txt

Plain text
sudo apt-get install libgstreamer0.10-dev libgstrtspserver-0.10-dev build-essential git

code.txt

Plain text
sudo apt-get install wicd-curses wireless-tools

code.txt

BatchFile
CPPFLAGS += -I. -I$(top_builddir)/include -I/usr/include/gstreamer-0.10 -I/usr/include/glib-2.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/libxml2 -I/usr/lib/glib-2.0/include -I/usr/include/gstreamer-0.10/gst/rtsp-server/
OBJ = rtsptest.o

%.o: %.c $(DEPS)
    $(CC) -c -o $@ $< $(CPPFLAGS)

rtsptest: $(OBJ)
    $(CC) -o $@ $^ $(LDFLAGS) $(CPPFLAGS) -pthread -lstdc++ -lgstreamer-0.10 -lgstrtsp-0.10 -lgstrtspserver-0.10 -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lxml2 -lglib-2.0 -lm

clean:
    rm *.o
    rm test

code.txt

Plain text
ln -s /dev/ttymxc3 /dev/ttyS0           
sleep 60s
/carmadillo/rtspserver/rtsptest &       
java -jar /carmadillo/carmadillo.jar      
exit 0

code.txt

C/C++
#include <stdio.h>
#include <Servo.h>

#define DIR_A 12
#define BRAKE_A 9
#define SPEED_A 3
#define DIR_B 13
#define BRAKE_B 8
#define SPEED_B 11

Servo panServo;
Servo tiltServo;
byte pan = (byte)90;   // init servo values
byte tilt = (byte)40;
boolean received = false;
int initSerialGarbage = 0;
int msg1garbage = 55;
int msg2garbage = 29;
int msg4garbage = 124;

void setup()
{
    // set communiation speed
    Serial.begin(230400);   
    pinMode(DIR_A, OUTPUT);
    pinMode(BRAKE_A, OUTPUT);
    pinMode(SPEED_A, OUTPUT);
    pinMode(DIR_B, OUTPUT);
    pinMode(BRAKE_B, OUTPUT);
    pinMode(SPEED_B, OUTPUT);
    digitalWrite(BRAKE_A, HIGH);
    analogWrite(SPEED_A, 0);
    printf("\r\Carmadillo serial start\r\n");
    panServo.attach(5);
    tiltServo.attach(6);
    delay(50);
    panServo.write(pan);
    tiltServo.write(tilt);
}

#define RCVSIZE 5

void loop()
{
    byte incomingByte = 0;
    uint8_t msg[RCVSIZE];
    uint32_t nbread = 0; 
    
    while (Serial.available() > 0) {
        // read the incoming byte:
        incomingByte = Serial.read();
        msg[nbread] = incomingByte;
        nbread++;
       // Serial.println(incomingByte);
        received = true;
        initSerialGarbage ++;
    } 

   if (received && initSerialGarbage > 5) {
     /*Serial.print("msg0: ");Serial.println(msg[0]);
     Serial.print("msg1: ");Serial.println(msg[1]);
     Serial.print("msg2: ");Serial.println(msg[2]);
     Serial.print("msg3: ");Serial.println(msg[3]);
     Serial.print("msg4: ");Serial.println(msg[4]); */

     if (msg[0] > 30 && msg[0] < 90){  // direction
        //digitalWrite(BRAKE_B, HIGH);
        analogWrite(SPEED_B, 0);
     } else if (msg[0] <= 30 && msg[0] > 0){
        digitalWrite(DIR_B, HIGH);
        digitalWrite(BRAKE_B, LOW);
        analogWrite(SPEED_B, 255);
     } else if (msg[0] >= 90){
        digitalWrite(DIR_B, LOW);
        digitalWrite(BRAKE_B, LOW);
        analogWrite(SPEED_B, 255);
     }

     if (msg[1] == 0 || msg[1] == 63){  // speed
        digitalWrite(BRAKE_A, HIGH);
        analogWrite(SPEED_A, 0);
     } else if (msg[1] < 63 && msg[1] > 0 && msg[1] != msg1garbage){
        digitalWrite(DIR_A, LOW);
        digitalWrite(BRAKE_A, LOW);
        analogWrite(SPEED_A, 127 - msg[1]);
     } else if (msg[1] > 63 && msg[1] < 128){
        digitalWrite(DIR_A, HIGH);
        digitalWrite(BRAKE_A, LOW);
        analogWrite(SPEED_A, msg[1]); 
     }

     if(msg[2] == 0 || msg[2] == 63){
     }if(msg[2] < 30 && msg[2] > 0 && msg[2] != msg2garbage){
         pan += 3;            // inverted axes
         if (pan > 170) pan = 170;
     } else if(msg[2] > 90){
         pan -= 3;
         if (pan < 5) pan = 5;
     }

     if(msg[3] == 0 || msg[3] == 63){
     }else if(msg[3] < 30 && msg[3] > 0){
         tilt += 3;  
         if (tilt > 125) tilt = 125;
     } else if(msg[3] > 90){
         tilt -= 3;
         if (tilt < 10) tilt = 10;
     } 

     if(msg[4] != 0 && msg[4] != msg4garbage) {
       if(msg[4] == 1){
         pan = 90;
         tilt = 40;
       }
     }

     panServo.write(pan);
     tiltServo.write(tilt); 
     received = false;
   } 
   delay(20);
}

Github

https://github.com/UDOOProjects/CarmadilloMk1/tree/master/CARMadilloDUE

Credits

Michelangelo Guarise

Michelangelo Guarise

7 projects • 57 followers
Founder @ volumio.org , passionate maker, unpredictable developer, misunderstood creative. I do stuff, I build things.

Comments