Skip to content
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
3 changes: 3 additions & 0 deletions SubZero/src/settings/settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ SIMSUB_START_X = 50.0
SIMSUB_START_Y = 50.0
SIMSUB_START_Z = 50.0
SIMSUB_START_YAW = 30.0
SIMSUB_START_SPEED = 2
SIMSUB_START_DEPTH_SPEED = 1
SIMSUB_START_ANGULAR_SPEED = 1

SIMSUB_UPDATE_FREQ = 20.0
39 changes: 31 additions & 8 deletions SubZero/src/simulator/SimFPGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ SimFPGA::SimFPGA(Properties* properties) {
position.y = std::stod(properties->getProperty("SIMSUB_START_Y"));
position.z = std::stod(properties->getProperty("SIMSUB_START_Z"));
yaw = std::stod(properties->getProperty("SIMSUB_START_YAW"));
speed = 0;
depth_speed = 0;
angular_speed = 0;
speed = std::stoi(properties->getProperty("SIMSUB_START_SPEED"));;
depth_speed = std::stoi(properties->getProperty("SIMSUB_START_DEPTH_SPEED"));;
angular_speed = std::stoi(properties->getProperty("SIMSUB_START_ANGULAR_SPEED"));;
accel = 0;
depth_accel = 0;
angular_accel = 0;
Expand Down Expand Up @@ -44,7 +44,8 @@ void SimFPGA::updateLoop() {
if (timeElapsed > update_period) {
timer.start();
if(power && motors) {
update(timeElapsed);
//update(timeElapsed);
update2(timeElapsed);
}
}
}
Expand Down Expand Up @@ -99,6 +100,32 @@ void SimFPGA::update(double period) {
//TODO call code to update simulator engine's sub's position and yaw
}

void SimFPGA::update2(double timeElapsed) {
//assume all speed in per second units

//updating z
if (position.z > target_depth)
position.z -= depth_speed * timeElapsed;
else if (position.z < target_depth)
position.z += depth_speed * timeElapsed;
else
continue;

//updating x
position.x += speed;

//updating y
//we don't care :D atm

//updating yaw
target_yaw=target_yaw%360;
if (yaw < target_yaw)
yaw += angular_speed * timeElapsed;
else if (yaw > target_yaw)
yaw -= angular_speed * timeElapsed;
else
continue;
}

void SimFPGA::power_on() {
power = true;
Expand Down Expand Up @@ -142,7 +169,3 @@ int SimFPGA::get_yaw() {
int SimFPGA::get_depth() {
return -(int)position.z;
}




10 changes: 8 additions & 2 deletions SubZero/src/simulator/SimFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ typedef struct {
double z;
} sim_position;

enum dir {
X,
Y,
Z
};

#define ACCEL 5
#define DEPTH_ACCEL 5
#define ANGULAR_ACCEL 3
Expand Down Expand Up @@ -54,7 +60,7 @@ class SimFPGA {

void updateLoop();
void update(double period);

void update2(double period);

public:

Expand Down Expand Up @@ -83,7 +89,7 @@ class SimFPGA {
void power_off();
int get_power();

void set_target_speed(int);
void set_target_speed(int speed);
void set_target_depth(int);
void set_target_yaw(int);

Expand Down