Skip to content

Commit

Permalink
Add generator error code binding to LUA
Browse files Browse the repository at this point in the history
  • Loading branch information
EosBandi committed Jun 24, 2024
1 parent 5ab2aaf commit df1e864
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ArduCopter/Generator_test/scripts/gentest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

function update()

local errorcode = generator:get_errorcode()
gcs:send_text(0, "LUA: Error code: " .. errorcode)

return update, 1000
end

return update()
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
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

0 comments on commit df1e864

Please sign in to comment.