Skip to content

Commit

Permalink
#31 [feat] done for the week :)
Browse files Browse the repository at this point in the history
  • Loading branch information
kianwasabi committed Nov 3, 2023
1 parent 06018f5 commit c1047be
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 40 deletions.
2 changes: 1 addition & 1 deletion car_control_v2/fidl/carcontrol.fidl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface CarControl {

method gearSelectionHeadUnit {
in {
String gearSelection
String gearSelectionHeadUnit
}
out {
Boolean accepted
Expand Down
4 changes: 1 addition & 3 deletions car_control_v2/include/CarControlStubImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ class CarControlStubImpl: public v0_1::commonapi::CarControlStubDefault {
CarControlStubImpl();
virtual ~CarControlStubImpl();
virtual void gearSelectionHeadUnit(const std::shared_ptr<CommonAPI::ClientId> _client,
const std::string& _gear,
const std::string& _gearSelectionHeadUnit,
gearSelectionHeadUnitReply_t _reply);
// virtual void modifyGearAttribute(const std::string& _gear);
// virtual void modifyIndicatorAttribute(const std::string& _indicator);
private:
};

Expand Down
2 changes: 1 addition & 1 deletion car_control_v2/include/PiRacer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class PiRacer
private:
std::string _gear;
std::string _indicator;
double _throttle;
double _steering;
py::object pModule;
py::object pClass;
py::object pInstance;
static PiRacer* _instance;
static std::mutex _mutex;
double _throttle;
protected:
PiRacer();
~PiRacer();
Expand Down
29 changes: 12 additions & 17 deletions car_control_v2/src/CarControlClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

using namespace v0::commonapi;

// void recv_cb(const CommonAPI::CallStatus& callStatus,
// const bool& gearSelectionHeadUnit) {
// std::cout << "Result of asynchronous call of gearSelectionHeadUnit: " << std::endl;
// std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS")
// << std::endl;
// std::cout << " Output values: gear = " << gearSelectionHeadUnit << std::endl;
// }
void recv_cb(const CommonAPI::CallStatus& callStatus, const bool& gearSelectionHeadUnit) {
std::cout << "Result of asynchronous call of gearSelectionHeadUnit: " << std::endl;
std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS")<< std::endl;
std::cout << " Output : " << gearSelectionHeadUnit << std::endl;
}

int main()
{
Expand Down Expand Up @@ -46,18 +44,15 @@ int main()
char c = gears[rand() % arraySize];
std::string random_gear(1, c);
// Asynchronous call to set gear attribute of service
//std::cout << "Call gearSelectionHeadUnit with asynchronous semantics ..." << std::endl;
// std::function<
// void(const CommonAPI::CallStatus&,
// const bool&)> fcb = recv_cb;
// myProxy->gearSelectionHeadUnitAsync(random_gear, fcb);
std::cout << "Call gearSelectionHeadUnit with asynchronous semantics ..." << std::endl;
std::function< void(const CommonAPI::CallStatus&, const bool&)> fcb = recv_cb;
myProxy->gearSelectionHeadUnitAsync(random_gear, fcb, &info);
// Synchronous call
myProxy->gearSelectionHeadUnit(random_gear,callStatus,returnMessage);
myProxy->gearSelectionHeadUnit(random_gear,callStatus,returnMessage,&info);
std::cout << "Result of synchronous call: " << std::endl;
std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS")
<< std::endl;
std::cout << " Input values: " << random_gear << std::endl;
std::cout << " Output values:" << returnMessage << std::endl;
std::cout << " callStatus: " << ((callStatus == CommonAPI::CallStatus::SUCCESS) ? "SUCCESS" : "NO_SUCCESS") << std::endl;
std::cout << " Input: " << random_gear << std::endl;
std::cout << " Output: " << returnMessage << std::endl;
// wait for 5 seconds
std::this_thread::sleep_for(std::chrono::seconds(5));
}
Expand Down
18 changes: 4 additions & 14 deletions car_control_v2/src/CarControlStubImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,19 @@ CarControlStubImpl::~CarControlStubImpl() {
}
/*can be invoked by client */
void CarControlStubImpl::gearSelectionHeadUnit(const std::shared_ptr<CommonAPI::ClientId> _client,
const std::string &_gear,
const std::string &_gearSelectionHeadUnit,
gearSelectionHeadUnitReply_t _reply)
{
std::cout << "gearSelectionHeadUnit() called by client." << std::endl;
std::cout << "setting new gear: " << _gear << std::endl;
std::cout << " Input: " << _gearSelectionHeadUnit << std::endl;

PiRacer* piracer = PiRacer::getInstance();
PyGILState_STATE gilState = PyGILState_Ensure();
bool accepted = piracer->setGear(_gear);
bool accepted = piracer->setGear(_gearSelectionHeadUnit);
if(accepted) {
setGearAttribute(_gear);
setGearAttribute(_gearSelectionHeadUnit);
}
PyGILState_Release(gilState);

_reply(accepted);
}

// void CarControlStubImpl::modifyGearAttribute(const std::string &_gear)
// {
// setGearAttribute(_gear);
// }

// void CarControlStubImpl::modifyIndicatorAttribute(const std::string &_indicator)
// {
// setIndicatorAttribute(_indicator);
// }
8 changes: 4 additions & 4 deletions car_control_v2/src/PiRacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ const std::string& PiRacer::getIndicator()

bool PiRacer::setGear(const std::string& gear)
{
// std::lock_guard<std::mutex> lock(_mutex);
//std::cout << "Abs throttel: " << abs(_throttle) << std::endl;
if (abs(_throttle) >= 0.01)
return false;
_gear = gear;
std::cout << "PiRacer - Gear set to: " << _gear << std::endl;
//std::cout << "PiRacer - Gear set to: " << _gear << std::endl;
py::object setThrottle = pInstance.attr("set_throttle_percent");
setThrottle(0.0);
return true;
Expand All @@ -82,13 +82,13 @@ bool PiRacer::setIndicator(const std::string& indicator)
if (_indicator == indicator)
return false;
_indicator = indicator;
std::cout << "PiRacer - Indicator set to: " << indicator << std::endl;
//std::cout << "PiRacer - Indicator set to: " << indicator << std::endl;
return true;
}

bool PiRacer::setThrottle(const double& throttle)
{
if (_gear == "P" || _gear == "N")
if ((_gear == "P" || _gear == "N"))
return false;
if (_gear == "D" && throttle < -0.1)
return false;
Expand Down

0 comments on commit c1047be

Please sign in to comment.