mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
Get halsim_gazebo building again (#1201)
This commit is contained in:
committed by
Peter Johnson
parent
fe5d7dd6ba
commit
74efe5aafe
54
simulation/halsim_gazebo/src/main/native/cpp/main.cpp
Normal file
54
simulation/halsim_gazebo/src/main/native/cpp/main.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <HAL/Ports.h>
|
||||
|
||||
#include "GazeboAnalogIn.h"
|
||||
#include "GazeboDIO.h"
|
||||
#include "GazeboEncoder.h"
|
||||
#include "GazeboPCM.h"
|
||||
#include "GazeboPWM.h"
|
||||
#include "HALSimGazebo.h"
|
||||
|
||||
/* Currently, robots never terminate, so we keep a single static object
|
||||
to access Gazebo with and it is never properly released or cleaned up. */
|
||||
static HALSimGazebo halsim;
|
||||
|
||||
extern "C" {
|
||||
int HALSIM_InitExtension(void) {
|
||||
std::cout << "Gazebo Simulator Initializing." << std::endl;
|
||||
|
||||
if (!halsim.node.Connect()) {
|
||||
std::cerr << "Error: unable to connect to Gazebo. Is it running?."
|
||||
<< std::endl;
|
||||
return -1;
|
||||
}
|
||||
std::cout << "Gazebo Simulator Connected." << std::endl;
|
||||
|
||||
for (int i = 0; i < HALSimGazebo::kPWMCount; i++)
|
||||
halsim.pwms[i] = new GazeboPWM(i, &halsim);
|
||||
|
||||
for (int i = 0; i < HALSimGazebo::kPCMCount; i++)
|
||||
halsim.pcms[i] = new GazeboPCM(0, i, &halsim);
|
||||
GazeboPCM_SetPressureSwitch(0, true);
|
||||
|
||||
for (int i = 0; i < HALSimGazebo::kEncoderCount; i++)
|
||||
halsim.encoders[i] = new GazeboEncoder(i, &halsim);
|
||||
|
||||
int analog_in_count = HAL_GetNumAnalogInputs();
|
||||
for (int i = 0; i < analog_in_count; i++)
|
||||
halsim.analog_inputs.push_back(new GazeboAnalogIn(i, &halsim));
|
||||
|
||||
int dio_count = HAL_GetNumDigitalChannels();
|
||||
for (int i = 0; i < dio_count; i++)
|
||||
halsim.dios.push_back(new GazeboDIO(i, &halsim));
|
||||
|
||||
return 0;
|
||||
}
|
||||
} // extern "C"
|
||||
Reference in New Issue
Block a user