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

VLC #56

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

VLC #56

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: 2 additions & 0 deletions Library/include/actuators/Light.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ namespace sf
//! A method returning the type of the actuator.
ActuatorType getType() const;

OpenGLLight* getGLLight();

private:
void InitGraphics();

Expand Down
17 changes: 16 additions & 1 deletion Library/include/comms/Comm.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,39 @@
#include <SDL2/SDL_mutex.h>
#include <deque>
#include "StonefishCommon.h"
#include <variant>

namespace sf
{
//! An enum defining types of comms.
enum class CommType {RADIO, ACOUSTIC, USBL, VLC};
enum class CommType {RADIO, ACOUSTIC, USBL, VLC, OPTIC};

struct Renderable;
class Entity;
class StaticEntity;
class MovingEntity;

struct Point {
float x, y, z;
float intensity;
};

struct PointCloud {
std::vector<Point> points;
std::string frame_id;
double timestamp;
};

struct CommDataFrame
{
using DataType = std::variant<int, float, double, std::string, std::vector<uint8_t>, std::vector<float>, std::vector<double>, PointCloud>;

Scalar timeStamp;
uint64_t seq;
uint64_t source;
uint64_t destination;
std::string data;
DataType data_mission;
};

//! An abstract class representing a communication device.
Expand Down
127 changes: 127 additions & 0 deletions Library/include/comms/VLC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
This file is a part of Stonefish.

Stonefish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Stonefish is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

//
// VLC.h
// Stonefish

#ifndef __Stonefish_VLC__
#define __Stonefish_VLC__

#include "actuators/Light.h"
#include "comms/Comm.h"
#include "graphics/OpenGLDataStructs.h"
#include <map>

namespace sf
{
class Light;
class StaticEntity;
class AnimatedEntity;

//! A class representing a light of two common types: omni and spot.
class VLC : public Comm
{
public:
//! A constructor of an omni light.
/*!
\param uniqueName a name of the light
\param radius a radius of the light source [m]
\param color a color of the light
\param lum the luminous power of the light [lm]
*/
VLC(std::string uniqueName, uint64_t deviceId, Scalar minVerticalFOVDeg, Scalar maxVerticalFOVDeg, Scalar range, Scalar comm_speed);

void SendMessage(std::string data, const CommDataFrame::DataType& data_mission);
//! A constructor of a spot light.
/*!
\param uniqueName a name of the light
\param radius a radius of the light source [m]
\param coneAngleDeg a cone angle of the spot light in degrees [deg]
\param color a color of the light
\param lum the luminous power of the light [lm]
*/

//! A method used to attach the comm device to the world origin.
/*!
\param origin the place where the comm should be attached in the world frame
*/
/*!
\param dt a time step of the simulation
*/
virtual void InternalUpdate(Scalar dt);

//! A method implementing the rendering of the light dummy.
std::vector<Renderable> Render();

//! A method returning the type of the actuator.
CommType getType() const;

std::vector<Light*> getLights();

void SwitchOff();

void SwitchOn();

bool isActive();

void enable(bool t);

Scalar getRange();

void setRange(Scalar r);

Scalar getCommSpeed();

void setCommSpeed(Scalar r);

void addLight(Light* l);

bool getOcclusionTest() const;
CommDataFrame* getData();
void setWaterType(Scalar t);



protected:

virtual void ProcessMessages();
static VLC* getNode(uint64_t deviceId);

private:

Scalar R;
Scalar Fi;
Scalar coneAngle;
std::vector<Light*> lights;
Scalar minFov2, maxFov2;
bool active;
Scalar range;
Scalar comm_speed;
static std::vector<uint64_t> getNodeIds();
static bool mutualContact(uint64_t device1Id, uint64_t device2Id);
bool isReceptionPossible(Vector3 dir, Scalar distance);
bool occlusion;
static std::map<uint64_t, VLC*> nodes;
CommDataFrame* data;
Scalar water_type;


};
}

#endif
40 changes: 40 additions & 0 deletions Library/include/core/Battery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef BATTERY_H
#define BATTERY_H

#include <vector>
#include "sensors/Sensor.h"
#include <iostream>

namespace sf
{

class Battery
{
private:
float voltage; // Battery voltage in volts
float capacity; // Battery capacity in ampere-hours (Ah)
float maxCapacity; // Maximum battery capacity in ampere-hours
double powerDraw; // Current power draw in watts (calculated)
double energyRemaining; // Energy remaining in watt-hours (Wh)

public:
Battery(float voltage, float capacity);

// Copy Constructor
Battery(const Battery& other);

// Assignment Operator
Battery& operator=(const Battery& other);

float getVoltage() const;
float getCapacity() const;
double getEnergyRemaining() const;
void consume(const std::vector<Sensor*>& sensors, float timeStep); // timeStep in seconds
void setVoltage(Scalar v);
void setMaxCapacity(Scalar mc);
};

} // namespace sf

#endif // BATTERY_H

6 changes: 6 additions & 0 deletions Library/include/core/Robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <utility>
#include "StonefishCommon.h"
#include "joints/Joint.h"
#include "Battery.h"

namespace sf
{
Expand Down Expand Up @@ -239,6 +240,10 @@ namespace sf
//! A method returning type of algorithm used for the robot.
virtual RobotType getType() const = 0;

Battery* getBattery();

void setBattery(Battery* b);

protected:
struct JointData
{
Expand All @@ -259,6 +264,7 @@ namespace sf
std::vector<Actuator*> actuators;
std::vector<Comm*> comms;
std::string name;
Battery* battery;
bool fixed;
};
}
Expand Down
3 changes: 3 additions & 0 deletions Library/include/core/ScenarioParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace sf
class Robot;
class Entity;
class SolidEntity;
class Battery;
class Sensor;
class Actuator;
class Light;
Expand Down Expand Up @@ -273,6 +274,8 @@ namespace sf
*/
virtual FixedJoint* ParseGlue(XMLElement* element);

virtual bool ParseBattery(XMLElement* element, Battery* battery);

//! A method to get the full file path depending on the format of the passed string.
/*!
\param path a file path candidate
Expand Down
2 changes: 1 addition & 1 deletion Library/include/sensors/ScalarSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
namespace sf
{
//! An enum defining types of scalar sensors.
enum class ScalarSensorType {ACC, CURRENT, DVL, COMPASS, FT, GPS, GYRO, IMU, INS, MULTIBEAM, ODOM, PRESSURE, PROFILER, ENCODER, TORQUE, POSE};
enum class ScalarSensorType {ACC, CURRENT, DVL, COMPASS, FT, GPS, GYRO, IMU, INS, MULTIBEAM, ODOM, PRESSURE, PROFILER, ENCODER, TORQUE, LASERMEMS, POSE};

//! An enum defining the type of quantity represented by the measurement.
enum class QuantityType
Expand Down
40 changes: 28 additions & 12 deletions Library/include/sensors/Sensor.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace sf

//! A method used to mark data as old.
void MarkDataOld();

//! A method to check if new data is available.
bool isNewDataAvailable() const;

Expand All @@ -75,27 +75,23 @@ namespace sf
*/
void setUpdateFrequency(Scalar f);

//! A method returning the sensor's name.
std::string getName() const;

//! A method returning the sampling rate of the sensor.
Scalar getUpdateFrequency() const;

//! A method informing if the sensor is enabled.
bool isEnabled() const;

//! A method informing if the sensor is renderable.
bool isRenderable() const;

//! A method to set if the sensor is enabled.
void setEnabled(bool en);

//! A method to set if the sensor is renderable.
void setRenderable(bool render);

//! A method to set the visual representation of the sensor.
void setVisual(const std::string& meshFilename, Scalar scale, const std::string& look);


//! A method returning the sensor name.
std::string getName() const;

void setName(std::string n);

//! A method performing an internal update of the sensor state.
/*!
\param dt the sampling time of the simulation [s]
Expand All @@ -107,6 +103,23 @@ namespace sf

//! A method returning the sensor measurement frame.
virtual Transform getSensorFrame() const = 0;

Scalar getPower();

Scalar getVoltage();

Scalar getDutyCycle();

void setWatt(Scalar w);

void setVoltage(Scalar v);

void setDutyCycle(Scalar dt_c);

void setEnabled(bool en);

bool isEnabled() const;


protected:
Scalar freq;
Expand All @@ -120,9 +133,12 @@ namespace sf
Scalar eleapsedTime;
bool newDataAvailable;
bool renderable;
bool enabled;
int lookId;
int graObjectId;
bool enabled;
Scalar voltage;
Scalar watt;
Scalar duty_cycle;
};
}

Expand Down
Loading