Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Actuate all three motors of the seat #114

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ed73393
Cange ECU1 to ECU2 to address seat forward backward motor
lukasmittag Nov 21, 2023
23adbc2
Ecu Reset script new
lukasmittag Dec 12, 2023
2113bc5
Not fully completed implementation for all three motors
lukasmittag Dec 12, 2023
30e9e41
Fix float issue
lukasmittag Jan 10, 2024
2e042ab
Typo fix
lukasmittag Jan 10, 2024
b0677fc
Fix loop logic and minor typos
lukasmittag Jan 17, 2024
6116589
Extend CANSIM for ECU2(back/forth,tilt)
lukasmittag Jan 17, 2024
2de3381
Document known issues with implementation
lukasmittag Jan 17, 2024
f2ad708
Fix tests for seat service all three motors
lukasmittag Jan 22, 2024
1dc5899
Fix in API test too
lukasmittag Jan 22, 2024
de7de6f
Fix in API test timestamp check
lukasmittag Jan 22, 2024
fcc8290
Fix in API test handle secu stat call
lukasmittag Jan 22, 2024
aad0f8b
Fix in API test call to ecu loop
lukasmittag Jan 22, 2024
6e2dd0a
Fix in API test secu2_stat_pack
lukasmittag Jan 22, 2024
deec902
Take dbc configured dlc
lukasmittag Jan 22, 2024
5a8ed8d
Change dlc for ecu2 to 5
lukasmittag Jan 22, 2024
d51f5e9
Change dlc to default value
lukasmittag Jan 22, 2024
936978f
Fix SECU2_CMD_1 RealSeat motor direction in seat_ecu.dbc
chheis Jan 22, 2024
82ff5fe
Cansim for switching DIR && dbc config fix representing in code
lukasmittag Jan 23, 2024
53a8861
Fix conversion of directions
lukasmittag Jan 24, 2024
1b1ddfd
Fix DBC file (again)
lukasmittag Jan 24, 2024
f6d4437
Fix DBC file values not comments
lukasmittag Jan 24, 2024
5268c4f
missing return statement in controll loop
lukasmittag Jan 24, 2024
e00ed2f
Fix RPM values for tilt and position
lukasmittag Jan 24, 2024
f7dc0b4
Update Cansim to represent seat and fix ecu-reset
lukasmittag Jan 25, 2024
3fea27e
Fix&extend tests for all three directions
lukasmittag Feb 6, 2024
7a0d41e
Fix cmake for cansim & adapt timeouts
lukasmittag Feb 7, 2024
32f4069
Change to use VSS 4 again
lukasmittag Feb 8, 2024
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
8 changes: 4 additions & 4 deletions integration_test/test_val_seat.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ async def test_vdb_metadata_get(setup_helper: VDBHelper) -> None:


@pytest.mark.asyncio
async def test_subscribe_seat_pos_0(setup_helper: VDBHelper) -> None:
async def test_subscribe_seat_pos_10(setup_helper: VDBHelper) -> None:
helper: VDBHelper = setup_helper
name = os.getenv("TEST_NAME", DEFAULT_VSS_PATH)
query = "SELECT {}".format(name)

start_value = int(os.getenv("TEST_START_VALUE", "500"))
expected_value = int(os.getenv("TEST_VALUE", "0"))
expected_value = int(os.getenv("TEST_VALUE", "10"))
timeout = int(os.getenv("TEST_TIMEOUT", "10"))

# initiate seat move to 42
Expand Down Expand Up @@ -161,8 +161,8 @@ async def test_subscribe_seat_pos_where_eq(setup_helper: VDBHelper) -> None:
helper = setup_helper

name = os.getenv("TEST_NAME", DEFAULT_VSS_PATH)
expected_value = int(os.getenv("TEST_VALUE", "1000"))
timeout = int(os.getenv("TEST_TIMEOUT", "10"))
expected_value = int(os.getenv("TEST_VALUE", "990"))
timeout = int(os.getenv("TEST_TIMEOUT", "20"))

query = "SELECT {} where {} = {}".format(name, name, expected_value)

Expand Down
2 changes: 1 addition & 1 deletion seat_service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,4 @@ check [SeatController README](./src/lib/seat_adjuster/seat_controller/README.md)
```

- The output will be stored to ``./docs/out``. You can watch the documentation with open the following file in the browser:
`./docs/doxygen/out/html/index.html`
`./docs/doxygen/out/html/index.html`
2 changes: 1 addition & 1 deletion seat_service/build-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ cmake --build . -j $(nproc)
cmake --install .
set +e

# Ensure release is sripped
# Ensure release is stripped
if [ "$TARGET_ARCH" = "aarch64" ]; then
STRIP="$(which aarch64-linux-gnu-strip)"
else
Expand Down
58 changes: 53 additions & 5 deletions seat_service/src/bin/seat_service/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ using sdv::databroker::v1::ChangeType;

const std::string SEAT_POS_VSS_3 = "Vehicle.Cabin.Seat.Row1.Pos1.Position";
const std::string SEAT_POS_VSS_4 = "Vehicle.Cabin.Seat.Row1.DriverSide.Position";
const std::string SEAT_TILT_VSS_3 = "Vehicle.Cabin.Seat.Row1.Pos1.Tilt";
const std::string SEAT_TILT_VSS_4 = "Vehicle.Cabin.Seat.Row1.DriverSide.Tilt";
const std::string SEAT_HEIGHT_VSS_3 = "Vehicle.Cabin.Seat.Row1.Pos1.Height";
const std::string SEAT_HEIGHT_VSS_4 = "Vehicle.Cabin.Seat.Row1.DriverSide.Height";

const sdv::broker_feeder::DatapointConfiguration metadata_4 {
{ SEAT_POS_VSS_4,
Expand All @@ -57,6 +61,20 @@ const sdv::broker_feeder::DatapointConfiguration metadata_4 {
sdv::broker_feeder::createNotAvailableValue(),
"Seat position on vehicle x-axis. Position is relative to the frontmost position supported by the seat. 0 = Frontmost position supported."
},
{ SEAT_TILT_VSS_4,
DataType::FLOAT,
// EntryType::ENTRY_TYPE_ACTUATOR, // entry type can't be set with current API
ChangeType::ON_CHANGE,
sdv::broker_feeder::createNotAvailableValue(),
"Tilting of seat (seating and backrest) relative to vehicle x-axis. 0 = seat bottom is flat, seat bottom and vehicle x-axis are parallel. Positive degrees = seat tilted backwards, seat x-axis tilted upward, seat z-axis is tilted backward."
},
{ SEAT_HEIGHT_VSS_4,
DataType::UINT16,
// EntryType::ENTRY_TYPE_ACTUATOR, // entry type can't be set with current API
ChangeType::ON_CHANGE,
sdv::broker_feeder::createNotAvailableValue(),
"Seat position on vehicle z-axis. Position is relative within available movable range of the seating. 0 = Lowermost position supported."
},
{ "Vehicle.Cabin.SeatRowCount",
DataType::UINT8,
// EntryType::ENTRY_TYPE_ATTRIBUTE,
Expand All @@ -79,6 +97,20 @@ const sdv::broker_feeder::DatapointConfiguration metadata_3 {
sdv::broker_feeder::createNotAvailableValue(),
"Longitudinal position of overall seat"
},
{ SEAT_TILT_VSS_3,
DataType::FLOAT,
// EntryType::ENTRY_TYPE_ACTUATOR, // entry type can't be set with current API
ChangeType::ON_CHANGE,
sdv::broker_feeder::createNotAvailableValue(),
"Tilting of seat (seating and backrest) relative to vehicle x-axis. 0 = seat bottom is flat, seat bottom and vehicle x-axis are parallel. Positive degrees = seat tilted backwards, seat x-axis tilted upward, seat z-axis is tilted backward."
},
{ SEAT_HEIGHT_VSS_3,
DataType::UINT16,
// EntryType::ENTRY_TYPE_ACTUATOR, // entry type can't be set with current API
ChangeType::ON_CHANGE,
sdv::broker_feeder::createNotAvailableValue(),
"Seat position on vehicle z-axis. Position is relative within available movable range of the seating. 0 = Lowermost position supported."
},
{ "Vehicle.Cabin.SeatRowCount",
DataType::UINT8,
// EntryType::ENTRY_TYPE_ATTRIBUTE,
Expand Down Expand Up @@ -154,9 +186,11 @@ void Run(std::string can_if_name, std::string listen_address, std::string port,
sdv::broker_feeder::DatapointConfiguration metadata = vss_4 ? metadata_4 : metadata_3;

std::string seat_pos_name = vss_4 ? SEAT_POS_VSS_4 : SEAT_POS_VSS_3;
std::string seat_tilt_name = vss_4 ? SEAT_TILT_VSS_4 : SEAT_TILT_VSS_3;
std::string seat_height_name = vss_4 ? SEAT_HEIGHT_VSS_4 : SEAT_HEIGHT_VSS_3;

// runtime check for valid 1st entry name
if (metadata.size() < 1 || seat_pos_name != metadata[0].name) {
if (metadata.size() < 1 || seat_pos_name != metadata[0].name || seat_tilt_name != metadata[1].name || seat_height_name != metadata[2].name) {
std::cerr << SELF "Invalid metadata configuration!" << std::endl;
exit(1);
}
Expand All @@ -166,16 +200,26 @@ void Run(std::string can_if_name, std::string listen_address, std::string port,

// Setup feeder
//
sdv::seat_service::SeatDataFeeder seat_data_feeder(seat_adjuster, client, seat_pos_name, std::move(metadata));
sdv::seat_service::SeatDataFeeder seat_data_feeder(seat_adjuster, client, seat_pos_name, seat_tilt_name, seat_height_name, std::move(metadata));
std::cout << SELF "SeatDataFeeder connecting to " << broker_addr << std::endl;
std::thread feeder_thread(&sdv::seat_service::SeatDataFeeder::Run, &seat_data_feeder);


// Setup target actuator subscriber
sdv::seat_service::SeatPositionSubscriber seat_position_subscriber(seat_adjuster, client, seat_pos_name);
sdv::seat_service::SeatPositionSubscriber seat_position_subscriber(seat_adjuster, client, seat_pos_name, sdv::seat_service::posSub::POSITION);
std::cout << SELF "Start seat position subscription " << broker_addr << std::endl;

std::thread subscriber_thread(&sdv::seat_service::SeatPositionSubscriber::Run, &seat_position_subscriber);
// Setup target actuator subscriber
sdv::seat_service::SeatPositionSubscriber seat_tilt_subscriber(seat_adjuster, client, seat_tilt_name, sdv::seat_service::posSub::TILT);
std::cout << SELF "Start seat tilt subscription " << broker_addr << std::endl;

// Setup target actuator subscriber
sdv::seat_service::SeatPositionSubscriber seat_height_subscriber(seat_adjuster, client, seat_height_name, sdv::seat_service::posSub::HEIGHT);
std::cout << SELF "Start seat height subscription " << broker_addr << std::endl;

std::thread subscriber1_thread(&sdv::seat_service::SeatPositionSubscriber::Run, &seat_position_subscriber);
std::thread subscriber2_thread(&sdv::seat_service::SeatPositionSubscriber::Run, &seat_tilt_subscriber);
std::thread subscriber3_thread(&sdv::seat_service::SeatPositionSubscriber::Run, &seat_height_subscriber);

// Setup grpc server and register the services
//
Expand Down Expand Up @@ -204,11 +248,15 @@ void Run(std::string can_if_name, std::string listen_address, std::string port,

seat_data_feeder.Shutdown();
seat_position_subscriber.Shutdown();
seat_tilt_subscriber.Shutdown();
seat_height_subscriber.Shutdown();
if (server) {
server->Shutdown();
server_thread->join();
}
subscriber_thread.join();
subscriber1_thread.join();
subscriber2_thread.join();
subscriber3_thread.join();
feeder_thread.join();

// Optional: Delete all global objects allocated by libprotobuf.
Expand Down
70 changes: 69 additions & 1 deletion seat_service/src/bin/seat_service/seat_data_feeder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const sdv::broker_feeder::DatapointConfiguration metadata_3 {
*/

SeatDataFeeder::SeatDataFeeder(std::shared_ptr<SeatAdjuster> seat_adjuster, std::shared_ptr<broker_feeder::KuksaClient> collector_client,
std::string& seat_pos_name, DatapointConfiguration&& dpConfig)
std::string& seat_pos_name, std::string& seat_tilt_name, std::string& seat_height_name, DatapointConfiguration&& dpConfig)
: seat_adjuster_(seat_adjuster)
{
/* Init feeder
Expand All @@ -95,6 +95,7 @@ SeatDataFeeder::SeatDataFeeder(std::shared_ptr<SeatAdjuster> seat_adjuster, std:

/* Internally subscribe to signals to be fed to broker
*/
// handle forward motor position
seat_adjuster_->SubscribePosition([this, seat_pos_name](int position_in_percent) {
const std::string self = "[SeatSvc][SeatDataFeeder] ";
if (debug > 1) { // require more verbose for extra dump
Expand Down Expand Up @@ -127,6 +128,73 @@ SeatDataFeeder::SeatDataFeeder(std::shared_ptr<SeatAdjuster> seat_adjuster, std:
}
broker_feeder_->FeedValue(seat_pos_name, datapoint);
});

// handle tilt motor position
seat_adjuster_->SubscribeTilt([this, seat_tilt_name](int position_in_percent) {
const std::string self = "[SeatSvc][SeatDataFeeder] ";
if (debug > 1) { // require more verbose for extra dump
std::cout << self << "got pos: " << position_in_percent << "%" << std::endl;
}
Datapoint datapoint;
if (0 <= position_in_percent && position_in_percent <= 100) {
datapoint.set_float_value(static_cast<float>(position_in_percent * 10)); // scale up to [0..1000]
} else
if (position_in_percent == -1) { // -1 replaces MOTOR_POS_INVALID in SeatAdjusterImpl::seatctrl_event_cb()
datapoint.set_failure_value(Datapoint_Failure::Datapoint_Failure_NOT_AVAILABLE);
} else {
// values > 100 are invalid
datapoint.set_failure_value(Datapoint_Failure::Datapoint_Failure_INVALID_VALUE);
}
if (debug) {
if (datapoint.has_failure_value()) {
std::cout << self << "pos: " << position_in_percent << "% -> "
<< "FeedValue(" << seat_tilt_name << ", failure:"
<< Datapoint_Failure_Name(datapoint.failure_value()) << ")" << std::endl;
} else
if (datapoint.has_float_value()) {
std::cout << self << "pos: " << position_in_percent << "% -> "
<< "FeedValue(" << seat_tilt_name << ", float:" << datapoint.float_value() << ")" << std::endl;
} else {
std::cout << self << "pos: " << position_in_percent << "% -> "
<< "FeedValue(" << seat_tilt_name << ", unknown)" << std::endl;
}
}
broker_feeder_->FeedValue(seat_tilt_name, datapoint);
});

// handle height motor position
seat_adjuster_->SubscribeHeight([this, seat_height_name](int position_in_percent) {
const std::string self = "[SeatSvc][SeatDataFeeder] ";
if (debug > 1) { // require more verbose for extra dump
std::cout << self << "got pos: " << position_in_percent << "%" << std::endl;
}
Datapoint datapoint;
// NOTE: we are using uint32 value as grpc does not have smaller integers
if (0 <= position_in_percent && position_in_percent <= 100) {
datapoint.set_uint32_value(position_in_percent * 10); // scale up to [0..1000]
} else
if (position_in_percent == -1) { // -1 replaces MOTOR_POS_INVALID in SeatAdjusterImpl::seatctrl_event_cb()
datapoint.set_failure_value(Datapoint_Failure::Datapoint_Failure_NOT_AVAILABLE);
} else {
// values > 100 are invalid
datapoint.set_failure_value(Datapoint_Failure::Datapoint_Failure_INVALID_VALUE);
}
if (debug) {
if (datapoint.has_failure_value()) {
std::cout << self << "pos: " << position_in_percent << "% -> "
<< "FeedValue(" << seat_height_name << ", failure:"
<< Datapoint_Failure_Name(datapoint.failure_value()) << ")" << std::endl;
} else
if (datapoint.has_uint32_value()) {
std::cout << self << "pos: " << position_in_percent << "% -> "
<< "FeedValue(" << seat_height_name << ", uint32:" << datapoint.uint32_value() << ")" << std::endl;
} else {
std::cout << self << "pos: " << position_in_percent << "% -> "
<< "FeedValue(" << seat_height_name << ", unknown)" << std::endl;
}
}
broker_feeder_->FeedValue(seat_height_name, datapoint);
});
}
void SeatDataFeeder::Run() { broker_feeder_->Run(); }
void SeatDataFeeder::Shutdown() { broker_feeder_->Shutdown(); }
Expand Down
2 changes: 2 additions & 0 deletions seat_service/src/bin/seat_service/seat_data_feeder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class SeatDataFeeder {
SeatDataFeeder(std::shared_ptr<SeatAdjuster>,
std::shared_ptr<sdv::broker_feeder::KuksaClient> collector_client,
std::string& seat_pos_name,
std::string& seat_tilt_name,
std::string& seat_height_name,
sdv::broker_feeder::DatapointConfiguration&& dpConfig);
/**
* Starts the feeder trying to connect to the data broker, registering data points
Expand Down
44 changes: 42 additions & 2 deletions seat_service/src/bin/seat_service/seat_position_subscriber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string>
#include <sstream>
#include <thread>
#include <mutex>

#include "kuksa_client.h"
#include "seat_adjuster.h"
Expand All @@ -31,12 +32,15 @@ extern int debug;
namespace sdv {
namespace seat_service {

std::mutex seat_adjuster_mutex;

SeatPositionSubscriber::SeatPositionSubscriber(std::shared_ptr<SeatAdjuster> seat_adjuster,
std::shared_ptr<broker_feeder::KuksaClient> kuksa_client,
const std::string& seat_pos_name)
const std::string& seat_pos_name, const sdv::seat_service::posSub& pos)
: seat_adjuster_(seat_adjuster)
, kuksa_client_(kuksa_client)
, seat_pos_name_(seat_pos_name)
, pos_(pos)
, running_(false)
{
/* Define datapoints (metadata) of seat service */
Expand Down Expand Up @@ -98,7 +102,43 @@ void SeatPositionSubscriber::Run() {

int position_in_percent = (position + 5) / 10;

seat_adjuster_->SetSeatPosition(position_in_percent);
std::lock_guard<std::mutex> guard(seat_adjuster_mutex);
switch(pos_){
case posSub::POSITION:
seat_adjuster_->SetSeatPosition(position_in_percent);
break;
case posSub::TILT:
seat_adjuster_->SetSeatTilt(position_in_percent);
break;
case posSub::HEIGHT:
seat_adjuster_->SetSeatHeight(position_in_percent);
break;
}
break;
}
case sdv::databroker::v1::Datapoint::ValueCase::kFloatValue: {
auto position = static_cast<unsigned int>(actuator_target.float_());
std::cout << "SeatPositionSubscriber: Got actuator target: " << position << std::endl;
if (position < 0 || 1000 < position) {
std::cout << "Invalid position" << std::endl;
continue;
}

int position_in_percent = (position + 5) / 10;

std::lock_guard<std::mutex> guard(seat_adjuster_mutex);
switch(pos_){
case posSub::POSITION:
seat_adjuster_->SetSeatPosition(position_in_percent);
break;
case posSub::TILT:
seat_adjuster_->SetSeatTilt(position_in_percent);
break;
case posSub::HEIGHT:
seat_adjuster_->SetSeatHeight(position_in_percent);
break;
}
break;
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion seat_service/src/bin/seat_service/seat_position_subscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,17 @@ class KuksaClient;

namespace seat_service {

enum class posSub{
POSITION,
TILT,
HEIGHT
};

class SeatPositionSubscriber {
public:
SeatPositionSubscriber(std::shared_ptr<SeatAdjuster>,
std::shared_ptr<broker_feeder::KuksaClient> kuksa_client,
const std::string& seat_pos_name);
const std::string& seat_pos_name, const sdv::seat_service::posSub& pos);
/**
* Starts the subscriber.
* Note: This function will block the calling thread until it's terminated by
Expand All @@ -62,6 +68,7 @@ class SeatPositionSubscriber {
std::shared_ptr<broker_feeder::KuksaClient> kuksa_client_;
std::unique_ptr<grpc::ClientContext> subscriber_context_;
std::string seat_pos_name_;
sdv::seat_service::posSub pos_;

std::atomic_bool running_;
};
Expand Down
2 changes: 1 addition & 1 deletion seat_service/src/examples/can_send/can_send.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(int argc, char* argv[]) {
sdv::hal::CanRawSocket can_if("vcan0");

sdv::hal::CanFrame frame = {
.can_id = 0x712,
.can_id = 0x714,
.data = {0x1, 0x50, 20, 0, 0, 0, 0, 0},
};

Expand Down
Loading
Loading