How to add Ardupilot Parameters in source files

Hi,

I am trying to modify the AP_GPS.cpp file so the Ardupilot reports the GPS position with an offset. I would like to use the BCN_LATITUDE, BCN_LONGITUDE, BCN_ALT, and BCN_ORIENT_YAW to be able to change the offset without the need to recompile the firmware.

How can I get the value of these parameters within the AP_GPS.cpp ?

I am new to firmware programming and I am just testing. If there is a wiki where there is all the dev documentation please point me there.

Hope anyone can help me the the value to the parameters within the AP_GPS.cpp file.

Thank you in advance.
Regards,
Joel

All 1200 parameters are changeable at run time without having to recompile the source code.

Please use mission planner software to configure the parameters

Thank you for this information however, how do I get the value of the parameters inside the AP_GPS.cpp file?

My issue is that I do not know how to get the value of the parameters in the source code.

Read the source code, it already accesses the values of all the GPS parameters, use that as example. You already foun the correct file, just read it.

Instead of (mis)using existing parameters, I’d recommend adding new parameters.
The wiki explains how to do this here: Adding a New Parameter to Copter — Dev documentation

1 Like

Hi,

I am trying to add the new parameters as per the documentation.

In the AP_GPS_NMEA.h:

public:
<snip>
    static const struct AP_Param::GroupInfo var_info[];
private: 
<snip>
     AP_Int32 _origin_lat;
<snip>

In the AP_GPS_NMEA.cpp:

const AP_Param::GroupInfo AP_GPS_NMEA::var_info[] = {
     // @Param: _LATITUDE
     // @DisplayName: Origin's latitude
     // @Description: Origin's latitude
     // @Units: deg
     // @Increment: 0.000001
     // @Range: -90 90
     // @User: Advanced
     AP_GROUPINFO("_LATITUDE", 0, AP_GPS_NMEA, _origin_lat, 0),
     AP_GROUPEND
};

With these modifications, I can compile the code but from the console of the SITL, I can not see the parameters.

I also added in Parameters.cpp:

const AP_Param::Info var_info[] = {
<snip>
     // NMEA Modification
     // @Group: NMEA_
     // @Path: ../libraries/AP_GPS/AP_GPS_NMEA.cpp
     GOBJECT(nmea, "NMEA", AP_GPS_NMEA),
<snip>
};

Making this modification in the Parameters.cpp, the compiler gives me an error telling me that the AP_GPS_NMEA in GOBJECT is not declared.

I also tried to access any of the parameters of AP_GPS.h from AP_GPS_NMEA.cpp, for example _min_dgps, but all I get is _min_dpgs was not declared in this scope.

What am I missing?

Can someone please help me create a parameter that I can access from within AP_GPS_NMEA.cpp that I can change from Mission Planner ?

Regards,
Joel

Did you skip Steps 1 and 2?

From the documentation:
Step 1: Add the new variable to the top level .h file:

public:
<snip>
    static const struct AP_Param::GroupInfo var_info[];
private: 
<snip>
     AP_Int32 _origin_lat;
<snip>

Step 2: Add the variable to the var_info table in the .cpp file:

const AP_Param::GroupInfo AP_GPS_NMEA::var_info[] = {
     // @Param: _LATITUDE
     // @DisplayName: Origin's latitude
     // @Description: Origin's latitude
     // @Units: deg
     // @Increment: 0.000001
     // @Range: -90 90
     // @User: Advanced
     AP_GROUPINFO("_LATITUDE", 0, AP_GPS_NMEA, _origin_lat, 0),
     AP_GROUPEND
};

Is this what you refer ?

Can you provide with a full example on how I would need to do it? I tried everything the documentation says and I also tried to get the value of the AP_GPS.h parameters but I get that the parameter is not declared in the scope.

I just need to know how to add one parameter as later I will copy the code to generate as many parameters as I need.

Joel

The code you’re looking at is full of examples of parameters which are properly declared and implemented.
I can’t give any better explanation than what is in the wiki. It was written by developers who are much better programmers than me.

I am failing to see that the AP_GPS_NEMA.cpp is getting the value of any parameters.

I want to follow the wiki as I assume how everyone codes but after trying what the wiki says the SITL gives up errors meaning I am doing something wrong that I am failing to see or the wiki is not up to date with the current code so the tutorial in the wiki does not work.

The only thing I am missing is how to access the value of parameters. I could hardcode my modifications but every time I would need to recompile the code and upload it to the drone for each flight.

Also, what is the correct way to get the value of a parameter in the code? (Failed to see an example in the wiki)
From my understanding, it has to be as simple as using the declared parameter name but I only get that this parameter name is not declared in the scope.
For example, the _min_dgps which is declared in AP_GPS.h and AP_GPS_NMEA.h includes AP_GPS.h so it should be in the scope.

Do I understand correctly the workings of the scope or not?

Joel

I’m afraid I can’t answer that question, but perhaps if you post a link to your branch on github someone with sufficient skill will take a look.

ArduPilot reports to who, a companion computer onboard the drone? If yes, will this be helpful? Users experience and result.

Another potential way is using lua script read the param , do the offset and print to GCS (MP) console.

Maybe I wrote it wrong. I meant that the Ardupilot thinks that it is at the place with the offset.
So everything needs to be inside the code no lua or companion computer.

How is it possible without recompile code. Only Pull request, then why the developer need to satisfy ones need to suffer the rest?

From my understanding, this is my first time modifying the source code, if I can create or reuse a latitude and longitude parameter that can be set from mission planner, only I would need to add this value to the NMEA output to apply the offset. Therefore I could change the offset without needing to recompile as the latitude and the longitude are a parameter not a fixed variable.

There are NO reusable latitude and longitude parameter that can be set from mission planner without causing side-effects.

You need to add NEW latitude and longitude parameter that can be set from mission planner and cause the effects you want.

As explained in my previous post, I tried to create new parameters using the documentation as a guide but I got an error telling me that AP_GPS_NMEA in GOBJECT is not declared.

In the AP_GPS_NMEA.h:

public:
<snip>
    static const struct AP_Param::GroupInfo var_info[];
private: 
<snip>
     AP_Int32 _origin_lat;
<snip>

In the AP_GPS_NMEA.cpp:

const AP_Param::GroupInfo AP_GPS_NMEA::var_info[] = {
     // @Param: _LATITUDE
     // @DisplayName: Origin's latitude
     // @Description: Origin's latitude
     // @Units: deg
     // @Increment: 0.000001
     // @Range: -90 90
     // @User: Advanced
     AP_GROUPINFO("_LATITUDE", 0, AP_GPS_NMEA, _origin_lat, 0),
     AP_GROUPEND
};

With these modifications, I can compile the code but from the console of the SITL, I can not see the parameters.

I also added in Parameters.cpp:

const AP_Param::Info var_info[] = {
<snip>
     // NMEA Modification
     // @Group: NMEA_
     // @Path: ../libraries/AP_GPS/AP_GPS_NMEA.cpp
     GOBJECT(nmea, "NMEA", AP_GPS_NMEA),
<snip>
};

Can you guide me a bit better on how to add the new parameters?

Read Adding a New Parameter to Copter — Dev documentation again.