Let's Make Robots!

Pi-Boe - Raspberry pi

Navigate via website commands, ip webcam
AttachmentSize
photo2.PNG82.26 KB
photo3.JPG1.67 MB

Parts:      
     Parallax Boe-bot (Basic Stamp; Board of Education USB)
     Raspberry Pi
     Wireless adapter Wireless IP camera
     (an android phone with a busted screen running an IP webcam app on start up)

     Greetings LMR! This is my first post here and I am a new member. So, Saturday afternoon I was stuck indoors because I was sick. I started looking around at the electronics in my room, and this was born. The chassis is from a parallax Boe-bot of course(Be-bo as I like to refer to it). Basically what I've done is made the Rpi into a webserver. Thanks largely to drcurzon's tutorial on Instructables.(I had no experience with web programming, and this was a great opportunity to learn!). It is currently controlled by a web page and the debug terminal, to take advantage of the USB ports.(I've attached a picture of the page). This is rather messy and haphazardly thrown together and I will be improving it. This bot came together in two iterations.

1) I polled the debug terminal for incoming commands and executed movements accordingly. The commands were sent by logging in to the Rpi via my wireless local network, and executing a python script via the terminal. I established a Serial Connection via the Pyserial module. I wanted continuous input for control.

2)I used apache, MySQL, and a bash script as in the instructable I mentioned above. Basically, I can turn the Rpi's GPIO pins via a bash script, and a control.php webpage. The basic stamp then reads the state of the pin and executes movements accordingly. 3.3v is enough to pass the threshold to register as HIGH on the basic stamp(BS2 by the way). The bash script has to be running for the web control to work, so sometime soon I will be writing an init script and adding it to the boot sequence.

The second iteration is kind of dirty, but accomplishes my goal of a web controlled bot with an IP webcam(kind of a little security bot). I want to utilize the Rpi's UART pins with the basic stamp, but due to my lack of web programming knowledge I am unsure of how execute serial commands via a web interface. This is mainly a software project I suppose. A large portion of this is to teach myself about webservers and connecting that to physical output. Also I am an advocate of using old things in new ways, i.e. the boe-bot chassis. Be-bo was my first bot so I am paying homage to him with this project. Input is welcomed, thank you in advance, and thank LMR for facilitating this site!!

_________________________________________________________________________________________________________________

Update**

I swapped out the Basic Stamp for an Arduino Mega. I have a power transistor connected to the GPIO pin of the Rpi that I can turn the Mcu and sensors on and off through software to save power. Also I have a power transistor from the arduino to the servos, So that I can cut the power to the servos and save precious Amps. I want to add a circuit in to measure power capacity so that it can manage it's own power. Also since this is kind of a security bot, I can move it into position and cut power so that it can last longer.

_________________________________________________________________________________________________________

Update** 12-12-13

Lately I've been trying to use fopen(); in PHP to communicate with the serial port. I've tried to open it like a file and write to it in a similar manner. I've programmed the arduino to operate on serial commands. Alas, when I run the php script, no response. I will be re-examining everything I've done, and give it another go. Any advice is welcome!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I think that's not a bad idea :)

Thanks for sharing your code.

Here's what works for me...  I *tried* the php_serial class library, but it was a lot of overhead with little actual gain... I'm running the php from CLI in a Raspberry PI...  I found I did have to initialize the ttyACM0  serial port through an exec call, however after that, everything *just works*.


<?PHP

//Connect to Arduino for Motor Control
exec('stty -F /dev/ttyACM0 57600 raw -echo');
$arduino = fopen("/dev/ttyACM0", "w+");
print("Arduino attached:  ");

......................

stuff here ......

.....................

      //Sending the command string to the Arduino.  Comma Delimited string, started by a "99" <known value, can be anything>

     //  so... 99, command, parameter, current command UID   eg:  99,10,100,5  is -> move 100mm  as per command #5

    //  The UID is to provide feedback to the host as to what has been received/completed

   //  In *my* case, the cmd[] structure comes from a MySQL database fed by the control console...

 

     if($cmd[1] > 0 && $cmd[0] > $last_cmd) {     // If there is a command in the queue send to Arduino
            echo 'Command: '; echo $cmd[1]; echo "  Parameter: "; echo $cmd[2]; echo "\n";
                $ard_cmd = sprintf("99,%s,%s,%s", $cmd[1], $cmd[2], $cmd[0] )    ;
                echo "Sending: " . $ard_cmd;  echo "\n";
                fwrite($arduino,$ard_cmd);
                $last_cmd = $cmd[0];



       }

......................

stuff here ......

.....................

 

     //Reading datafrom the Arduino.  Comma Delimited string, started by a Response Type. Such as SNSR, for sensor dump

    // or SCAN, for a Sonar coordinates dump

    $buffer = fgets($arduino);                 // Read a line from the Arduino and parse
    $line = explode(',',$buffer);
        if($line[0] =='SNSR'){
              echo "Buffer is: " .$buffer."\n";
              $arduinodata['ardtime'] = $line[1];
              $arduinodata['motion'] = $line[2];
              $arduinodata['accel_x'] = $line[3];
              $arduinodata['accel_y'] = $line[4];
              $arduinodata['accel_z'] = $line[5];
              $arduinodata['heading'] = $line[6];
              $arduinodata['pan'] = $line[7];
              $arduinodata['tilt'] = $line[8];
              $arduinodata['directahead'] = $line[9];
              $arduinodata['directbehind'] = $line[10];
              $arduinodata['directright'] = $line[11];
              $arduinodata['directleft'] = $line[12];
              $arduinodata['ticksright'] = $line[13];
              $arduinodata['ticksleft'] = $line[14];
              $arduinodata['temperature'] = $line[15];
              $arduinodata['humidity'] = $line[16];
              $arduinodata['voltage'] = $line[17];
              $arduinodata['resp_UID'] = $line[18];

              $resp_UID = $line[18];
              $heading = $line[6];

              print_r($arduinodata);
              echo "\n\n";
           }      

?>


Hope this helps some...

 

I forgot about having to initialize the serial port, I will have to give that a go, thanks for that! Hopefully I'll get a chance to try it out today, between, work, my girlfriend, and getting ready to go into the military, it's hard to make time ha ha. I think a forum would be a wonderful resource for us. Collaboration is awesome.

I'm very interested which software / scripts you have used to control the robot through a webserver. Can you tell us a bit more about it? I'm planning to do the same thing and I'm a bit lost on how to get started with the rpi.

Should we start a separate forum thread re RPi web control over Arduino?

I'm sure there are a few of us doing this...  Might be good to compare notes / code...

 

Thanks a lot.

That's not the first time but now I REALLY have to learn back all this knowledge I had 20 years ago :)

 

It's never too late to learn or relearn ha ha

This looks good!

Can you explain a bit more the way you used transistor to manage power to sensors and servos ?

This is kind of what I did but instead of a solenoid I have the transistor between arduino and its battery supply. So that when a GPIO pin connected at the base goes HIGH the transistor passes power. Ideally this would be a opto-isolator and transistor, to not risk my Pi, but im taking a little bit of a chance. Then I have the same set up between the arduino and the servos connected to it so that I can set the base of the transistor low and disconnect the servos, and have any other sensors drawing power but not the servomotors.So if i want to turn the arduino off i set the GPIO pin LOW and if i want to disconnect the servos i set the pin as low. Being a little security bot, I can move it into position and then cut power until i am ready to move it..thanks for the quesiton and your interest!

I posted twice unintentionally, and have no clue how to delete it ha ha