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

adds digital sensor interface #84

Open
wants to merge 97 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
b686a05
updates copyright for bag recorder and timer nodes
xwilson03 Jun 2, 2024
430ec17
adds digital IO to device interfaces
xwilson03 Jun 2, 2024
f861502
copies joystick interface into new digital io interface
xwilson03 Jun 3, 2024
63a5392
adds digital IO interface header
xwilson03 Jun 3, 2024
7d0c743
fixes deserialize write behavior
xwilson03 Jun 3, 2024
f8b3bc1
renames digital io config
xwilson03 Jun 3, 2024
ae75931
fixes deserialize behavior
xwilson03 Jun 3, 2024
75366f1
updates device type enum
xwilson03 Jun 4, 2024
b5e5235
commits base, unfinished load libraries
xwilson03 Jun 4, 2024
3cfb577
changes digital io into digital sensor
xwilson03 Jun 4, 2024
93c6fef
adds digital actuator interface
xwilson03 Jun 4, 2024
4147a20
recombines digital device types
xwilson03 Jun 4, 2024
8a37ecf
adds digital_io_type enum
xwilson03 Jun 4, 2024
efa5e56
recombines digital device interface headers
xwilson03 Jun 4, 2024
3102c59
renames yaml loading helper
xwilson03 Jun 4, 2024
5ce2712
adds serial config to digital device
xwilson03 Jun 4, 2024
b59dcb9
adds yaml loading
xwilson03 Jun 4, 2024
fcaf7c3
changes io type name in YAML loading
xwilson03 Jun 4, 2024
cb7021d
adds example to comment doc
xwilson03 Jun 4, 2024
27d9fe9
fixes method comments in device interfaces header
xwilson03 Jun 4, 2024
ed725e7
changes digital device ports to start at 22
xwilson03 Jun 5, 2024
16a4706
adds digital device support to RHI
xwilson03 Jun 5, 2024
b53f4f1
removes (now) unused digital_io_ vector from RHI
xwilson03 Jun 5, 2024
8628c0c
adds whitespace
xwilson03 Jun 5, 2024
1bea329
adds digital device helpers to RHI
xwilson03 Jun 5, 2024
939d690
removes digital io vector from RHI header
xwilson03 Jun 6, 2024
6fcdbd6
adds digital device to conversion helpers
xwilson03 Jun 6, 2024
321bb47
adds whitespace
xwilson03 Jun 6, 2024
40b2375
adds digital device ros msg
xwilson03 Jun 6, 2024
ba6db69
adds digital device msg helpers
xwilson03 Jun 6, 2024
a0cebcc
adds digital device msg to cmake
xwilson03 Jun 6, 2024
b96061f
adds conversion maps for digital io type
xwilson03 Jun 6, 2024
38ecd83
(TEMP) disables digital io tests
xwilson03 Jun 6, 2024
f8a6ba8
fixes digital msg helpers, updates RHI msgs and helpers
xwilson03 Jun 6, 2024
89611aa
moves digital device base node in yaml loader
xwilson03 Jun 6, 2024
64aef43
adds adi sensors to yaml
xwilson03 Jun 6, 2024
12674a8
replaces digital io in swerve plugin
xwilson03 Jun 6, 2024
3c688aa
replaces digital io in climb plugin
xwilson03 Jun 6, 2024
3b3a74c
replaces swipeTail digital io
xwilson03 Jun 6, 2024
f4d8e3f
fixes example comment
xwilson03 Jun 6, 2024
4d68735
removes old digital io test
xwilson03 Jun 6, 2024
0693004
adds digital test devices
xwilson03 Jun 6, 2024
071ec22
fixes digital device ==
xwilson03 Jun 6, 2024
a413e8b
adds digital device test helpers
xwilson03 Jun 6, 2024
7c0a32e
fixes digital config ==
xwilson03 Jun 6, 2024
3720c8b
adds io_type to digital test helper
xwilson03 Jun 6, 2024
cd82add
adds digital devices to existing tests
xwilson03 Jun 6, 2024
6643ad4
replaces previous digital io setup with new vectors in headers
xwilson03 Jun 6, 2024
53ad581
adds mutex for digital actuators just in case
xwilson03 Jun 6, 2024
0ebc193
makes interface class for digital actuators
xwilson03 Jun 6, 2024
eae7a50
switches digital actuator vector to new interface
xwilson03 Jun 6, 2024
5c51071
removes useless digital actuator mutex
xwilson03 Jun 6, 2024
5985a0c
changes digital io in v5 code
xwilson03 Jun 6, 2024
f3ed0e1
adds digital device codegen
xwilson03 Jun 6, 2024
9675f29
fixes digital test util
xwilson03 Jun 6, 2024
d04b25a
adds digital device yaml loader to cmake
xwilson03 Jun 6, 2024
45874a3
fixes yaml conversions
xwilson03 Jun 6, 2024
6ccd491
changes io_type to device types
xwilson03 Jun 6, 2024
635476d
adds digital child classes
xwilson03 Jun 6, 2024
3ae0c82
removes digital device base class
xwilson03 Jun 6, 2024
f448004
updates digital test helpers
xwilson03 Jun 6, 2024
adec68b
updates robot config yaml
xwilson03 Jun 6, 2024
5208806
updates device config factory
xwilson03 Jun 6, 2024
80806c3
updates v5 serial node
xwilson03 Jun 6, 2024
2252c6d
updates v5 main
xwilson03 Jun 6, 2024
3b6fa22
updates RHI digital helpers
xwilson03 Jun 6, 2024
002e02f
fixes example yaml
xwilson03 Jun 6, 2024
83adcb4
updates yaml loader
xwilson03 Jun 6, 2024
613818b
updates device config factory
xwilson03 Jun 6, 2024
5f50577
updates digital msg helpers
xwilson03 Jun 6, 2024
25fad9a
adds more test yamls
xwilson03 Jun 6, 2024
cb14b6c
adds interface test
xwilson03 Jun 6, 2024
897d5eb
fixes config factory
xwilson03 Jun 6, 2024
8c1b276
fixes digital == and serialize
xwilson03 Jun 6, 2024
ee93d56
fixes digital data fetching in RHI
xwilson03 Jun 6, 2024
3159b72
initializes digital value
xwilson03 Jun 6, 2024
5cfc464
adds maxx tests
xwilson03 Jun 6, 2024
e50f1ab
updates cmake
xwilson03 Jun 6, 2024
e65bc77
adds digital device msg tests
xwilson03 Jun 6, 2024
64300bf
updates digital msg helpers
xwilson03 Jun 6, 2024
880e58a
adds msg helper tests
xwilson03 Jun 6, 2024
b40503a
fixes error messages in RHI digital helpers
xwilson03 Jun 6, 2024
a2af3a7
updates rhi digital helper calls in BT nodes
xwilson03 Jun 6, 2024
6e2a251
updates rhi ros msg tests
xwilson03 Jun 6, 2024
64b2203
fixes whitespace
xwilson03 Nov 17, 2024
7c5e79a
slightly refactors load digital device yaml
xwilson03 Nov 17, 2024
736199d
updates example_robot_2 yaml
xwilson03 Nov 18, 2024
54eb2fb
update example_robot yaml
xwilson03 Nov 18, 2024
ee96429
update test_load_digital_device yaml
xwilson03 Nov 18, 2024
0f5817f
adds digital device test to cmake
xwilson03 Dec 8, 2024
310cec9
reduces some duplication in cmake
xwilson03 Dec 8, 2024
1ded1a1
adds comments and whitespace
xwilson03 Dec 8, 2024
a556491
changes digital device port ranges
xwilson03 Dec 8, 2024
6ae2dcf
changes RHI deserialize call for digital devices
xwilson03 Dec 8, 2024
3a02275
changes error messages for setDigitalXX functions
xwilson03 Dec 9, 2024
ab1db6a
changes whitespace
xwilson03 Dec 9, 2024
c9c06a0
changes port range in loadDigital tests
xwilson03 Dec 9, 2024
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
20 changes: 14 additions & 6 deletions 01_Libraries/ghost_v5_interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set(UTIL_LIBS
load_motor_device_config_yaml
load_rotation_sensor_device_config_yaml
load_inertial_sensor_device_config_yaml
load_digital_device_config_yaml
)

foreach(UTIL ${UTIL_LIBS})
Expand Down Expand Up @@ -137,6 +138,7 @@ set(DEVICE_TESTS
test_rotation_sensor_device_interface
test_inertial_sensor_device_interface
test_joystick_device_interface
test_digital_device_interface
)
foreach(TEST ${DEVICE_TESTS})
ament_add_gtest(${TEST} test/devices/${TEST}.cpp)
Expand All @@ -152,9 +154,7 @@ foreach(TEST ${UTIL_LIBS})
ament_target_dependencies(test_${TEST} ${DEPENDENCIES})
target_link_libraries(test_${TEST}
gtest_main
load_motor_device_config_yaml
load_rotation_sensor_device_config_yaml
load_inertial_sensor_device_config_yaml
${UTIL_LIBS}
device_config_factory_utils
yaml-cpp
)
Expand All @@ -170,12 +170,20 @@ target_link_libraries(test_device_config_factory_utils
)

# Hardware Interface Tests
ament_add_gtest(test_rhi_serialization test/test_rhi_serialization.cpp)
ament_target_dependencies(test_rhi_serialization ${DEPENDENCIES})
target_link_libraries(test_rhi_serialization
gtest_main
device_config_factory_utils
robot_hardware_interface
)

ament_add_gtest(test_robot_hardware_interface test/test_robot_hardware_interface.cpp)
ament_target_dependencies(test_robot_hardware_interface ${DEPENDENCIES})
target_link_libraries(test_robot_hardware_interface
gtest_main
device_config_factory_utils
robot_hardware_interface
gtest_main
device_config_factory_utils
robot_hardware_interface
)

ament_package()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Maxx Wilson
* Copyright (c) 2024 Maxx Wilson, Xander Wilson
* All rights reserved.

* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -46,6 +46,8 @@ enum device_type_e
GPS_SENSOR, // Unsupported
RADIO, // Unsupported
JOYSTICK,
DIGITAL_INPUT,
DIGITAL_OUTPUT,
INVALID
};

Expand Down Expand Up @@ -164,7 +166,7 @@ class DeviceData : public DeviceBase
/**
* @brief Converts device data to byte stream.
*
* @param to_v5 set to true when the data is going from coprocessor -> V5 Brain
* @param hardware_type current hardware type
* @return std::vector<unsigned char> byte stream
*/
virtual std::vector<unsigned char> serialize(hardware_type_e hardware_type) const = 0;
Expand All @@ -173,7 +175,7 @@ class DeviceData : public DeviceBase
* @brief Updates device data from byte stream.
*
* @param data byte stream as unsigned char vector
* @param from_coprocessor set to true when the data is going from coprocesspr -> V5 Brain
* @param hardware_type current hardware type
*/
virtual void deserialize(
const std::vector<unsigned char> & data,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* Copyright (c) 2024 Maxx Wilson, Xander Wilson
* All rights reserved.

* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:

* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#pragma once

#include <cstring>
#include "ghost_v5_interfaces/devices/device_interfaces.hpp"

namespace ghost_v5_interfaces
{

namespace devices
{

class DigitalInputDeviceData : public DeviceData
{
public:
DigitalInputDeviceData(std::string name)
: DeviceData(name, DIGITAL_INPUT)
{
}

int getActuatorPacketSize() const override
{
return 0;
}

int getSensorPacketSize() const override
{
return 1;
}

std::shared_ptr<DeviceBase> clone() const override
{
return std::make_shared<DigitalInputDeviceData>(*this);
}

std::vector<unsigned char> serialize(hardware_type_e hardware_type) const override
{
std::vector<unsigned char> msg(1);
if (hardware_type == V5_BRAIN) {
msg.push_back((unsigned char) value);
}
return msg;
}

void deserialize(const std::vector<unsigned char> & msg, hardware_type_e hardware_type) override
{
if (hardware_type == COPROCESSOR) {
value = ((bool) msg.data()[0]);
}
}

void update(std::shared_ptr<DeviceData> data_ptr) override
{
auto digital_data_ptr = data_ptr->as<DigitalInputDeviceData>();
value = digital_data_ptr->value;
}

bool operator==(const DeviceBase & rhs) const override
{
const DigitalInputDeviceData * d_rhs = dynamic_cast<const DigitalInputDeviceData *>(&rhs);
return (d_rhs != nullptr) && (name == d_rhs->name) && (type == d_rhs->type) && (value == d_rhs->value);
}

bool value = false;
};

class DigitalOutputDeviceData : public DeviceData
{
public:
DigitalOutputDeviceData(std::string name)
: DeviceData(name, DIGITAL_OUTPUT)
{
}

int getActuatorPacketSize() const override
{
return 1;
}

int getSensorPacketSize() const override
{
return 0;
}

std::shared_ptr<DeviceBase> clone() const override
{
return std::make_shared<DigitalOutputDeviceData>(*this);
}

std::vector<unsigned char> serialize(hardware_type_e hardware_type) const override
{
std::vector<unsigned char> msg;
if (hardware_type == COPROCESSOR) {
msg.push_back((unsigned char) value);
}
return msg;
}

void deserialize(const std::vector<unsigned char> & msg, hardware_type_e hardware_type) override
{
if (hardware_type == V5_BRAIN) {
value = ((bool) msg.data()[0]);
}
}

void update(std::shared_ptr<DeviceData> data_ptr) override
{
auto digital_data_ptr = data_ptr->as<DigitalOutputDeviceData>();
value = digital_data_ptr->value;
}

bool operator==(const DeviceBase & rhs) const override
{
const DigitalOutputDeviceData * d_rhs = dynamic_cast<const DigitalOutputDeviceData *>(&rhs);
return (d_rhs != nullptr) && (name == d_rhs->name) && (type == d_rhs->type) && (value == d_rhs->value);
}

bool value = false;
};

class DigitalDeviceConfig : public DeviceConfig
{
public:
std::shared_ptr<DeviceBase> clone() const override
{
return std::make_shared<DigitalDeviceConfig>(*this);
}

bool operator==(const DeviceBase & rhs) const override
{
const DigitalDeviceConfig * d_rhs = dynamic_cast<const DigitalDeviceConfig *>(&rhs);
return (d_rhs != nullptr) && (port == d_rhs->port) && (name == d_rhs->name) &&
(type == d_rhs->type);
}
};

} // namespace devices

} // namespace ghost_v5_interfaces
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
#include <memory>
#include <mutex>
#include <unordered_map>
#include "ghost_util/byte_utils.hpp"
#include "ghost_v5_interfaces/devices/device_config_map.hpp"
#include "ghost_v5_interfaces/devices/inertial_sensor_device_interface.hpp"
#include "ghost_v5_interfaces/devices/joystick_device_interface.hpp"
#include "ghost_v5_interfaces/devices/motor_device_interface.hpp"
#include "ghost_v5_interfaces/devices/rotation_sensor_device_interface.hpp"
#include "ghost_v5_interfaces/devices/digital_device_interface.hpp"


#if GHOST_DEVICE == GHOST_JETSON
Expand Down Expand Up @@ -214,19 +216,19 @@ class RobotHardwareInterface
float getInertialSensorZAccel(const std::string & sensor_name);
float getInertialSensorHeading(const std::string & sensor_name);

/////////////////////////////////////////////////////////////
///////////////// Digital Device Interfaces /////////////////
/////////////////////////////////////////////////////////////
bool getDigitalDeviceValue(const std::string & device_name);
void setDigitalOutputValue(const std::string & device_name, bool value);
void setDigitalInputValue(const std::string & device_name, bool value);

//////////////////////////////////////////////////////////////
///////////////// Joystick Device Interfaces /////////////////
//////////////////////////////////////////////////////////////
std::shared_ptr<devices::JoystickDeviceData> getMainJoystickData();
std::shared_ptr<devices::JoystickDeviceData> getPartnerJoystickData();

//////////////////////////////////////////////////////////////
///////////////////////// Digital IO /////////////////////////
//////////////////////////////////////////////////////////////

void setDigitalIO(const std::vector<bool> & digital_io);
const std::vector<bool> & getDigitalIO() const;

/////////////////////////////////////////////////////////
/////////////////// Device Interfaces ///////////////////
/////////////////////////////////////////////////////////
Expand Down Expand Up @@ -397,9 +399,6 @@ class RobotHardwareInterface
bool is_autonomous_ = false;
bool is_connected_ = false;

// Digital IO
std::vector<bool> digital_io_;

// Serialization
int msg_id_ = 0;
int sensor_update_msg_length_;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Maxx Wilson
* Copyright (c) 2024 Maxx Wilson, Xander Wilson
* All rights reserved.

* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -26,6 +26,7 @@
#include <memory>
#include <ghost_util/test_util.hpp>
#include "ghost_v5_interfaces/devices/inertial_sensor_device_interface.hpp"
#include "ghost_v5_interfaces/devices/digital_device_interface.hpp"
#include "ghost_v5_interfaces/devices/joystick_device_interface.hpp"
#include "ghost_v5_interfaces/devices/motor_device_interface.hpp"
#include "ghost_v5_interfaces/devices/rotation_sensor_device_interface.hpp"
Expand Down Expand Up @@ -183,6 +184,18 @@ std::shared_ptr<devices::InertialSensorDeviceData> getRandomInertialSensorData(
return inertial_sensor_ptr;
}


std::shared_ptr<devices::DigitalOutputDeviceData> getRandomDigitalOutputDeviceData(){
auto digital_output_ptr = std::make_shared<devices::DigitalOutputDeviceData>("test");
digital_output_ptr->value = ghost_util::getRandomBool();
return digital_output_ptr;
}

std::shared_ptr<devices::DigitalInputDeviceData> getRandomDigitalInputDeviceData(){
auto digital_input_ptr = std::make_shared<devices::DigitalInputDeviceData>("test");
digital_input_ptr->value = ghost_util::getRandomBool();
return digital_input_ptr;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ namespace util
*
* port_configuration:
* use_partner_joystick = false/true
* adi:
* limit_switch_1:
* port: A
* type: DIGITAL_INPUT
* devices:
* my_motor_name_here:
* port: 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const std::unordered_map<std::string, devices::device_type_e> STRING_TO_DEVICE_T
{"VISION_SENSOR", devices::device_type_e::VISION_SENSOR},
{"GPS_SENSOR", devices::device_type_e::GPS_SENSOR},
{"RADIO", devices::device_type_e::RADIO},
{"DIGITAL_INPUT", devices::device_type_e::DIGITAL_INPUT},
{"DIGITAL_OUTPUT", devices::device_type_e::DIGITAL_OUTPUT},
{"INVALID", devices::device_type_e::INVALID},
};
const std::unordered_map<devices::device_type_e, std::string> DEVICE_TYPE_TO_STRING_MAP{
Expand All @@ -54,6 +56,8 @@ const std::unordered_map<devices::device_type_e, std::string> DEVICE_TYPE_TO_STR
{devices::device_type_e::VISION_SENSOR, "VISION_SENSOR"},
{devices::device_type_e::GPS_SENSOR, "GPS_SENSOR"},
{devices::device_type_e::RADIO, "RADIO"},
{devices::device_type_e::DIGITAL_INPUT, "DIGITAL_INPUT"},
{devices::device_type_e::DIGITAL_OUTPUT, "DIGITAL_OUTPUT"},
{devices::device_type_e::INVALID, "INVALID"}
};

Expand Down
Loading