Skip to content

Commit

Permalink
Make state observer ignore fault bit
Browse files Browse the repository at this point in the history
At first, bit 3 of statusword is reset upon RESET_FAULT transition.
Then, either fault state is entered again if error is still present (I
did not check this), or SWITCH_ON_DISABLED state is reached and reported
by the next statusword event.
  • Loading branch information
PeterBowman committed Jan 16, 2020
1 parent 988ed20 commit 304ea6d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion libraries/CanBusSharerLib/DriveStatusMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ namespace

bool DriveStatusMachine::update(std::uint16_t statusword)
{
static const word_t statuswordMask("0000000001101111"); // state machine-related bits
// state machine-related bits (at least those we can transition to)
static const word_t statuswordMask("0000000001100111");

std::lock_guard<std::mutex> lock(stateMutex);
const word_t old = _statusword;
Expand Down
9 changes: 5 additions & 4 deletions tests/testCanBusSharerLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class CanBusSharerTest : public testing::Test
return *f;
}

static constexpr double TIMEOUT = 0.1; // [s]
static constexpr double TIMEOUT = 0.125; // [s]
static constexpr int MILLIS = 50;

private:
Expand Down Expand Up @@ -912,13 +912,13 @@ TEST_F(CanBusSharerTest, DriveStatusMachine)
ASSERT_EQ(status.statusword(), faultReactionActive);
ASSERT_EQ(status.getCurrentState(), DriveState::FAULT_REACTION_ACTIVE);
ASSERT_EQ(DriveStatusMachine::parseStatusword(faultReactionActive), DriveState::FAULT_REACTION_ACTIVE);
ASSERT_EQ(status.controlword(), 0x0000);
// controlword doesn't change

ASSERT_TRUE(status.update(fault));
ASSERT_EQ(status.statusword(), fault);
ASSERT_EQ(status.getCurrentState(), DriveState::FAULT);
ASSERT_EQ(DriveStatusMachine::parseStatusword(fault), DriveState::FAULT);
ASSERT_EQ(status.controlword(), 0x0000);
// controlword doesn't change

// test random controlword commands

Expand Down Expand Up @@ -1058,7 +1058,8 @@ TEST_F(CanBusSharerTest, DriveStatusMachine)
// test FAULT -> SWITCH_ON_DISABLED (transition 15: FAULT_RESET)

ASSERT_TRUE(status.update(fault));
f() = std::async(std::launch::async, observer_timer{MILLIS, [&]{ return status.update(switchOnDisabled); }});
f() = std::async(std::launch::async, observer_timer{MILLIS, [&]{ return status.update(notReadyToSwitchOn); }}); // fault state resets
f() = std::async(std::launch::async, observer_timer{MILLIS * 2, [&]{ return status.update(switchOnDisabled); }});
ASSERT_TRUE(status.requestTransition(DriveTransition::FAULT_RESET));
ASSERT_EQ(getSender()->getLastMessage().id, rpdo.getCobId());
ASSERT_EQ(getSender()->getLastMessage().len, 2);
Expand Down

0 comments on commit 304ea6d

Please sign in to comment.