Welcome, Guest. Please login or register.
Did you miss your activation email?

Username: Password:


Pages: [1]   Go Down

Author Topic: pleo taking photos (source code for pdk)  (Read 11133 times)

mischamd

  • Member of the herd
  • ** Posts: 19
  • Male
pleo taking photos (source code for pdk)
« on: September 12, 2009, 01:47:17 PM »

hey guys
here is my sourcecode for the pdk with it your pleo is able to take photos from objects he can see.
its not complete now but im working on it.

at the moment i have some problem with saving the photos because many times he take a photo and write nothing in the bmp file
and my code for saving the photos in different files didnt work correct on pleo.

Instructions:

because pleo needs some time to save the photos correctly you have to wait a little bit after holding an object in front of the cam.
if he has saved the photo correctly he plays a simple sound back to you. after he plays the sound you can take the object in front of his cam back. pleo also plays the same sound after that. now pleo is ready for taking a second photo.
the photos are on you sd-card and you can open them on your pc.


Code:

but here is my code it is an extended props_example i only post the main script.
i hope you can understand my comments if not ask me ;)

Code: [Select]
//
// main.p
// extended Properties Example
//
// Version 0.2
//
// 0.2: pleo now take photos correctly but give him some time!
//
// This very simple main script, which runs in the
// Main VM, demonstrates the
// use of Pleo's properties system to communicate
// between scripts running in different VMs.
//

// save space by packing all strings
#pragma pack 1

#pragma tabsize 0
//
#include <Log.inc>
#include <Script.inc>
#include <Property.inc>
#include <Sound.inc>
#include <Motion.inc>
#include <File.inc>
#include <String.inc>
#include <Script.inc>
#include <Camera.inc>
#include <Util.inc>
#include <Time.inc>

#include "user_properties.inc"
#include "sounds.inc"
#include "motions.inc"

forward public photo(zahl);

public init()
{
    print("main::init() enter\n");
print("main::init() exit\n");
}

public main()
{
    print("main::main() enter\n");

//variables for filenames

new file_name[]="test0.bmp";
new file_number=0;
new file_number_two[2]="";


while (file_exists(file_name))
{
file_number=file_number+1;
string_copy(file_name,"");
  string_copy(file_number_two,"");
string_concat(file_name,"test",39);
itoa(file_number,10,file_number_two,2);
string_concat(file_name,file_number_two,39);
string_concat(file_name,".bmp",39);
}

    // The main VM will run the main() function again and
    // again once it returns, but this infinite for loop is
    // inserted to keep the main() function from returning.
   for (;;)
    {
if(property_get(property_object_front))
{



//copy the right string to take the photo
file_number++;
string_copy(file_name,"");
string_copy(file_number_two,"");
itoa(file_number,16,file_number_two,2);
string_concat(file_name,"camera capture test",39);
string_concat(file_name,file_number_two,39);
string_concat(file_name,".bmp",39);

//change drive to SD-card and photo size
monitor_exec("chdrv a");
monitor_exec(file_name)

  //time for pleo to save the photo
for (new i=0;i<2000;i++)
{
sleep;
}




//play sound the check if the photo was taken
sound_play(snd_fat_014);

while(sound_is_playing(snd_fat_014))
{
sleep;
}

property_set(property_object_front, 0)
}
        // If Pleo's head is being held, play a mooing noise
        // over and over again.
        while (property_get(property_head_held))
        {

            // Sounds are referred to by their filename,
            // minus the extension, with a prefix of "snd_".

sound_play(snd_moo);

            // Wait for the sound to complete.
            while (sound_is_playing(snd_moo))
            {
                sleep;
            }

        }

        // If Pleo's head is tapped, play the bow motion
        if (property_get(property_head_tapped))
        {

            // Reset the head tapped property, to indicate
            // that we've taken action.
            property_set(property_head_tapped, 0);



            // Motions are referred to by their filename, minus
            // the extension, with a prefix of "mot_".

motion_play(mot_kiss);

            // Wait for the sound to complete.
            while (motion_is_playing(mot_kiss))
            {
                sleep;
            }

        }

        // give some time back to the firmware
        sleep;
    }

}


public close()
{
    print("main:close() enter\n");

    print("main:close() exit\n");
}


and here is the sensor.p :

Code: [Select]
//
// sensors.p
// Properties Example
//
// This sensors.p script runs in the Sensors VM. It
// watches sensors and sets properties to notify the
// other scripts of certain events.
//
// The sensors used in this example are derived sensors
// and they may require that you use special methods to
// modify them. See the PDK documentation for more details.
//

// save space by packing all strings
#pragma pack 1

#include <Log.inc>
#include <Script.inc>
#include <Sensor.inc>
#include <Property.inc>
#include <Util.inc>
#include <Camera.inc>

#include "user_properties.inc"

public init()
{
    print("sensors:init() enter\n");
    print("sensors:init() exit\n");
}

public on_sensor(time, sensor_name: sensor, value)
{
    new name[32];
sensor_get_name(sensor, name);

    printf("sensors:on_sensor(%d, %s, %d)\n", time, name, value);

    switch (sensor)
    {

case SENSOR_OBJECT_IN_FRONT:
{

property_set(property_object_front, 1);



}
        // SENSOR_TOUCH_HOLD tells us that a sensor
        // is being held - the value passed by SENSOR_TOUCH_HOLD
        // is equal to the sensor that is being held.
        case SENSOR_TOUCH_HOLD:
        {
            if (sensor_name:value == SENSOR_HEAD)
            {
                // Let other scripts know that the sensor
                // is being held.
                property_set(property_head_held, 1);
            }
        }

        // SENSOR_TOUCH_RELEASE tells us that a sensor
        // that was being held was released - the value passed by
        // SENSOR_TOUCH_RELEASE is equal to the sensor that was
        // just released.
        case SENSOR_TOUCH_RELEASE:
        {
            if (sensor_name:value == SENSOR_HEAD)
            {
                // Let other scripts know that the sensor
                // has been released.
                property_set(property_head_held, 0);
            }
        }

        // SENSOR_TOUCH_TAP tells us that a sensor
        // has been tapped - the value passed by SENSOR_TOUCH_TAP
        // is equal to the sensor that is being held.
        case SENSOR_TOUCH_TAP:
        {
            if (sensor_name:value == SENSOR_HEAD)
            {
                // Let other scripts know that the head
                // sensor has been tapped.
                property_set(property_head_tapped, 1);
            }
        }

    }

    // reset sensor trigger
    return true;
}

public close()
{
    print("sensors:close() enter\n");

    print("sensors:close() exit\n");
}


here is a photo that my pleo have taken



Update September the 22nd
« Last Edit: September 22, 2009, 04:11:44 AM by mischamd »
Logged


justbede

  • Pleo visionary
  • * Posts: 260
  • Male
Re: pleo taking photos (source code for pdk)
« Reply #1 on: September 15, 2009, 12:30:25 PM »

Sorry forgot to say thanx. Thank you misch :) btw when i tried the code the .bmp saved was empty, it read as 0kb and would not open. Off topic have you done many courses in programming? or are you learning as you go along like me? Thanks again.
Logged
Innvo Labs, creating life since 2009

mischamd

  • Member of the herd
  • ** Posts: 19
  • Male
Re: pleo taking photos (source code for pdk)
« Reply #2 on: September 15, 2009, 01:04:42 PM »

yes i have the same problem with the bmp file but sometimes i dont no why he take a photo that works but i am working on this problem and i hope to fix it.

as i was younger mabay i was 12 years old i start programming with c++ by reading a book of it and later i visited a special school for people who wanna study computer systems at the universaty where i learn c and other computer related things. at the universaty i had and have some lectures for algorithm and data strucktures or programming a little os. all these lectures are in different languages like java haskell c++ fortran and all those formal languages. in my free time i read books or ebooks about programming and all those things and try a little bit by my self. i hope its a good answer of your off topic question
Logged

justbede

  • Pleo visionary
  • * Posts: 260
  • Male
Re: pleo taking photos (source code for pdk)
« Reply #3 on: September 15, 2009, 08:54:26 PM »

Good good it's a shame because it really is a small problem. Wow 12 that's pretty impressive hah i'm 19 and struggling with pawn  ;D keep it up dude.
Logged
Innvo Labs, creating life since 2009

InmemoryofRomeo

  • Global Moderator
  • Pleo Grand Master RB
  • * Posts: 6903
  • au Female
  • Pleo(s): Lilo, Stitch, Pleakley, Jumba, Nani, Yuki, Angus, Pluto
  • : 2011 winner2009 winnerTomato Harvest Festivals
  • SAVE THE EARTH It's the only planet with chocolate
    • Professor
    • Wile_E_Coyote
    • Marcie
Re: pleo taking photos (source code for pdk)
« Reply #4 on: September 15, 2009, 10:57:16 PM »

Drat... that make me feel old :P
Logged
Eagerly awaiting Vector and Blue!

Dadio

  • Pleozoologist
  • * Posts: 247
  • Male
  • Robotics, is the sincerest form of flattery!
Re: pleo taking photos (source code for pdk)
« Reply #5 on: September 16, 2009, 09:46:36 AM »

If you feel old I must feel ancient!!!  ^-^

That's a very impressive educational background in programming ;)

Please bear with we who are older and slower with our program writing and testing.  ;)

You sure are a welcome friend and resource for our community.  :)

Dadio  8)
Logged
PLEO's Forever!
Take Good Care!  - from Dadio 8)  & Stoney [img width=200 height=50 alt=]http://bobthepleo.com/forums/MGalleryItem.php?id=1183[/img]

b blue eyes

  • Pleo visionary
  • * Posts: 273
  • Female
  • ACCOUNT DELETED
Re: pleo taking photos (source code for pdk)
« Reply #6 on: September 16, 2009, 02:06:10 PM »

yes i have the same problem with the bmp file but sometimes i dont no why he take a photo that works but i am working on this problem and i hope to fix it.

as i was younger mabay i was 12 years old i start programming with c++ by reading a book of it and later i visited a special school for people who wanna study computer systems at the universaty where i learn c and other computer related things. at the universaty i had and have some lectures for algorithm and data strucktures or programming a little os. all these lectures are in different languages like java haskell c++ fortran and all those formal languages. in my free time i read books or ebooks about programming and all those things and try a little bit by my self. i hope its a good answer of your off topic question

I am so thankful for all of you technical people who are so willing to share your talent with those of us, especially me who has no talent for technical things, who are not gifted in this area.  Most of the people on here at least have a clue to what is happening, have knowledge in software, hardware, etc.  I thank you so much for making it possible for me to use my gift by providing all the great things you all do to keep the Pleo's going and providing endless joy and hours of comfort to so many people.  Just like the human body, all parts have a purpose from the heart to the smallest blood vessel each working in unison.  Keep up the good work, you have a big cheering section behind you.
« Last Edit: September 16, 2009, 02:09:10 PM by b blue eyes »
Logged

justbede

  • Pleo visionary
  • * Posts: 260
  • Male
Re: pleo taking photos (source code for pdk)
« Reply #7 on: September 16, 2009, 03:28:26 PM »

Heh blue eyes is always so gratious  :)
Logged
Innvo Labs, creating life since 2009

mischamd

  • Member of the herd
  • ** Posts: 19
  • Male
Re: pleo taking photos (source code for pdk)
« Reply #8 on: September 22, 2009, 04:05:41 AM »

hey guys i think i have found the problem why there is nothing in the photo files.
i have tested a little bit and i have found out that pleos prozessor isnt so fast as i have imagined.
so i give pleo some sleeptime that he can save the photos corractly.

i have added the new main.p file with instructions and a sample photo from nino.
Logged

justbede

  • Pleo visionary
  • * Posts: 260
  • Male
Re: pleo taking photos (source code for pdk)
« Reply #9 on: September 22, 2009, 07:52:26 AM »

Wicked thanks Misch your a star i'll give it ago asap, koodos.
Logged
Innvo Labs, creating life since 2009

Dadio

  • Pleozoologist
  • * Posts: 247
  • Male
  • Robotics, is the sincerest form of flattery!
Re: pleo taking photos (source code for pdk)
« Reply #10 on: September 22, 2009, 08:39:50 AM »

Mischamd;  :)

Thanks for the work and the file. I hope to try it soon.  ;)
 
Dadio  8)
Logged
PLEO's Forever!
Take Good Care!  - from Dadio 8)  & Stoney [img width=200 height=50 alt=]http://bobthepleo.com/forums/MGalleryItem.php?id=1183[/img]

InmemoryofRomeo

  • Global Moderator
  • Pleo Grand Master RB
  • * Posts: 6903
  • au Female
  • Pleo(s): Lilo, Stitch, Pleakley, Jumba, Nani, Yuki, Angus, Pluto
  • : 2011 winner2009 winnerTomato Harvest Festivals
  • SAVE THE EARTH It's the only planet with chocolate
    • Professor
    • Wile_E_Coyote
    • Marcie
Re: pleo taking photos (source code for pdk)
« Reply #11 on: September 22, 2009, 05:17:33 PM »

I will certainly try it sooner or later I'm afraid my to-do list is quite long at the moment though :P
Logged
Eagerly awaiting Vector and Blue!

justbede

  • Pleo visionary
  • * Posts: 260
  • Male
Re: pleo taking photos (source code for pdk)
« Reply #12 on: September 27, 2009, 11:23:41 AM »

Hi Misch sorry for the long wait (flu took longer than expected) i built the source into an urf put it in Baxter and hey presto he's taking pictures. Currently picture 1 will save but number two is saving an empty .bmp like last time, great work on getting things working i've been playing with camera scripts but being a noob to scripting is making things tough :p. Koodos again my friend!
Logged
Innvo Labs, creating life since 2009

haniel

  • Guest
Re: pleo taking photos (source code for pdk)
« Reply #13 on: March 25, 2010, 02:52:37 AM »

This looks great, but I seem to be having trouble compiling it. I keep getting errors about missing the symbols for the properties (like property_object_front).
And I'm not really sure what this user_properties file is supposed to be, but then I haven't coded for the Pleo at all, so I'm relatively new to this. >.<

A question about the code though, wouldn't it be better to construct the filename inside the for-loop? Instead of constructing it before and inside it.

For example:
Code: [Select]
public main(){
    print("main::main() enter\n");

//variables for filenames
new file_name[]="test0.bmp";
new file_number=0;
new file_number_two[2]="";

    // The main VM will run the main() function again and
    // again once it returns, but this infinite for loop is
    // inserted to keep the main() function from returning.
   for (;;){
if(property_get(property_object_front)){
//copy the right string to take the photo

while (file_exists(file_name)){
file_number=file_number+1;
string_copy(file_name,"");
  string_copy(file_number_two,"");
string_concat(file_name,"test",39);
itoa(file_number,10,file_number_two,2);
string_concat(file_name,file_number_two,39);
string_concat(file_name,".bmp",39);
}

//change drive to SD-card and photo size
monitor_exec("chdrv a");
monitor_exec(string_concat("camera capture ",file_name,39));


    //time for pleo to save the photo
Logged
Pages: [1]   Go Up
 

SimplePortal 2.3.5 © 2008-2012, SimplePortal