Pages: [1]   Go Down
Author Topic: Need help understanding this piece of code (ArduPlane)  (Read 453 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys. I am looking at the code used by the open source ardupilot
http://code.google.com/p/ardupilot-mega/downloads/detail?name=ArduPlane-2.68.zip&can=2&q=

And I am having problem understanding this piece of code. Under GCS_Mavlink...

#if CAMERA == ENABLED
    case MAVLINK_MSG_ID_DIGICAM_CONFIGURE:
    {
        g.camera.configure_msg(msg);
        break;
    }

    case MAVLINK_MSG_ID_DIGICAM_CONTROL:
    {
        g.camera.control_msg(msg);
        break;
    }
#endif // CAMERA == ENABLED

So for "g.camera.configure_msg(msg);",
the dot operator is for accessing a structure member. So "g" and "camera" is a structure name and "configure_msg(msg)" is a structure member? So I assume there exists a declaration somewhere stating that...

int 50; //or any integer
int msg[n];

struct xxx{
configure_msg(msg);
}

struct yyy{
structure xxx camera;
}

struct yyy g;

But I couldn't find anything like that in the code. Can anyone tell me what exactly does that piece of code do? I have never learned anything about C structure before. I was just looking at tutorial online... Thanks a lot!
« Last Edit: February 08, 2013, 11:27:03 pm by dominicfhk » Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could be a struct or a class.  Either way, configure_msg() is a method "on" the object:
Code:
struct G {
  Camera camera;
};
struct Camera {
  void configure_msg(int msg){}
};
...

G g;
g.camera.configure_msg(msg);

HTH,
John
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the response. Would you mind to explain what you mean by "a method "on" the object" please? Thanks!
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

"Object-oriented programming (OOP) is a programming paradigm that represents concepts as "objects" that have data fields (attributes that describe the object) and associated procedures known as methods. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs.[1] [2]"  -- wiki

In c++, for you right now, a struct is basically the same as a class.

Cheers,
John
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In AP_Camera.h:

Code:
/// @class Camera
/// @brief Object managing a Photo or video camera
class AP_Camera {

public:

...

    // MAVLink methods
    void            configure_msg(mavlink_message_t* msg);
    void            control_msg(mavlink_message_t* msg);

I didn't find "g" or "camera" but there are a lot of files to look through.
Logged

Pages: [1]   Go Up
Jump to: