sgslib 0.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,150 @@
1
+ #
2
+ # Copyright (c) 2013-2023, Kalopa Robotics Limited. All rights
3
+ # reserved.
4
+ #
5
+ # This program is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License as
7
+ # published by the Free Software Foundation; either version 2 of
8
+ # the License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
+ # 02110-1301, USA.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY KALOPA ROBOTICS LIMITED "AS IS" AND
21
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KALOPA
24
+ # ROBOTICS LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27
+ # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ #
33
+ # ABSTRACT
34
+ #
35
+
36
+ ##
37
+ # Routines for handling sailboat bearings.
38
+ #
39
+ require 'json'
40
+
41
+ module SGS
42
+ ##
43
+ # Class for dealing with the angle/distance vector.
44
+ #
45
+ # Note that for convenience, we retain the angle in Radians. The
46
+ # distance is in nautical miles.
47
+ class Bearing
48
+ attr_accessor :distance
49
+
50
+ #
51
+ # Create the Bearing instance.
52
+ def initialize(angle = 0.0, distance = 0.0)
53
+ self.angle = angle.to_f
54
+ self.distance = distance.to_f
55
+ end
56
+
57
+ #
58
+ # Create a bearing from an angle in degrees.
59
+ def self.degrees(angle, distance)
60
+ new(Bearing.dtor(angle), distance)
61
+ end
62
+
63
+ #
64
+ # Handy function to translate degrees to radians
65
+ def self.dtor(deg)
66
+ deg.to_f * Math::PI / 180.0
67
+ end
68
+
69
+ #
70
+ # Handy function to translate radians to degrees
71
+ def self.rtod(rad)
72
+ rad.to_f * 180.0 / Math::PI
73
+ end
74
+
75
+ #
76
+ # Handy function to re-adjust an angle away from negative
77
+ def self.absolute(angle)
78
+ (angle + 2.0 * Math::PI) % (2.0 * Math::PI)
79
+ end
80
+
81
+ #
82
+ # Another handy function to re-adjust an angle (in degrees) away from
83
+ # negative.
84
+ def self.absolute_d(angle)
85
+ (angle + 360) % 360
86
+ end
87
+
88
+ #
89
+ # Haversine formula for calculating distance and angle, given two
90
+ # locations.
91
+ #
92
+ # To calculate an angle and distance from two positions:
93
+ #
94
+ # This code was derived from formulae on the Movable Type site:
95
+ # http://www.movable-type.co.uk/scripts/latlong.html
96
+ #
97
+ # var d = Math.acos(Math.sin(lat1)*Math.sin(lat2) +
98
+ # Math.cos(lat1)*Math.cos(lat2) *
99
+ # Math.cos(lon2-lon1)) * R;
100
+ # var y = Math.sin(dLon) * Math.cos(lat2);
101
+ # var x = Math.cos(lat1)*Math.sin(lat2) -
102
+ # Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
103
+ # var angle = Math.atan2(y, x).toDeg();
104
+ def self.compute(loc1, loc2)
105
+ bearing = new
106
+ sin_lat1 = Math.sin(loc1.latitude)
107
+ sin_lat2 = Math.sin(loc2.latitude)
108
+ cos_lat1 = Math.cos(loc1.latitude)
109
+ cos_lat2 = Math.cos(loc2.latitude)
110
+ sin_dlon = Math.sin(loc2.longitude - loc1.longitude)
111
+ cos_dlon = Math.cos(loc2.longitude - loc1.longitude)
112
+ bearing.distance = Math.acos(sin_lat1*sin_lat2 + cos_lat1*cos_lat2*cos_dlon) *
113
+ SGS::EARTH_RADIUS
114
+ y = sin_dlon * cos_lat2
115
+ x = cos_lat1 * sin_lat2 - sin_lat1 * cos_lat2 * cos_dlon
116
+ bearing.angle = Math.atan2(y, x)
117
+ bearing
118
+ end
119
+
120
+ #
121
+ # Set the angle
122
+ def angle=(angle)
123
+ @angle = Bearing.absolute(angle)
124
+ end
125
+
126
+ #
127
+ # Get the angle
128
+ def angle
129
+ @angle
130
+ end
131
+
132
+ #
133
+ # Return the angle (in degrees)
134
+ def angle_d
135
+ Bearing.rtod(@angle).to_i
136
+ end
137
+
138
+ #
139
+ # Get the back-angle (the angle viewed from the opposite end of the line)
140
+ def back_angle
141
+ Bearing.absolute(@angle - Math::PI)
142
+ end
143
+
144
+ #
145
+ # Convert to a string
146
+ def to_s
147
+ "BRNG %03dd,%.3fnm" % [angle_d, @distance]
148
+ end
149
+ end
150
+ end
data/lib/sgs/config.rb CHANGED
@@ -1,38 +1,48 @@
1
1
  #
2
- # Copyright (c) 2018, Kalopa Research. All rights reserved. This is free
3
- # software; you can redistribute it and/or modify it under the terms of the
4
- # GNU General Public License as published by the Free Software Foundation;
5
- # either version 2, or (at your option) any later version.
2
+ # Copyright (c) 2018-2023, Kalopa Robotics Limited. All rights
3
+ # reserved.
6
4
  #
7
- # It is distributed in the hope that it will be useful, but WITHOUT
8
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10
- # for more details.
5
+ # This program is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License as
7
+ # published by the Free Software Foundation; either version 2 of
8
+ # the License, or (at your option) any later version.
11
9
  #
12
- # You should have received a copy of the GNU General Public License along
13
- # with this product; see the file COPYING. If not, write to the Free
14
- # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
15
14
  #
16
- # THIS SOFTWARE IS PROVIDED BY KALOPA RESEARCH "AS IS" AND ANY EXPRESS OR
17
- # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
- # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
- # IN NO EVENT SHALL KALOPA RESEARCH BE LIABLE FOR ANY DIRECT, INDIRECT,
20
- # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
- # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22
- # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23
- # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
+ # 02110-1301, USA.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY KALOPA ROBOTICS LIMITED "AS IS" AND
21
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KALOPA
24
+ # ROBOTICS LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27
+ # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ #
33
+ # ABSTRACT
26
34
  #
27
35
  module SGS
28
36
  class Config < RedisBase
29
37
  attr_accessor :otto_device, :gps_device, :comm_device
30
38
  attr_accessor :otto_speed, :gps_speed, :comm_speed
39
+ attr_accessor :mission_file
31
40
 
32
41
  def initialize
33
- @otto_device = "/dev/ttyU0"
34
- @gps_device = "/dev/ttyU1"
35
- @comm_device = "/dev/ttyU2"
42
+ @mission_file = "/etc/mission.yaml"
43
+ @otto_device = "/dev/ttyu0"
44
+ @gps_device = "/dev/ttyu1"
45
+ @comm_device = "/dev/ttyu2"
36
46
  @otto_speed = @gps_speed = @comm_speed = 9600
37
47
  super()
38
48
  end
@@ -41,6 +51,7 @@ module SGS
41
51
  # Set up the Redis configuration with some basic data
42
52
  def self.configure_all
43
53
  Config.setup
54
+ MissionStatus.setup
44
55
  Alarm.setup
45
56
  GPS.setup
46
57
  Otto.setup
data/lib/sgs/course.rb CHANGED
@@ -1,28 +1,36 @@
1
1
  #
2
- # Copyright (c) 2013, Kalopa Research. All rights reserved. This is free
3
- # software; you can redistribute it and/or modify it under the terms of the
4
- # GNU General Public License as published by the Free Software Foundation;
5
- # either version 2, or (at your option) any later version.
2
+ # Copyright (c) 2013-2023, Kalopa Robotics Limited. All rights
3
+ # reserved.
6
4
  #
7
- # It is distributed in the hope that it will be useful, but WITHOUT
8
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10
- # for more details.
5
+ # This program is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License as
7
+ # published by the Free Software Foundation; either version 2 of
8
+ # the License, or (at your option) any later version.
11
9
  #
12
- # You should have received a copy of the GNU General Public License along
13
- # with this product; see the file COPYING. If not, write to the Free
14
- # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
15
14
  #
16
- # THIS SOFTWARE IS PROVIDED BY KALOPA RESEARCH "AS IS" AND ANY EXPRESS OR
17
- # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
- # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
- # IN NO EVENT SHALL KALOPA RESEARCH BE LIABLE FOR ANY DIRECT, INDIRECT,
20
- # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
- # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22
- # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23
- # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
+ # 02110-1301, USA.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY KALOPA ROBOTICS LIMITED "AS IS" AND
21
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KALOPA
24
+ # ROBOTICS LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27
+ # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ #
33
+ # ABSTRACT
26
34
  #
27
35
 
28
36
  ##
@@ -31,9 +39,6 @@
31
39
  # The code on this page was derived from formulae on the Movable Type site:
32
40
  # http://www.movable-type.co.uk/scripts/latlong.html
33
41
  #
34
-
35
- require 'date'
36
-
37
42
  module SGS
38
43
  ##
39
44
  #
@@ -0,0 +1,49 @@
1
+ #
2
+ # Copyright (c) 2013-2023, Kalopa Robotics Limited. All rights
3
+ # reserved.
4
+ #
5
+ # This program is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License as
7
+ # published by the Free Software Foundation; either version 2 of
8
+ # the License, or (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
+ # 02110-1301, USA.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY KALOPA ROBOTICS LIMITED "AS IS" AND
21
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KALOPA
24
+ # ROBOTICS LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27
+ # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ #
33
+ # ABSTRACT
34
+ #
35
+
36
+ ##
37
+ # Routines for handling sailboat navigation and route planning.
38
+ #
39
+ module SGS
40
+ class Diagnostics < RedisBase
41
+ #
42
+ # Main daemon function (called from executable)
43
+ def self.daemon
44
+ loop do
45
+ sleep 300
46
+ end
47
+ end
48
+ end
49
+ end
data/lib/sgs/gps.rb CHANGED
@@ -1,28 +1,36 @@
1
1
  #
2
- # Copyright (c) 2013, Kalopa Research. All rights reserved. This is free
3
- # software; you can redistribute it and/or modify it under the terms of the
4
- # GNU General Public License as published by the Free Software Foundation;
5
- # either version 2, or (at your option) any later version.
2
+ # Copyright (c) 2013-2023, Kalopa Robotics Limited. All rights
3
+ # reserved.
6
4
  #
7
- # It is distributed in the hope that it will be useful, but WITHOUT
8
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10
- # for more details.
5
+ # This program is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU General Public License as
7
+ # published by the Free Software Foundation; either version 2 of
8
+ # the License, or (at your option) any later version.
11
9
  #
12
- # You should have received a copy of the GNU General Public License along
13
- # with this product; see the file COPYING. If not, write to the Free
14
- # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
15
14
  #
16
- # THIS SOFTWARE IS PROVIDED BY KALOPA RESEARCH "AS IS" AND ANY EXPRESS OR
17
- # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
- # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
- # IN NO EVENT SHALL KALOPA RESEARCH BE LIABLE FOR ANY DIRECT, INDIRECT,
20
- # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
- # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
22
- # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23
- # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
+ # 02110-1301, USA.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY KALOPA ROBOTICS LIMITED "AS IS" AND
21
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
+ # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KALOPA
24
+ # ROBOTICS LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27
+ # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+ #
33
+ # ABSTRACT
26
34
  #
27
35
  module SGS
28
36
  class GPS < RedisBase
@@ -38,6 +46,14 @@ module SGS
38
46
  super()
39
47
  end
40
48
 
49
+ #
50
+ # Main daemon function (called from executable)
51
+ def self.daemon
52
+ loop do
53
+ sleep 300
54
+ end
55
+ end
56
+
41
57
  #
42
58
  # Set the validity
43
59
  def is_valid