Skip to content

Commit

Permalink
Ground leds Brightness control parameter included
Browse files Browse the repository at this point in the history
  • Loading branch information
musalman709 committed Mar 2, 2020
1 parent 538c532 commit 1f2254f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace argos {
CCI_EPuckGroundLEDsActuator::CCI_EPuckGroundLEDsActuator() {
m_unLEDSettingsD1ToD8 = 0;
m_unLEDSettingsD9 = 0;
m_unPWMGroundLED = 0;
}

/****************************************/
Expand Down Expand Up @@ -100,16 +101,8 @@ namespace argos {
m_unLEDSettingsD9 = 0; // (x x x x x x x 0)
}


}

// for(size_t i=0; i<=un_number_of_leds-1; i++){
// if(un_number_of_leds - 1 <= 7){
// m_unLEDSettingsD1ToD8 |= (1 << i);
// }else if(un_number_of_leds - 1 == 8){
// m_unLEDSettingsD9 |= (1 << 0);
// }
// }
}

/****************************************/
Expand Down Expand Up @@ -138,5 +131,21 @@ namespace argos {

UInt8 CCI_EPuckGroundLEDsActuator::GetD9(){
return m_unLEDSettingsD9;

}

/****************************************/
/****************************************/

void CCI_EPuckGroundLEDsActuator::SetPWM(UInt8 un_PWM_Ground_LED){
m_unPWMGroundLED = un_PWM_Ground_LED;
}

/****************************************/
/****************************************/

UInt8 CCI_EPuckGroundLEDsActuator::GetPWM(){
return m_unPWMGroundLED;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ namespace argos {

UInt8 GetD9();

virtual void SetPWM(UInt8 un_PWM_Ground_LED);

UInt8 GetPWM();




protected:

Expand All @@ -77,6 +83,12 @@ namespace argos {
* State of the 9th LED (8 bits, LSB for 9th LED, 0 for off, 1 for on)
*/
UInt8 m_unLEDSettingsD9;

/**
* PWM value for ground LEDs
*/
UInt8 m_unPWMGroundLED;

};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum GLEDsRegisters {
};

enum DriverParameters{
DRIVER_PWM = 230 // @param DRIVER_PWM Can be modified to set the brightness [0 - 255]
DRIVER_PWM = 220 // @param DRIVER_PWM Can be modified to set the brightness [0 - 255]
};


Expand Down Expand Up @@ -68,27 +68,38 @@ CRealEPuckGroundLEDsActuator::~CRealEPuckGroundLEDsActuator() {
/***
* Set PWM of each LED
***/
WriteRegister(m_tDeviceStream,REG_D1_PWM,DRIVER_PWM);
WriteRegister(m_tDeviceStream,REG_D2_PWM,DRIVER_PWM);
WriteRegister(m_tDeviceStream,REG_D3_PWM,DRIVER_PWM);
WriteRegister(m_tDeviceStream,REG_D4_PWM,DRIVER_PWM);
WriteRegister(m_tDeviceStream,REG_D5_PWM,DRIVER_PWM);
WriteRegister(m_tDeviceStream,REG_D6_PWM,DRIVER_PWM);
WriteRegister(m_tDeviceStream,REG_D7_PWM,DRIVER_PWM);
WriteRegister(m_tDeviceStream,REG_D8_PWM,DRIVER_PWM);
WriteRegister(m_tDeviceStream,REG_D9_PWM,DRIVER_PWM);
InitPWM(DRIVER_PWM);
}

/****************************************/
/****************************************/

void CRealEPuckGroundLEDsActuator::InitPWM(UInt8 un_PWM_Ground_LED) {
WriteRegister(m_tDeviceStream,REG_D1_PWM,un_PWM_Ground_LED);
WriteRegister(m_tDeviceStream,REG_D2_PWM,un_PWM_Ground_LED);
WriteRegister(m_tDeviceStream,REG_D3_PWM,un_PWM_Ground_LED);
WriteRegister(m_tDeviceStream,REG_D4_PWM,un_PWM_Ground_LED);
WriteRegister(m_tDeviceStream,REG_D5_PWM,un_PWM_Ground_LED);
WriteRegister(m_tDeviceStream,REG_D6_PWM,un_PWM_Ground_LED);
WriteRegister(m_tDeviceStream,REG_D7_PWM,un_PWM_Ground_LED);
WriteRegister(m_tDeviceStream,REG_D8_PWM,un_PWM_Ground_LED);
WriteRegister(m_tDeviceStream,REG_D9_PWM,un_PWM_Ground_LED);
}

/****************************************/
/****************************************/
void CRealEPuckGroundLEDsActuator::SendData() {

WriteRegister(m_tDeviceStream,REG_D1TOD8_OUTPUT_CONTROL,GetD1ToD8());

WriteRegister(m_tDeviceStream,REG_D9_OUTPUT_CONTROL,GetD9());
}

/****************************************/
/****************************************/

void CRealEPuckGroundLEDsActuator::SetPWM(UInt8 un_PWM_Ground_LED){
CCI_EPuckGroundLEDsActuator::SetPWM(un_PWM_Ground_LED);
InitPWM(un_PWM_Ground_LED);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ namespace argos {
CRealEPuckGroundLEDsActuator();
virtual ~CRealEPuckGroundLEDsActuator();

virtual void SendData();

virtual void Init_LED_Driver();
void InitPWM(UInt8 DRIVER_PWM);

virtual void SendData();
virtual void SetPWM(UInt8 un_PWM_Ground_LED);

private:

Expand Down
19 changes: 16 additions & 3 deletions src/testing/watcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ CWatcherController::CWatcherController() :
m_sLeftWheelSpeed(0),
m_sRightWheelSpeed(0),
m_nControlStep(0),
m_unNumberOfLeds(0), // no. of leds to switch on
m_unNumberOfGroundLeds(0), // no. of leds to switch on
m_unPWMGroundLED(0), // PWM ground LEDs
m_pcWheelsActuator(NULL),
m_pcLEDsActuator(NULL),
m_pcRGBLEDsActuator(NULL),
Expand Down Expand Up @@ -67,7 +68,10 @@ void CWatcherController::ParseParams(TConfigurationNode& t_node) {
GetNodeAttributeOrDefault(t_node, "data_size", m_nDataSize, m_nDataSize);
GetNodeAttributeOrDefault(t_node, "distance", m_nDistance, m_nDistance);
GetNodeAttributeOrDefault(t_node, "run", m_nRun, m_nRun);
GetNodeAttributeOrDefault(t_node, "no_of_leds", m_unNumberOfLeds, m_unNumberOfLeds);
GetNodeAttributeOrDefault(t_node, "no_of_leds", m_unNumberOfGroundLeds, m_unNumberOfGroundLeds); //ground LEDs
GetNodeAttributeOrDefault(t_node, "pwm", m_unPWMGroundLED, m_unPWMGroundLED);


if (filename != "") {
LOG << "[INFO]\tfilename: " << filename << std::endl;
LOG_FILE_INIT(filename.c_str());
Expand Down Expand Up @@ -105,6 +109,11 @@ void CWatcherController::Init(TConfigurationNode& t_node) {
try {
m_pcGroundLEDsActuator = GetActuator<CCI_EPuckGroundLEDsActuator>("epuck_ground_leds");
} catch (CARGoSException ex) {}
if (m_pcGroundLEDsActuator != NULL) {
/* Set PWM of ground LEDs */
m_pcGroundLEDsActuator->SetPWM(m_unPWMGroundLED);
//LOG << "PWM " << m_unPWMGroundLED << std::endl;
}
/* sensors */
try {
m_pcProximitySensor = GetSensor<CCI_EPuckProximitySensor>("epuck_proximity");
Expand All @@ -124,6 +133,7 @@ void CWatcherController::Init(TConfigurationNode& t_node) {
try {
m_pcCamera = GetSensor<CCI_EPuckOmnidirectionalCameraSensor>("epuck_omnidirectional_camera");
} catch (CARGoSException ex) {}

}

/****************************************/
Expand Down Expand Up @@ -154,8 +164,11 @@ void CWatcherController::ControlStep() {
}
/* Ground leds*/
if (m_pcGroundLEDsActuator != NULL) {
/* Set PWM of ground LEDs */
//m_pcGroundLEDsActuator->SetPWM(m_unPWMGroundLED);
//LOG << "PWM " << m_unPWMGroundLED << std::endl;
/* turn-on the given number of LEDs */
m_pcGroundLEDsActuator->SwitchLEDs(m_unNumberOfLeds);
m_pcGroundLEDsActuator->SwitchLEDs(m_unNumberOfGroundLeds);
}
if (m_pcRABActuator != NULL) {
UInt8 data[4];
Expand Down
7 changes: 4 additions & 3 deletions src/testing/watcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <argos3/plugins/robots/e-puck/control_interface/ci_epuck_wheels_actuator.h>
#include <argos3/plugins/robots/e-puck/control_interface/ci_epuck_base_leds_actuator.h>
#include <argos3/plugins/robots/e-puck/control_interface/ci_epuck_rgb_leds_actuator.h>
#include <argos3/plugins/robots/e-puck/control_interface/ci_epuck_ground_leds_actuator.h> /@salman
#include <argos3/plugins/robots/e-puck/control_interface/ci_epuck_ground_leds_actuator.h>
#include <argos3/plugins/robots/e-puck/control_interface/ci_epuck_range_and_bearing_actuator.h>
#include <argos3/plugins/robots/e-puck/control_interface/ci_epuck_ircom_actuator.h>

Expand Down Expand Up @@ -41,15 +41,16 @@ namespace argos {
UInt32 m_nDistance;
UInt32 m_nRun;

size_t m_unNumberOfLeds;

std::string filename;

SInt32 m_sLeftWheelSpeed;
SInt32 m_sRightWheelSpeed;

UInt32 m_nControlStep;

size_t m_unNumberOfGroundLeds;
UInt8 m_unPWMGroundLED;

CCI_EPuckWheelsActuator* m_pcWheelsActuator;
CCI_EPuckBaseLEDsActuator* m_pcLEDsActuator;
CCI_EPuckRGBLEDsActuator* m_pcRGBLEDsActuator;
Expand Down

0 comments on commit 1f2254f

Please sign in to comment.