Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Generator: Add error code LUA binding #27375

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions libraries/AP_Generator/AP_Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ bool AP_Generator::run()
return _driver_ptr->run();
}

int AP_Generator::get_errorcode()
{
// Return 0 if no driver
if (_driver_ptr == nullptr) {
return 0;
}
return _driver_ptr->get_errorcode();
}

// Get the AP_Generator singleton
AP_Generator *AP_Generator::get_singleton()
{
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Generator/AP_Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class AP_Generator
bool idle(void);
bool run(void);

// error code returns 0 if no error or the error code return function is not implemented
int get_errorcode(void);

void send_generator_status(const class GCS_MAVLINK &channel);

// Parameter block
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Generator/AP_Generator_Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class AP_Generator_Backend
virtual bool idle(void) { return false; }
virtual bool run(void) { return false; }

// Error code returns 0 if no error or the error code return function is not implemented
virtual int get_errorcode(void) {return 0;}

// Use generator mavlink message
virtual void send_generator_status(const GCS_MAVLINK &channel) {}

Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Generator/AP_Generator_IE_FuelCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class AP_Generator_IE_FuelCell : public AP_Generator_Backend
// Update fuel cell, expected to be called at 20hz
void update(void) override;

// Allow generator error code to pass up to frontend and export to LUA
int get_errorcode(void) override {return _err_code;}

protected:

// Pointer to serial uart
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_Generator/AP_Generator_RichenPower.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class AP_Generator_RichenPower : public AP_Generator_Backend
// healthy returns true if the generator is not present, or it is
// present, providing telemetry and not indicating an errors.
bool healthy() const override;

// Allow generator error code to pass up to fronten and export to LUA
int get_errorcode(void) override {return last_reading.errors;}

private:

Expand Down
8 changes: 8 additions & 0 deletions libraries/AP_Scripting/docs/docs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3571,3 +3571,11 @@ function visual_odom:healthy() end
-- visual odometry quality as a percentage from 1 to 100 or 0 if unknown
---@return integer
function visual_odom:quality() end

--Gnerator object
--@class generator
generator = {}

-- returns the generator error code
--- @return integer
function generator:get_errorcode() end
5 changes: 5 additions & 0 deletions libraries/AP_Scripting/generator/description/bindings.desc
Original file line number Diff line number Diff line change
Expand Up @@ -955,3 +955,8 @@ singleton AP_VisualOdom depends HAL_VISUALODOM_ENABLED
singleton AP_VisualOdom rename visual_odom
singleton AP_VisualOdom method healthy boolean
singleton AP_VisualOdom method quality int8_t

include AP_Generator/AP_Generator.h
singleton AP_Generator depends HAL_GENERATOR_ENABLED
singleton AP_Generator rename generator
singleton AP_Generator method get_errorcode int8_t
Loading