-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '83-implementation-hal-aktorik' into 'master'
Resolve "Implementation HAL Aktorik" Closes #83 See merge request ss21-esep-gruppe-2.3/esep!37
- Loading branch information
Showing
24 changed files
with
987 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* BlinkWorker.cpp | ||
* | ||
* Created on: 30.04.2021 | ||
* Author: jendr | ||
*/ | ||
|
||
#include <../actuators/BlinkWorker.h> | ||
#include <iostream> | ||
#include <memory> | ||
|
||
namespace hal { | ||
|
||
BlinkWorker::BlinkWorker(std::shared_ptr<GPIOWrapper> gpio) : | ||
_gpio { gpio }, _running { true }, _duty_cycle { 1000 }, _color { hal::RED } { | ||
_blink_lock.try_lock(); | ||
} | ||
|
||
void BlinkWorker::run() { | ||
int val = 0; | ||
while (_running) { | ||
_blink_lock.lock(); | ||
_blink_lock.unlock(); | ||
val = !val; | ||
switch (_color) { | ||
case GREEN: | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, | ||
gpio_adresses::AMPEL_GRUEN_1, val); | ||
break; | ||
case YELLOW: | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, | ||
gpio_adresses::AMPEL_GELB_1, val); | ||
break; | ||
default: | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::AMPEL_ROT_1, | ||
val); | ||
break; | ||
} | ||
|
||
std::this_thread::sleep_for (std::chrono::milliseconds(_duty_cycle/2)); | ||
} | ||
} | ||
|
||
void BlinkWorker::stop_loop() { | ||
stop_blinking(); | ||
_blink_lock.unlock(); | ||
_running = false; | ||
} | ||
|
||
void BlinkWorker::set_duty_cycle(const uint32_t milliseconds) { | ||
_duty_cycle = milliseconds; | ||
} | ||
|
||
void BlinkWorker::start_blinking(Color c) { | ||
_color = c; | ||
_blink_lock.try_lock(); | ||
_blink_lock.unlock(); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::AMPEL_GRUEN_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::AMPEL_GELB_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::AMPEL_ROT_1, 0); | ||
} | ||
|
||
void BlinkWorker::stop_blinking() { | ||
_blink_lock.try_lock(); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::AMPEL_GRUEN_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::AMPEL_GELB_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::AMPEL_ROT_1, 0); | ||
} | ||
|
||
BlinkWorker::~BlinkWorker() { | ||
_running = false; | ||
_blink_lock.try_lock(); | ||
_blink_lock.unlock(); | ||
} | ||
|
||
} /* namespace hal */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* BlinkWorker.h | ||
* | ||
* Created on: 30.04.2021 | ||
* Author: jendr | ||
*/ | ||
|
||
#ifndef SRC_ACTUATORS_BLINKWORKER_H_ | ||
#define SRC_ACTUATORS_BLINKWORKER_H_ | ||
|
||
#include <mutex> | ||
#include <thread> | ||
#include "../gpiowrapper.h" | ||
#include "color.h" | ||
#include <chrono> | ||
|
||
namespace hal { | ||
|
||
class BlinkWorker { | ||
public: | ||
BlinkWorker(std::shared_ptr<GPIOWrapper>); | ||
BlinkWorker(const BlinkWorker&); | ||
void run(); | ||
void set_duty_cycle(const uint32_t milliseconds = 1000); | ||
void start_blinking(Color); | ||
void stop_blinking(); | ||
void stop_loop(); | ||
virtual ~BlinkWorker(); | ||
|
||
private: | ||
std::shared_ptr<GPIOWrapper> _gpio; | ||
bool _running; | ||
useconds_t _duty_cycle; | ||
hal::Color _color; | ||
std::mutex _blink_lock; | ||
|
||
}; | ||
|
||
} /* namespace hal */ | ||
|
||
#endif /* SRC_ACTUATORS_BLINKWORKER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* cb_motor.cpp | ||
* | ||
* Created on: 28.04.2021 | ||
* Author: Justin Hoffmann | ||
*/ | ||
|
||
#include "../actuators/cb_motor.h" | ||
|
||
namespace hal { | ||
|
||
CBMotor::CBMotor(std::shared_ptr<GPIOWrapper> gpio) { | ||
_gpio = gpio; | ||
} | ||
|
||
void CBMotor::set_direction(Direction direction) { | ||
switch(direction){ | ||
case FAST_FORWARDS: | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_STOP_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LANGSAM_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LINKS_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_RECHTS_1, 1); | ||
break; | ||
case SLOW_FORWARDS: | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_STOP_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LINKS_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LANGSAM_1, 1); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_RECHTS_1, 1); | ||
break; | ||
case FAST_BACKWARDS: | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_STOP_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LANGSAM_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_RECHTS_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LINKS_1, 1); | ||
break; | ||
case SLOW_BACKWARDS: | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_STOP_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_RECHTS_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LANGSAM_1, 1); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LINKS_1, 1); | ||
break; | ||
default: | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LANGSAM_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_LINKS_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_RECHTS_1, 0); | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::MOTOR_STOP_1, 1); | ||
} | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* cb_motor.h | ||
* | ||
* Created on: 28.04.2021 | ||
* Author: Justin Hoffmann | ||
*/ | ||
|
||
#ifndef SRC_ACTUATORS_CB_MOTOR_H_ | ||
#define SRC_ACTUATORS_CB_MOTOR_H_ | ||
|
||
#include "../gpiowrapper.h" | ||
#include <memory> | ||
|
||
namespace hal { | ||
|
||
enum Direction { | ||
FAST_FORWARDS = 0, SLOW_FORWARDS, STOP, SLOW_BACKWARDS, FAST_BACKWARDS | ||
}; | ||
|
||
class CBMotor { | ||
private: | ||
std::shared_ptr<GPIOWrapper> _gpio; | ||
|
||
public: | ||
CBMotor(std::shared_ptr<GPIOWrapper>); | ||
virtual ~CBMotor() = default; | ||
void set_direction(Direction); | ||
}; | ||
|
||
} | ||
|
||
#endif /* SRC_ACTUATORS_CB_MOTOR_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef COLOR_H | ||
#define COLOR_H | ||
|
||
namespace hal{ | ||
|
||
enum Color { | ||
GREEN = 0, YELLOW, RED | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* ejector.cpp | ||
* | ||
* Created on: 28.04.2021 | ||
* Author: Justin Hoffmann | ||
*/ | ||
|
||
#include "../actuators/ejector.h" | ||
|
||
namespace hal { | ||
|
||
Ejector::Ejector(std::shared_ptr<GPIOWrapper> gpio) : | ||
SortingMechanism(gpio) { | ||
} | ||
|
||
void Ejector::do_not_discard() const { | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::WEICHE_OEFFNEN_1, | ||
0); | ||
} | ||
|
||
void Ejector::discard() const { | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::WEICHE_OEFFNEN_1, | ||
1); | ||
} | ||
|
||
bool Ejector::is_open() const { | ||
return _gpio->in(gpio_adresses::BANK_INPUT, gpio_adresses::WEICHE_OFFEN_0) | ||
== 0; | ||
} | ||
|
||
void Ejector::reset() const { | ||
_gpio->out(gpio_adresses::BANK_ACTUATOR, gpio_adresses::WEICHE_OEFFNEN_1, | ||
0); | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.