2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2018-06-30 02:45:21 -05:00
|
|
|
|
|
|
|
|
#include "GazeboPCM.h"
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2019-10-19 11:35:56 -07:00
|
|
|
#include <hal/Value.h>
|
2020-06-27 22:11:24 -07:00
|
|
|
#include <hal/simulation/NotifyListener.h>
|
|
|
|
|
#include <hal/simulation/PCMData.h>
|
2018-07-20 00:03:45 -07:00
|
|
|
|
2018-06-30 02:45:21 -05:00
|
|
|
#include "simulation/gz_msgs/msgs.h"
|
|
|
|
|
|
|
|
|
|
static void init_callback(const char* name, void* param,
|
|
|
|
|
const struct HAL_Value* value) {
|
|
|
|
|
GazeboPCM* pcm = static_cast<GazeboPCM*>(param);
|
|
|
|
|
pcm->SetInitialized(value->data.v_boolean);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void output_callback(const char* name, void* param,
|
|
|
|
|
const struct HAL_Value* value) {
|
|
|
|
|
GazeboPCM* pcm = static_cast<GazeboPCM*>(param);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (pcm->IsInitialized())
|
|
|
|
|
pcm->Publish(value->data.v_boolean);
|
2018-06-30 02:45:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GazeboPCM::GazeboPCM(int index, int channel, HALSimGazebo* halsim) {
|
|
|
|
|
m_index = index;
|
|
|
|
|
m_channel = channel;
|
|
|
|
|
m_halsim = halsim;
|
|
|
|
|
m_pub = NULL;
|
|
|
|
|
HALSIM_RegisterPCMSolenoidInitializedCallback(index, channel, init_callback,
|
|
|
|
|
this, true);
|
|
|
|
|
HALSIM_RegisterPCMSolenoidOutputCallback(index, channel, output_callback,
|
|
|
|
|
this, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GazeboPCM::Publish(bool value) {
|
|
|
|
|
if (!m_pub) {
|
|
|
|
|
m_pub = m_halsim->node.Advertise<gazebo::msgs::Bool>(
|
|
|
|
|
"~/simulator/pneumatic/" + std::to_string(m_index + 1) + "/" +
|
|
|
|
|
std::to_string(m_channel));
|
|
|
|
|
m_pub->WaitForConnection(gazebo::common::Time(1, 0));
|
|
|
|
|
}
|
|
|
|
|
gazebo::msgs::Bool msg;
|
|
|
|
|
msg.set_data(value);
|
2020-12-28 12:58:06 -08:00
|
|
|
if (m_pub)
|
|
|
|
|
m_pub->Publish(msg);
|
2018-06-30 02:45:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GazeboPCM_SetPressureSwitch(int index, bool value) {
|
|
|
|
|
HALSIM_SetPCMPressureSwitch(index, value);
|
|
|
|
|
}
|