Skip to content
Snippets Groups Projects

develop -> main

1 file
+ 123
124
Compare changes
  • Side-by-side
  • Inline
+ 123
124
@@ -145,12 +145,12 @@ void SingleShotAOManager::init(asl::SingleShotAO * p_ssao, unsigned short p_nb_c
@@ -145,12 +145,12 @@ void SingleShotAOManager::init(asl::SingleShotAO * p_ssao, unsigned short p_nb_c
enable_periodic_msg(true);
enable_periodic_msg(true);
}
}
// initialize channel indexes (-1 means no ramp in progress)
// initialize channel indexes (-1 means no ramp in progress)
// and ramp states
// and ramp states
for (unsigned int l_cpt = 0;l_cpt < m_nb_chan;l_cpt++)
for (unsigned int l_cpt = 0; l_cpt < m_nb_chan; l_cpt++)
{
{
m_currentIndex[l_cpt] = -1;
m_currentIndex[l_cpt] = -1;
m_isRunning[l_cpt] = false;
m_isRunning[l_cpt] = false;
}
}
}
}
@@ -164,36 +164,39 @@ void SingleShotAOManager::process_message (yat::Message& msg)
@@ -164,36 +164,39 @@ void SingleShotAOManager::process_message (yat::Message& msg)
switch (msg.type())
switch (msg.type())
{
{
//- THREAD_INIT ----------------------
//- THREAD_INIT ----------------------
case yat::TASK_INIT:
case yat::TASK_INIT:
{
{
DEBUG_STREAM << "SingleShotAOManager::handle_message::THREAD_INIT::thread is starting up" << std::endl;
DEBUG_STREAM << "SingleShotAOManager::handle_message::THREAD_INIT::thread is starting up" << std::endl;
}
}
break;
break;
//- THREAD_EXIT ----------------------
//- THREAD_EXIT ----------------------
case yat::TASK_EXIT:
case yat::TASK_EXIT:
{
{
DEBUG_STREAM << "SingleShotAOManager::handle_message::THREAD_EXIT::thread is quitting" << std::endl;
DEBUG_STREAM << "SingleShotAOManager::handle_message::THREAD_EXIT::thread is quitting" << std::endl;
}
}
break;
break;
//- THREAD_PERIODIC ------------------
//- THREAD_PERIODIC ------------------
case yat::TASK_PERIODIC:
case yat::TASK_PERIODIC:
{
{
periodic_job_i();
periodic_job_i();
}
}
break;
break;
//- THREAD_TIMEOUT -------------------
//- THREAD_TIMEOUT -------------------
case yat::TASK_TIMEOUT:
case yat::TASK_TIMEOUT:
{
{
//- not used in this example
//- not used in this example
}
}
break;
break;
 
//- UNHANDLED MSG --------------------
//- UNHANDLED MSG --------------------
default:
default:
DEBUG_STREAM << "SingleShotAOManager::handle_message::unhandled msg type received" << std::endl;
{
break;
DEBUG_STREAM << "SingleShotAOManager::handle_message::unhandled msg type received" << std::endl;
 
break;
 
}
}
}
}
}
@@ -202,53 +205,52 @@ void SingleShotAOManager::process_message (yat::Message& msg)
@@ -202,53 +205,52 @@ void SingleShotAOManager::process_message (yat::Message& msg)
// ============================================================================
// ============================================================================
void SingleShotAOManager::periodic_job_i()
void SingleShotAOManager::periodic_job_i()
{
{
//test all channels
// test all channels
for (unsigned int l_cpt = 0;l_cpt < m_nb_chan;l_cpt++)
for (unsigned int l_cpt = 0;l_cpt < m_nb_chan;l_cpt++)
{
{
//test if a ramp step must occur
// test if a ramp step must occur
if (m_currentIndex[l_cpt] != -1)
if (m_currentIndex[l_cpt] == -1)
{
{
m_isRunning[l_cpt] = true;
m_isRunning[l_cpt] = false;
double l_val = 0;
continue;
l_val = m_ramps[l_cpt][m_currentIndex[l_cpt]];
DEBUG_STREAM << "Current value for channel" << l_cpt << ": " << l_val << endl;
try
{
CHECK_SSAO();
m_ssao->write_scaled_channel((adl::ChanId)l_cpt, l_val);
m_channels[l_cpt] = l_val;
}
catch(const asl::DAQException& de)
{
Tango::DevFailed df = daq_to_tango_exception(de);
ERROR_STREAM << df<< endl;
m_state = Tango::FAULT;
RETHROW_DEVFAILED(df,
"DRIVER_FAILURE",
"could not write channel [caught asl::DAQException]",
"SingleShotAOManager::write_channel");
}
catch(...)
{
ERROR_STREAM << "SingleShotAOManager::write_channel::unknown exception caught"<<std::endl;
m_state = Tango::FAULT;
THROW_DEVFAILED("DRIVER_FAILURE",
"could not write channel [unknown error]",
"SingleShotAOManager::write_channel");
}
//check if there is another value
m_currentIndex[l_cpt] +=1;
if (m_currentIndex[l_cpt] == m_ramps[l_cpt].capacity())
{
m_currentIndex[l_cpt] = -1;
m_initials[l_cpt] = m_channels[l_cpt];
m_ramps[l_cpt].clear();
}
}
}
else
 
m_isRunning[l_cpt] = true;
 
double l_val = 0;
 
l_val = m_ramps[l_cpt][m_currentIndex[l_cpt]];
 
DEBUG_STREAM << "Current value for channel" << l_cpt << ": " << l_val << endl;
 
try
{
{
m_isRunning[l_cpt] = false;
CHECK_SSAO();
 
m_ssao->write_scaled_channel((adl::ChanId)l_cpt, l_val);
 
m_channels[l_cpt] = l_val;
 
}
 
catch(const asl::DAQException& de)
 
{
 
Tango::DevFailed df = daq_to_tango_exception(de);
 
ERROR_STREAM << df << endl;
 
m_state = Tango::FAULT;
 
RETHROW_DEVFAILED(df,
 
"DRIVER_FAILURE",
 
"could not write channel [caught asl::DAQException]",
 
"SingleShotAOManager::write_channel");
 
}
 
catch(...)
 
{
 
ERROR_STREAM << "SingleShotAOManager::write_channel::unknown exception caught" << std::endl;
 
m_state = Tango::FAULT;
 
THROW_DEVFAILED("DRIVER_FAILURE",
 
"could not write channel [unknown error]",
 
"SingleShotAOManager::write_channel");
 
}
 
 
// check if there is another value
 
m_currentIndex[l_cpt] += 1;
 
if (m_currentIndex[l_cpt] == m_ramps[l_cpt].capacity())
 
{
 
m_currentIndex[l_cpt] = -1;
 
m_initials[l_cpt] = m_channels[l_cpt];
 
m_ramps[l_cpt].clear();
}
}
}
}
}
}
@@ -266,8 +268,9 @@ double SingleShotAOManager::get_channel(ChannelId_t p_chIdx)
@@ -266,8 +268,9 @@ double SingleShotAOManager::get_channel(ChannelId_t p_chIdx)
// ============================================================================
// ============================================================================
void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
{
{
DEBUG_STREAM << "write_channel : " << p_chIdx << " : " << p_val << " : " << endl;
DEBUG_STREAM << "write_channel " << p_chIdx << " : " << p_val << endl;
 
// if the speed is 0, write the value directly
if (m_speeds[p_chIdx] == 0.0)
if (m_speeds[p_chIdx] == 0.0)
{
{
try
try
@@ -276,11 +279,12 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
@@ -276,11 +279,12 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
m_ssao->write_scaled_channel((adl::ChanId)p_chIdx, p_val);
m_ssao->write_scaled_channel((adl::ChanId)p_chIdx, p_val);
m_channels[p_chIdx] = p_val;
m_channels[p_chIdx] = p_val;
m_initials[p_chIdx] = p_val;
m_initials[p_chIdx] = p_val;
 
DEBUG_STREAM << "Speed is 0, writing directly the value" << endl;
}
}
catch(const asl::DAQException& de)
catch(const asl::DAQException& de)
{
{
Tango::DevFailed df = daq_to_tango_exception(de);
Tango::DevFailed df = daq_to_tango_exception(de);
ERROR_STREAM << df<< endl;
ERROR_STREAM << df << endl;
m_state = Tango::FAULT;
m_state = Tango::FAULT;
RETHROW_DEVFAILED(df,
RETHROW_DEVFAILED(df,
"DRIVER_FAILURE",
"DRIVER_FAILURE",
@@ -295,83 +299,78 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
@@ -295,83 +299,78 @@ void SingleShotAOManager::write_channel(ChannelId_t p_chIdx, double p_val)
"could not write channel [unknown error]",
"could not write channel [unknown error]",
"SingleShotAOManager::write_channel");
"SingleShotAOManager::write_channel");
}
}
 
return;
}
}
else
 
// if a ramp is not running, error
 
if (m_isRunning[p_chIdx])
 
{
 
THROW_DEVFAILED("DEVICE_FAILURE",
 
"could not write channel : a ramp is still in progress on this channel",
 
"SingleShotAOManager::write_channel");
 
}
 
 
// if frequency = 0, error
 
if (m_frequency == 0)
 
{
 
THROW_DEVFAILED("DRIVER_FAILURE",
 
"could not set a ramp on this channel. The frequency is 0",
 
"SingleShotAOManager::write_channel");
 
}
 
 
// if initial = channel, skip
 
if (m_initials[p_chIdx] == p_val)
 
{
 
DEBUG_STREAM << "Initial value is the same as the given value, skipping" << endl;
 
return;
 
}
 
 
// ramp determination
 
double l_delta = p_val - m_initials[p_chIdx];
 
bool isDown = false;
 
l_delta = ((l_delta * m_frequency) / m_speeds[p_chIdx]) + 1;
 
if (l_delta < 0)
 
{
 
l_delta = -l_delta + 2;
 
isDown = true;
 
}
 
DEBUG_STREAM << "Computed ramp steps number : " << l_delta << endl;
 
 
yat::Buffer<double> l_buffer;
 
size_t ramp_size = (size_t)(ceil(l_delta));
 
l_buffer.capacity(ramp_size);
 
l_buffer.force_length(ramp_size);
 
 
// check if ramp step is integer or not
 
bool isDeltaNotInt = (ramp_size != ((size_t)(floor(l_delta))));
 
DEBUG_STREAM << "Real ramp steps number : " << ramp_size << endl;
 
 
for (unsigned int l_cpt = 0; l_cpt < ramp_size; l_cpt++)
{
{
// check if a ramp is not running
if ((l_cpt == (ramp_size - 1)) && (isDeltaNotInt))
if (!m_isRunning[p_chIdx])
{
{
// check if initial = channel
// add the setpoint value at the end of table
if (m_initials[p_chIdx] != p_val)
l_buffer[l_cpt] = p_val;
{
if (m_frequency == 0)
{
THROW_DEVFAILED("DRIVER_FAILURE",
"could not set a ramp on this channel. The frequency is 0",
"SingleShotAOManager::write_channel");
}
//ramp determination
double l_delta = p_val - m_initials[p_chIdx];
bool isDown = false;
l_delta = ((l_delta * m_frequency) / m_speeds[p_chIdx])+1;
if (l_delta < 0)
{
l_delta = -l_delta + 2;
isDown = true;
}
DEBUG_STREAM << "Computed ramp steps number : " << l_delta << endl;
yat::Buffer<double> l_buffer;
size_t ramp_size = (size_t)(ceil(l_delta));
l_buffer.capacity(ramp_size);
l_buffer.force_length(ramp_size);
// check if ramp step is integer or not
bool isDeltaNotInt = false;
if (ramp_size != ((size_t)(floor(l_delta))))
{
isDeltaNotInt = true;
}
DEBUG_STREAM << "Real ramp steps number : " << ramp_size << endl;
for (unsigned int l_cpt = 0; l_cpt < ramp_size; l_cpt++)
{
if ((l_cpt == (ramp_size - 1)) &&
(isDeltaNotInt))
{
// add the setpoint value at the end of table
l_buffer[l_cpt] = p_val;
}
else
{
if (isDown)
{
l_buffer[l_cpt] = m_initials[p_chIdx] - l_cpt*(m_speeds[p_chIdx]/m_frequency);
}
else
{
l_buffer[l_cpt] = m_initials[p_chIdx] + l_cpt*(m_speeds[p_chIdx]/m_frequency);
}
}
//DEBUG_STREAM << "Ramp buffer[" << l_cpt << "] = " << l_buffer[l_cpt] << endl;
}
m_ramps[p_chIdx].clear();
m_ramps[p_chIdx].capacity(0);
m_ramps[p_chIdx].force_length(0);
m_currentIndex[p_chIdx] = 0;
m_ramps[p_chIdx] = l_buffer;
//m_channels[p_chIdx] = m_ramps[p_chIdx][0]; -- soso on ne met rien ici => à l'application
}
}
}
else
else
{
{
THROW_DEVFAILED("DEVICE_FAILURE",
if (isDown)
"could not write channel : a ramp is still in progress on this channel",
{
"SingleShotAOManager::write_channel");
l_buffer[l_cpt] = m_initials[p_chIdx] - l_cpt * (m_speeds[p_chIdx] / m_frequency);
 
}
 
else
 
{
 
l_buffer[l_cpt] = m_initials[p_chIdx] + l_cpt * (m_speeds[p_chIdx] / m_frequency);
 
}
}
}
 
//DEBUG_STREAM << "Ramp buffer[" << l_cpt << "] = " << l_buffer[l_cpt] << endl;
}
}
 
m_ramps[p_chIdx].clear();
 
m_ramps[p_chIdx].capacity(0);
 
m_ramps[p_chIdx].force_length(0);
 
m_currentIndex[p_chIdx] = 0;
 
m_ramps[p_chIdx] = l_buffer;
 
//m_channels[p_chIdx] = m_ramps[p_chIdx][0]; -- soso on ne met rien ici => à l'application
}
}
// ============================================================================
// ============================================================================
Loading