Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the el5042 driver #144

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ find_package(YamlCpp REQUIRED 0.6.3)
include(FetchContent)
FetchContent_Declare(jsd
GIT_REPOSITORY https://github.com/nasa-jpl/jsd.git
GIT_TAG v3.0.1
GIT_TAG prestonr-add-el5042
)
FetchContent_MakeAvailable(jsd)

Expand Down
70 changes: 70 additions & 0 deletions doc/fastcat_device_config_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ For every `JSD Device` there is an `Offline Device` to emulate the behavior of t
| El3602 | Beckhoff | 2-channel +/-10v Diff. Analog Input |
| El2124 | Beckhoff | 4-channel 5v Digital Output |
| El2809 | Beckhoff | 16-channel 24v Digital Output |
| El5042 | Beckhoff | 2-channel Encoder |
| El2828 | Beckhoff | 8-channel 24v 2A Digital Output |
| El2798 | Beckhoff | 8-channel 30v AC/48v DC 2A Solid State Relay Output |
| El4102 | Beckhoff | 2-channel 0-10v Analog Output |
| Ild1900 | Micro-Epsilon | Distance Laser Sensor |
| AtiFts | ATI | Force-Torque Sensor |
Expand Down Expand Up @@ -425,6 +428,73 @@ The permitted range values are:
name: el2809_1
```

## El5042 (2-channel BiSS-C Encoder Interface)

| Parameter | Description |
| ----------------- | ------------------------------------------------------------ |
| `invert_feedback_direction` | Negates the position value (0 for don't invert and 1 for invert) |
| `disable_status_bits` | Tell the slave whether or not to send status bits (0 for don't disable and 1 for disable) |
| `invert_checksum` | Inverts the checksum bits (CRC) received by the encoder (0 for don't inver and 1 for invert) |
| `checksum_polynomial` | Polynomial used for calculating checksum. This is a 32 bit polynomial. |
| `supply_voltage` | Set the encoder supply voltage, either 50 for 5V or 90 for 9V |
| `clock_frequency` | Clock frequency for the BiSS-C protocol (250 kHz to 10 MHz as specified below) |
| `gray_code` | Option to either use dual code or gray code for accurate data (0 for dual code and 1 for gray code) |
| `multiturn_bits` | Set the number of multiturn bits (how many complete rotations) |
| `singleturn_bits` | Set the number of singleturn bits (resolution of a single rotation) |
| `offset_bits` | If there are addition null bits at the end of the packet, we shift by offset bits to get data |
| `ssi_mode` | Opt for SSI mode over BiSS-C (0 for BiSS-C and 1 for SSI) |

Clock frequency correspondances

* 10MHz: 10 MHz
* 5MHz: 5 MHz
* 3_33MHz: 3.3 MHz
* 2_5MHz: 2.5 MHz
* 2MHz: 2 MHz
* 1MHz: 1 MHz
* 500KHz: 500 kHz
* 250KHz: 250 kHz

#### Example

```yaml
- device_class: El5042
name: el5042_1
invert_feedback_direction: [0, 0]
disable_status_bits: [0, 0]
invert_checksum: [1, 1]
checksum_polynomial: [67, 67]
supply_voltage: [50, 50]
clock_frequency: [5MHz, 5MHz]
gray_code: [0, 0]
multiturn_bits: [0, 0]
singleturn_bits: [19, 19]
offset_bits: [0, 0]
ssi_mode: [0, 0]
```

## El2828 (8-channel 24v 2A Digital Output)

**The El2828 device has no configuration parameters**

#### Example

``` yaml
- device_class: El2828
name: el2828_1
```

## El2798 (8-channel 30v AC/48v DC 2A Solid State Relay Output)

**The El2798 device has no configuration parameters**

#### Example

``` yaml
- device_class: El2798
name: el2798_1
```

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

**The El4102 device has no configuration parameters.**
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ add_library(fastcat STATIC
jsd/el3602.cc
jsd/el2124.cc
jsd/el2809.cc
jsd/el2828.cc
jsd/el2798.cc
jsd/el4102.cc
jsd/el3162.cc
jsd/el1008.cc
jsd/el3104.cc
jsd/el3202.cc
jsd/el3318.cc
jsd/el5042.cc
jsd/gold_actuator.cc
jsd/ild1900.cc
jsd/jed0101.cc
Expand All @@ -92,6 +95,8 @@ add_library(fastcat STATIC
jsd/egd_offline.cc
jsd/el2124_offline.cc
jsd/el2809_offline.cc
jsd/el2828_offline.cc
jsd/el2798_offline.cc
jsd/el4102_offline.cc
jsd/el3208_offline.cc
jsd/el3602_offline.cc
Expand All @@ -100,6 +105,7 @@ add_library(fastcat STATIC
jsd/el3104_offline.cc
jsd/el3202_offline.cc
jsd/el3318_offline.cc
jsd/el5042_offline.cc
jsd/ild1900_offline.cc
jsd/gold_actuator_offline.cc
jsd/jed0101_offline.cc
Expand Down
109 changes: 109 additions & 0 deletions src/fcgen/fastcat_types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,44 @@ states:
type: uint8_t
- name: level_ch16
type: uint8_t

- name: el2828
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: el2798
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: el4102
fields:
Expand Down Expand Up @@ -486,6 +524,25 @@ states:
- name: adc_value_ch8
type: int16_t

- name: el5042
fields:
- name: position_ch1
type: int64_t
- name: warning_ch1
type: int8_t
- name: error_ch1
type: int8_t
- name: ready_ch1
type: int8_t
- name: position_ch2
type: int64_t
- name: warning_ch2
type: int8_t
- name: error_ch2
type: int8_t
- name: ready_ch2
type: int8_t

- name: ild1900
fields:
- name: distance_m
Expand Down Expand Up @@ -759,6 +816,58 @@ commands:
- name: channel_ch16
type: uint8_t

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

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

- name: el2828_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: el2798_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: el4102_write_channel
fields:
- name: channel
Expand Down
101 changes: 101 additions & 0 deletions src/jsd/el2798.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Include related header (for cc files)
#include "fastcat/jsd/el2798.h"

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

#include <cmath>
#include <iostream>

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

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

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

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

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

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

return true;
}

bool fastcat::El2798::Read()
{
const jsd_el2798_state_t* jsd_state =
jsd_el2798_get_state((jsd_t*)context_, slave_id_);

state_->el2798_state.level_ch1 = jsd_state->output[0];
state_->el2798_state.level_ch2 = jsd_state->output[1];
state_->el2798_state.level_ch3 = jsd_state->output[2];
state_->el2798_state.level_ch4 = jsd_state->output[3];
state_->el2798_state.level_ch5 = jsd_state->output[4];
state_->el2798_state.level_ch6 = jsd_state->output[5];
state_->el2798_state.level_ch7 = jsd_state->output[6];
state_->el2798_state.level_ch8 = jsd_state->output[7];

return true;
}

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

bool fastcat::El2798::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 == EL2798_WRITE_CHANNEL_CMD) {
uint8_t ch = cmd.el2798_write_channel_cmd.channel;
if (ch < 1 || ch > JSD_EL2798_NUM_CHANNELS) {
ERROR("Channel must be in range (1,%u)", JSD_EL2798_NUM_CHANNELS);
return false;
}

jsd_el2798_write_single_channel((jsd_t*)context_, slave_id_, ch - 1,
cmd.el2798_write_channel_cmd.level);

} else if (cmd.type == EL2798_WRITE_ALL_CHANNELS_CMD) {
uint8_t output_array[JSD_EL2798_NUM_CHANNELS] = {
cmd.el2798_write_all_channels_cmd.channel_ch1,
cmd.el2798_write_all_channels_cmd.channel_ch2,
cmd.el2798_write_all_channels_cmd.channel_ch3,
cmd.el2798_write_all_channels_cmd.channel_ch4,
cmd.el2798_write_all_channels_cmd.channel_ch5,
cmd.el2798_write_all_channels_cmd.channel_ch6,
cmd.el2798_write_all_channels_cmd.channel_ch7,
cmd.el2798_write_all_channels_cmd.channel_ch8};

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

} else {
ERROR("Bad EL2798 Command");
return false;
}
return true;
}
32 changes: 32 additions & 0 deletions src/jsd/el2798.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef FASTCAT_EL2798_H_
#define FASTCAT_EL2798_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_el2798_pub.h"

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

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

private:
jsd_slave_config_t jsd_slave_config_ = {0};
};

} // namespace fastcat

#endif
Loading