Skip to content

Commit

Permalink
Merge pull request #120 from nasa-jpl/feat-el2809-driver-addition
Browse files Browse the repository at this point in the history
Feat el2809 driver addition
  • Loading branch information
preston-rogers authored Sep 13, 2023
2 parents 765e212 + 1e363ac commit 16c6772
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ find_package(YamlCpp REQUIRED 0.6.3)
include(FetchContent)
FetchContent_Declare(jsd
GIT_REPOSITORY https://github.com/nasa-jpl/jsd.git
GIT_TAG v2.3.8
GIT_TAG v2.3.9
)
FetchContent_MakeAvailable(jsd)

Expand Down
12 changes: 12 additions & 0 deletions doc/fastcat_device_config_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For every `JSD Device` there is an `Offline Device` to emulate the behavior of t
| El3162 | Beckhoff | 2-channel 0-10v SE Analog Input |
| El3602 | Beckhoff | 2-channel +/-10v Diff. Analog Input |
| El2124 | Beckhoff | 4-channel 5v Digital Output |
| El2809 | Beckhoff | 16-channel 24v Digital Output |
| El4102 | Beckhoff | 2-channel 0-10v Analog Output |
| Ild1900 | Micro-Epsilon | Distance Laser Sensor |
| AtiFts | ATI | Force-Torque Sensor |
Expand Down Expand Up @@ -413,6 +414,17 @@ The permitted range values are:
name: el2124_1
```

## El2809 (16-channel 28v Digital Output)

**The El2809 device has no configuration parameters**

#### Example

``` yaml
- device_class: El2809
name: el2809_1
```

## El4102 (2-channel 0-10v Analog Output)

**The El4102 device has no configuration parameters.**
Expand Down
77 changes: 77 additions & 0 deletions src/fcgen/fastcat_types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,41 @@ states:
- name: level_ch4
type: uint8_t

- name: el2809
fields:
- name: level_ch1
type: uint8_t
- name: level_ch2
type: uint8_t
- name: level_ch3
type: uint8_t
- name: level_ch4
type: uint8_t
- name: level_ch5
type: uint8_t
- name: level_ch6
type: uint8_t
- name: level_ch7
type: uint8_t
- name: level_ch8
type: uint8_t
- name: level_ch9
type: uint8_t
- name: level_ch10
type: uint8_t
- name: level_ch11
type: uint8_t
- name: level_ch12
type: uint8_t
- name: level_ch13
type: uint8_t
- name: level_ch14
type: uint8_t
- name: level_ch15
type: uint8_t
- name: level_ch16
type: uint8_t

- name: el4102
fields:
- name: voltage_output_ch1
Expand Down Expand Up @@ -682,6 +717,48 @@ commands:
- name: channel_ch4
type: uint8_t

- name: el2809_write_channel
fields:
- name: channel
type: uint8_t
- name: level
type: uint8_t

- name: el2809_write_all_channels
fields:
- name: channel_ch1
type: uint8_t
- name: channel_ch2
type: uint8_t
- name: channel_ch3
type: uint8_t
- name: channel_ch4
type: uint8_t
- name: channel_ch5
type: uint8_t
- name: channel_ch6
type: uint8_t
- name: channel_ch7
type: uint8_t
- name: channel_ch8
type: uint8_t
- name: channel_ch9
type: uint8_t
- name: channel_ch10
type: uint8_t
- name: channel_ch11
type: uint8_t
- name: channel_ch12
type: uint8_t
- name: channel_ch13
type: uint8_t
- name: channel_ch14
type: uint8_t
- name: channel_ch15
type: uint8_t
- name: channel_ch16
type: uint8_t

- name: el4102_write_channel
fields:
- name: channel
Expand Down
117 changes: 117 additions & 0 deletions src/jsd/el2809.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Include related header (for cc files)
#include "fastcat/jsd/el2809.h"

// Include c then c++ libraries
#include <string.h>

#include <cmath>
#include <iostream>

// Include external then project includes
#include "fastcat/yaml_parser.h"

fastcat::El2809::El2809()
{
MSG_DEBUG("Constructed El2809");

state_ = std::make_shared<DeviceState>();
state_->type = EL2809_STATE;
}

bool fastcat::El2809::ConfigFromYaml(YAML::Node node)
{
bool retval = ConfigFromYamlCommon(node);
jsd_set_slave_config((jsd_t*)context_, slave_id_, jsd_slave_config_);
return retval;
}

bool fastcat::El2809::ConfigFromYamlCommon(YAML::Node node)
{
if (!ParseVal(node, "name", name_)) {
return false;
}
state_->name = name_;

jsd_slave_config_.configuration_active = true;
jsd_slave_config_.product_code = JSD_EL2809_PRODUCT_CODE;
snprintf(jsd_slave_config_.name, JSD_NAME_LEN, "%s", name_.c_str());

return true;
}

bool fastcat::El2809::Read()
{
const jsd_el2809_state_t* jsd_state =
jsd_el2809_get_state((jsd_t*)context_, slave_id_);

state_->el2809_state.level_ch1 = jsd_state->output[0];
state_->el2809_state.level_ch2 = jsd_state->output[1];
state_->el2809_state.level_ch3 = jsd_state->output[2];
state_->el2809_state.level_ch4 = jsd_state->output[3];
state_->el2809_state.level_ch5 = jsd_state->output[4];
state_->el2809_state.level_ch6 = jsd_state->output[5];
state_->el2809_state.level_ch7 = jsd_state->output[6];
state_->el2809_state.level_ch8 = jsd_state->output[7];
state_->el2809_state.level_ch9 = jsd_state->output[8];
state_->el2809_state.level_ch10 = jsd_state->output[9];
state_->el2809_state.level_ch11 = jsd_state->output[10];
state_->el2809_state.level_ch12 = jsd_state->output[11];
state_->el2809_state.level_ch13 = jsd_state->output[12];
state_->el2809_state.level_ch14 = jsd_state->output[13];
state_->el2809_state.level_ch15 = jsd_state->output[14];
state_->el2809_state.level_ch16 = jsd_state->output[15];

return true;
}

fastcat::FaultType fastcat::El2809::Process()
{
jsd_el2809_process((jsd_t*)context_, slave_id_);
return NO_FAULT;
}

bool fastcat::El2809::Write(DeviceCmd& cmd)
{
// If device supports async SDO requests
AsyncSdoRetVal sdoResult = WriteAsyncSdoRequest(cmd);
if (sdoResult != SDO_RET_VAL_NOT_APPLICABLE) {
return (sdoResult == SDO_RET_VAL_SUCCESS);
}

if (cmd.type == EL2809_WRITE_CHANNEL_CMD) {
uint8_t ch = cmd.el2809_write_channel_cmd.channel;
if (ch < 1 || ch > JSD_EL2809_NUM_CHANNELS) {
ERROR("Channel must be in range (1,%u)", JSD_EL2809_NUM_CHANNELS);
return false;
}

jsd_el2809_write_single_channel((jsd_t*)context_, slave_id_, ch - 1,
cmd.el2809_write_channel_cmd.level);

} else if (cmd.type == EL2809_WRITE_ALL_CHANNELS_CMD) {
uint8_t output_array[JSD_EL2809_NUM_CHANNELS] = {
cmd.el2809_write_all_channels_cmd.channel_ch1,
cmd.el2809_write_all_channels_cmd.channel_ch2,
cmd.el2809_write_all_channels_cmd.channel_ch3,
cmd.el2809_write_all_channels_cmd.channel_ch4,
cmd.el2809_write_all_channels_cmd.channel_ch5,
cmd.el2809_write_all_channels_cmd.channel_ch6,
cmd.el2809_write_all_channels_cmd.channel_ch7,
cmd.el2809_write_all_channels_cmd.channel_ch8,
cmd.el2809_write_all_channels_cmd.channel_ch9,
cmd.el2809_write_all_channels_cmd.channel_ch10,
cmd.el2809_write_all_channels_cmd.channel_ch11,
cmd.el2809_write_all_channels_cmd.channel_ch12,
cmd.el2809_write_all_channels_cmd.channel_ch13,
cmd.el2809_write_all_channels_cmd.channel_ch14,
cmd.el2809_write_all_channels_cmd.channel_ch15,
cmd.el2809_write_all_channels_cmd.channel_ch16};

jsd_el2809_write_all_channels((jsd_t*)context_, slave_id_, output_array);

} else {
ERROR("Bad EL2809 Command");
return false;
}
return true;
}
32 changes: 32 additions & 0 deletions src/jsd/el2809.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef FASTCAT_EL2809_H_
#define FASTCAT_EL2809_H_

// Include related header (for cc files)

// Include c then c++ libraries

// Include external then project includes
#include "fastcat/jsd/jsd_device_base.h"
#include "jsd/jsd_el2809_pub.h"

namespace fastcat
{
class El2809 : public JsdDeviceBase
{
public:
El2809();
bool ConfigFromYaml(YAML::Node node) override;
bool Read() override;
FaultType Process() override;
bool Write(DeviceCmd& cmd) override;

protected:
bool ConfigFromYamlCommon(YAML::Node node);

private:
jsd_slave_config_t jsd_slave_config_ = {0};
};

} // namespace fastcat

#endif
Loading

0 comments on commit 16c6772

Please sign in to comment.