sgslib 0.4.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sgs/alarm.rb CHANGED
@@ -1,36 +1,42 @@
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
  ##
29
37
  # Routines for handling sailboat alarms. Note that this is the definitive
30
38
  # list of alarms on the system. To add or modify an alarm, do so here.
31
39
  #
32
- require 'date'
33
-
34
40
  module SGS
35
41
  ##
36
42
  # Deal with alarm subsystem.
@@ -38,7 +44,9 @@ module SGS
38
44
  class Alarm < RedisBase
39
45
  attr_accessor :last_report, :time
40
46
 
41
- OTTO_RESTART = 0
47
+ #
48
+ # Alarms generated by Otto.
49
+ MISSION_SWITCH = 0
42
50
  RUDDSRV_FAULT = 1
43
51
  SAILSRV_FAULT = 2
44
52
  VBATT_CRITICAL = 3
@@ -54,16 +62,18 @@ module SGS
54
62
  RUDDER_NOZERO = 13
55
63
  SAIL_NOZERO = 14
56
64
  MOTHER_UNRESP = 15
57
-
58
- MISSION_COMMENCE = 16
59
- MISSION_COMPLETE = 17
60
- MISSION_ABORT = 18
61
- WAYPOINT_REACHED = 19
62
- CROSS_TRACK_ERROR = 20
63
- INSIDE_FENCE = 21
65
+ #
66
+ # Alarms generated by Mother.
67
+ OTTO_RESTART = 16
68
+ MISSION_COMMENCE = 17
69
+ MISSION_COMPLETE = 18
70
+ MISSION_ABORT = 19
71
+ WAYPOINT_REACHED = 20
72
+ CROSS_TRACK_ERROR = 21
73
+ INSIDE_FENCE = 22
64
74
 
65
75
  ALARM_NAMES = [
66
- "OTTO Restarted",
76
+ "Mission Activation Switch",
67
77
  "Rudder Servo Fault",
68
78
  "Sail Servo Fault",
69
79
  "Battery voltage is critically low",
@@ -79,6 +89,7 @@ module SGS
79
89
  "Cannot zero the rudder position",
80
90
  "Cannot zero the sail position",
81
91
  "Mother is unresponsive",
92
+ "OTTO Restarted",
82
93
  "Mission has commenced",
83
94
  "Mission is completed",
84
95
  "*** MISSION ABORT ***",
@@ -94,6 +105,37 @@ module SGS
94
105
  super
95
106
  end
96
107
 
108
+ #
109
+ # Main daemon function (called from executable)
110
+ def self.daemon
111
+ puts "Alarm daemon starting up..."
112
+ otto = SGS::RPCClient.new(:otto)
113
+ loop do
114
+ #puts "Check for any alarms..."
115
+ #resp = otto.command "A?"
116
+ #puts "Response: #{resp}"
117
+ sleep 30
118
+ end
119
+ end
120
+
121
+ #
122
+ # Build a C include file based on the current alarm definitions
123
+ def self.build_include(fname)
124
+ alarm = new
125
+ File.open(fname, "w") do |f|
126
+ f.puts "/*\n * Autogenerated by #{__FILE__}.\n * DO NOT HAND-EDIT!\n */"
127
+ constants.sort.each do |c|
128
+ unless c == :ALARM_NAMES
129
+ cval = SGS::Alarm.const_get(c)
130
+ str = "#define SGS_ALARM_#{c.to_s}"
131
+ str += "\t" if str.length < 32
132
+ str += "\t#{cval}\t/* #{alarm.name(cval)} */"
133
+ f.puts str
134
+ end
135
+ end
136
+ end
137
+ end
138
+
97
139
  #
98
140
  # Convert an alarm number into a string.
99
141
  def name(alarmno)
@@ -0,0 +1,151 @@
1
+ #
2
+ #
3
+ # Copyright (c) 2013-2023, Kalopa Robotics Limited. All rights
4
+ # reserved.
5
+ #
6
+ # This program is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU General Public License as
8
+ # published by the Free Software Foundation; either version 2 of
9
+ # the License, or (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
+ # 02110-1301, USA.
20
+ #
21
+ # THIS SOFTWARE IS PROVIDED BY KALOPA ROBOTICS LIMITED "AS IS" AND
22
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23
+ # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24
+ # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KALOPA
25
+ # ROBOTICS LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
+ # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28
+ # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+ # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32
+ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
+ #
34
+ # ABSTRACT
35
+ #
36
+
37
+ ##
38
+ # Routines for handling sailboat bearings.
39
+ #
40
+ require 'json'
41
+
42
+ module SGS
43
+ ##
44
+ # Class for dealing with the angle/distance vector.
45
+ #
46
+ # Note that for convenience, we retain the angle in Radians. The
47
+ # distance is in nautical miles.
48
+ class Bearing
49
+ attr_accessor :distance
50
+
51
+ #
52
+ # Create the Bearing instance.
53
+ def initialize(angle = 0.0, distance = 0.0)
54
+ self.angle = angle.to_f
55
+ self.distance = distance.to_f
56
+ end
57
+
58
+ #
59
+ # Create a bearing from an angle in degrees.
60
+ def self.degrees(angle, distance)
61
+ new(Bearing.dtor(angle), distance)
62
+ end
63
+
64
+ #
65
+ # Handy function to translate degrees to radians
66
+ def self.dtor(deg)
67
+ deg.to_f * Math::PI / 180.0
68
+ end
69
+
70
+ #
71
+ # Handy function to translate radians to degrees
72
+ def self.rtod(rad)
73
+ rad.to_f * 180.0 / Math::PI
74
+ end
75
+
76
+ #
77
+ # Handy function to re-adjust an angle away from negative
78
+ def self.absolute(angle)
79
+ (angle + 2.0 * Math::PI) % (2.0 * Math::PI)
80
+ end
81
+
82
+ #
83
+ # Another handy function to re-adjust an angle (in degrees) away from
84
+ # negative.
85
+ def self.absolute_d(angle)
86
+ (angle + 360) % 360
87
+ end
88
+
89
+ #
90
+ # Haversine formula for calculating distance and angle, given two
91
+ # locations.
92
+ #
93
+ # To calculate an angle and distance from two positions:
94
+ #
95
+ # This code was derived from formulae on the Movable Type site:
96
+ # http://www.movable-type.co.uk/scripts/latlong.html
97
+ #
98
+ # var d = Math.acos(Math.sin(lat1)*Math.sin(lat2) +
99
+ # Math.cos(lat1)*Math.cos(lat2) *
100
+ # Math.cos(lon2-lon1)) * R;
101
+ # var y = Math.sin(dLon) * Math.cos(lat2);
102
+ # var x = Math.cos(lat1)*Math.sin(lat2) -
103
+ # Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
104
+ # var angle = Math.atan2(y, x).toDeg();
105
+ def self.compute(loc1, loc2)
106
+ bearing = new
107
+ sin_lat1 = Math.sin(loc1.latitude)
108
+ sin_lat2 = Math.sin(loc2.latitude)
109
+ cos_lat1 = Math.cos(loc1.latitude)
110
+ cos_lat2 = Math.cos(loc2.latitude)
111
+ sin_dlon = Math.sin(loc2.longitude - loc1.longitude)
112
+ cos_dlon = Math.cos(loc2.longitude - loc1.longitude)
113
+ bearing.distance = Math.acos(sin_lat1*sin_lat2 + cos_lat1*cos_lat2*cos_dlon) *
114
+ SGS::EARTH_RADIUS
115
+ y = sin_dlon * cos_lat2
116
+ x = cos_lat1 * sin_lat2 - sin_lat1 * cos_lat2 * cos_dlon
117
+ bearing.angle = Math.atan2(y, x)
118
+ bearing
119
+ end
120
+
121
+ #
122
+ # Set the angle
123
+ def angle=(angle)
124
+ @angle = Bearing.absolute(angle)
125
+ end
126
+
127
+ #
128
+ # Get the angle
129
+ def angle
130
+ @angle
131
+ end
132
+
133
+ #
134
+ # Return the angle (in degrees)
135
+ def angle_d
136
+ Bearing.rtod(@angle).to_i
137
+ end
138
+
139
+ #
140
+ # Get the back-angle (the angle viewed from the opposite end of the line)
141
+ def back_angle
142
+ Bearing.absolute(@angle - Math::PI)
143
+ end
144
+
145
+ #
146
+ # Convert to a string
147
+ def to_s
148
+ "BRNG %03dd,%.3fnm" % [angle_d, @distance]
149
+ end
150
+ end
151
+ 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,50 @@
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
+ puts "Diagnostics subsystem starting up..."
45
+ loop do
46
+ sleep 300
47
+ end
48
+ end
49
+ end
50
+ end
data/lib/sgs/gps.rb CHANGED
@@ -1,29 +1,39 @@
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.
26
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
+ require 'serialport'
36
+
27
37
  module SGS
28
38
  class GPS < RedisBase
29
39
  attr_accessor :time, :location, :sog, :cmg, :magvar
@@ -38,6 +48,25 @@ module SGS
38
48
  super()
39
49
  end
40
50
 
51
+ #
52
+ # Main daemon function (called from executable)
53
+ def self.daemon
54
+ puts "GPS reader starting up..."
55
+ config = SGS::Config.load
56
+
57
+ sp = SerialPort.new config.gps_device, config.gps_speed
58
+ sp.read_timeout = 10000
59
+
60
+ loop do
61
+ nmea = SGS::NMEA.parse sp.readline
62
+ if nmea.is_gprmc?
63
+ gps = nmea.parse_gprmc
64
+ p gps
65
+ gps.save_and_publish if gps and gps.valid?
66
+ end
67
+ end
68
+ end
69
+
41
70
  #
42
71
  # Set the validity
43
72
  def is_valid