Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AX-12A by
Diff: AX12.cpp
- Revision:
- 7:155ecc801119
- Parent:
- 6:a702043b1420
- Child:
- 8:b6979be5a0a7
--- a/AX12.cpp Tue Dec 29 23:31:19 2015 +0000 +++ b/AX12.cpp Thu Dec 31 17:47:43 2015 +0000 @@ -13,6 +13,7 @@ _LastTemperature = 0; _LastVoltage = 0; _LastError = 0; + _LastLoad = 0; } /*****/ @@ -156,6 +157,34 @@ } } +/*****/ + +float AX12::GetLoad(void) +{ + _LastError = statusValid; + CommBuffer data; + StatusCode s = _pbus->Read(_ID, ctPresentLoadL, 2, data); + if( s == statusValid ) + { + int16_t value = data[0] | (data[1] << 8); + _LastLoad = (float)(value & 0x03ff); + return _LastLoad; + } + else + { + // try again one time + s = _pbus->Read(_ID, ctPresentLoadL, 2, data); + if( s == statusValid ) + { + int16_t value = data[0] | (data[1] << 8); + _LastLoad = (float)(value & 0x03ff); + return _LastLoad; + } + _LastError = s; + return 0.0f; + } +} + StatusCode AX12::TorqueEnable(bool enable) { _LastError = statusValid; @@ -179,6 +208,9 @@ case NM_Voltage: return true; + case NM_Load: + return true; + default: return false; } @@ -197,6 +229,9 @@ case NM_Voltage: return GetSupplyVoltage(); + case NM_Load: + return GetLoad(); + default: return 0.0f; } @@ -215,6 +250,9 @@ case NM_Voltage: return _LastVoltage; + case NM_Load: + return _LastLoad; + default: return 0.0f; }