Skip to content

Commit bd6677d

Browse files
author
mfbehrens99
committed
CHANGELOG and small changes in Boat.py
Mainly comments and stuff
1 parent 23c5972 commit bd6677d

3 files changed

Lines changed: 35 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,27 @@ Template
2222
2323
--->
2424

25+
## [Unreleased]
26+
27+
### Added
28+
29+
- [[Boat]] Add torques to the boat to make it spin
30+
- [[Simulation]] Run simulation for x steps
31+
- [[Sailor]] Basic rudder steering
32+
- [[GUI]] Display rudder forces in [boatInspector]
33+
34+
### Changed
35+
36+
- [[Boat]] Move forces and torques to their own files
37+
- [[Boat]] Rename waterDrag and waterLift to centerboardDrag and centerboardLift
38+
- [[Sailor]] Don't delete Waypoints after executing them
39+
40+
### Removed
41+
42+
- [[Boat]] Removed Boat::getSpeedSq()
43+
44+
45+
2546
## [0.0.1] - 2021-04-13
2647

2748
### Added
@@ -47,4 +68,6 @@ Template
4768
[Sailor]: https://github.com/mfbehrens99/sailsim/blob/main/sailsim/sailor/Sailor.py
4869
[Wind]: https://github.com/mfbehrens99/sailsim/blob/main/sailsim/wind/Wind.py
4970
[GUI]: https://github.com/mfbehrens99/sailsim/tree/main/sailsim/gui
71+
[mapView]: https://github.com/mfbehrens99/sailsim/blob/main/sailsim/gui/mapView.py
72+
[boatInspector]: https://github.com/mfbehrens99/sailsim/blob/main/sailsim/gui/boatInspector.py
5073
[utils]: https://github.com/mfbehrens99/sailsim/tree/main/sailsim/utils

sailsim/boat/Boat.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,26 @@ def __init__(self, posX=0, posY=0, direction=0, speedX=0, speedY=0, angSpeed=0):
7070
self.tackingAngleDownwind = 20 / 180 * pi
7171

7272

73-
# Simulation
73+
# Simulation methods
7474
def applyCauses(self, forceX, forceY, torque, interval):
7575
"""Change speed according a force & torque given."""
76-
# △v = a * t ; F = m * a
77-
# △v = F / m * t
76+
# Translation: △v = a * t; F = m * a -> △v = F / m * t
77+
# Rotation: △ω = α * t; M = I * α -> △ω = M / I * t
7878
self.speedX += forceX / self.mass * interval
7979
self.speedY += forceY / self.mass * interval
80-
81-
# △ω = α * t; M = I * α
82-
# △ω = M / I * t
8380
self.angSpeed += torque / self.momentumInertia * interval
8481

8582
def moveInterval(self, interval):
8683
"""Change position according to sailsDirection and speed."""
87-
# s = v * t
84+
# s = v * t; △α = ω * t
8885
self.posX += self.speedX * interval
8986
self.posY += self.speedY * interval
9087
self.direction = directionKeepInterval(self.direction + self.angSpeed * interval)
9188

9289
def runSailor(self):
9390
"""Activate the sailing algorithm to decide what the boat should do."""
9491
if not self.sailor is None:
92+
# Run sailor if sailor exists
9593
self.sailor.run(
9694
self.posX,
9795
self.posY,
@@ -100,26 +98,24 @@ def runSailor(self):
10098
self.direction,
10199
self.dataHolder.apparentWindSpeed,
102100
self.dataHolder.apparentWindAngle
103-
) # Run sailor
101+
)
104102

105-
# Set boat properties
103+
# Retrieve boat properties from Sailor
106104
self.mainSailAngle = self.sailor.mainSailAngle
107105
# self.direction = self.sailor.boatDirection
108106
self.rudderAngle = self.sailor.rudderAngle
109107

110-
111-
# Force & Torque calculations
112108
def resultingCauses(self, trueWindX, trueWindY):
113109
"""Add up all acting forces and return them as a tuple."""
114110
h = self.dataHolder
115111

112+
h.boatSpeed = self.boatSpeed()
113+
116114
# calculate apparent wind angle
117115
(h.apparentWindX, h.apparentWindY) = self.apparentWind(trueWindX, trueWindY)
118116
h.apparentWindAngle = self.apparentWindAngle(h.apparentWindX, h.apparentWindY)
119-
120117
apparentWindSpeedSq = cartToRadiusSq(h.apparentWindX, h.apparentWindY)
121118
h.apparentWindSpeed = sqrt(apparentWindSpeedSq)
122-
h.boatSpeed = self.boatSpeed()
123119

124120
# calculate flowSpeed
125121
(flowSpeedRudderX, flowSpeedRudderY) = self.leverSpeedVector(self.rudderLever)
@@ -141,7 +137,6 @@ def resultingCauses(self, trueWindX, trueWindY):
141137
h.leewayAngle = self.calcLeewayAngle()
142138
h.angleOfAttack = self.angleOfAttack(h.apparentWindAngle)
143139

144-
# Sum up all acting forces
145140
(forceX, forceY, torque) = (0, 0, 0)
146141

147142
# Sail forces
@@ -184,15 +179,11 @@ def resultingCauses(self, trueWindX, trueWindY):
184179
(h.forceX, h.forceY, h.torque) = (forceX, forceY, torque)
185180
return (forceX, forceY, torque)
186181

182+
# Import force and torque functions
187183
from .boat_forces import leverSpeedVector, sailDrag, sailLift, centerboardDrag, centerboardLift, rudderDrag, rudderLift, scalarToDragForce, scalarToLiftForce
188184
from .boat_torques import waterDragTorque, centerboardTorque, rudderTorque
189185

190186

191-
# Speed calculations
192-
def boatSpeedSq(self):
193-
"""Return speed of the boat but squared."""
194-
return pow(self.speedX, 2) + pow(self.speedY, 2)
195-
196187
def boatSpeed(self):
197188
"""Return speed of the boat."""
198189
return sqrt(pow(self.speedX, 2) + pow(self.speedY, 2))
@@ -218,4 +209,4 @@ def angleOfAttack(self, apparentWindAngle):
218209

219210
def __repr__(self):
220211
heading = round(cartToArg(self.speedX, self.speedY) * 180 / pi, 2)
221-
return "Boat @(%s|%s), v=%sm/s twds %s°" % (round(self.posX, 3), round(self.posY, 3), round(sqrt(self.boatSpeedSq()), 2), heading)
212+
return "Boat @(%s|%s), v=%sm/s twds %s°" % (round(self.posX, 3), round(self.posY, 3), round(self.boatSpeed(), 2), heading)

tests/basictest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@
5656
app = QApplication(sys.argv)
5757
window = SailsimGUI(s)
5858
window.show()
59-
sys.exit(app.exec_())
59+
sys.exit(app.exec())

0 commit comments

Comments
 (0)