-
Notifications
You must be signed in to change notification settings - Fork 2
Feature: SeaTrac vehicle support #73
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
Open
rgov
wants to merge
7
commits into
main
Choose a base branch
from
rzg/seatrac
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8b86dd2
Add SeaTrac node and network comms bridge
rgov 92b70d8
Use frontseat IP address for outbound packets
rgov 56c4f1d
Initial progress towards Starlink manager
rgov 917e38f
Update logic of Starlink manager
rgov 46937e6
Break container cache of seatrac-api package
rgov 75db0b8
Fixed OutletStatus import
figuernd e148789
Add full launch file for SeaTrac vehicles
rgov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <launch> | ||
| <!-- Most settings are in config.yaml, which is easier to edit. --> | ||
| <rosparam command="load" file="$(arg config_file)" /> | ||
|
|
||
| <node name="ifcb" pkg="ifcb" type="ifcb" /> | ||
|
|
||
| <node name="ifcb_logfilter" pkg="ifcb" type="ifcb_logfilter" /> | ||
|
|
||
| <group> | ||
| <node name="seatrac" pkg="seatrac" type="seatrac_node.py"> | ||
| <remap from="~in" to="~comms/in" /> | ||
| <remap from="~out" to="~comms/out" /> | ||
| </node> | ||
|
|
||
| <node ns="seatrac" name="comms" pkg="ds_util_nodes" type="bridge_node"/> | ||
|
|
||
| <node name="seatrac_starlink_manager" pkg="phyto_arm" | ||
| type="seatrac_starlink_manager.py" /> | ||
| </group> | ||
|
|
||
| <!-- Match namespace from arm_ifcb.launch --> | ||
| <group ns="arm_ifcb"> | ||
| <node name="arm" pkg="phyto_arm" type="arm_ifcb.py" /> | ||
|
|
||
| <node name="ctd_comms" pkg="ds_util_nodes" type="bridge_node" /> | ||
|
|
||
| <node name="ctd" pkg="aml_ctd" type="aml_ctd_node.py"> | ||
| <remap from="~in" to="ctd_comms/in" /> | ||
| </node> | ||
|
|
||
| <node name="ifcb_runner" pkg="phyto_arm" type="ifcb_runner.py" /> | ||
| </group> | ||
| </launch> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| #!/usr/bin/env python3 | ||
| import datetime | ||
| import json | ||
| import urllib.request | ||
|
|
||
| import rospy | ||
|
|
||
| from seatrac.msg import OutletStatus, PowerLevel | ||
| from std_msgs.msg import Bool as StdBool | ||
|
|
||
|
|
||
| def send_alerts(alert_config, message): | ||
| for alert in alert_config: | ||
| assert alert['type'] == 'slack' and alert['url'] | ||
| urllib.request.urlopen( | ||
| alert['url'], | ||
| json.dumps({'text': message}).encode() | ||
| ) | ||
|
|
||
|
|
||
| def main(): | ||
| rospy.init_node('seatrac_starlink_manager') | ||
|
|
||
| # Read parameters | ||
| alerts = rospy.get_param('/alerts', []) | ||
| high_threshold = rospy.get_param('~soc_threshold', {}).get('high', 95) | ||
| medium_threshold = rospy.get_param('~soc_threshold', {}).get('medium', 80) | ||
|
|
||
| shutdown_reminder = rospy.get_param('~shutdown_reminder', None) | ||
| if shutdown_reminder is not None: | ||
| shutdown_reminder = rospy.Duration(shutdown_reminder) | ||
|
|
||
| scheduled_on = rospy.get_param('~scheduled_on', None) | ||
| if scheduled_on is not None: | ||
| scheduled_on = datetime.datetime.strptime(scheduled_on, '%H:%M').time() | ||
|
|
||
|
|
||
| # Create a publisher for controlling the Starlink outlet | ||
| outlet_pub = rospy.Publisher('/seatrac/outlet/starlink/control', StdBool, | ||
| queue_size=1) | ||
|
|
||
|
|
||
| # Subscribe to power level messages and record the state of charge, and | ||
| # turn Starlink on automatically if the SOC is high enough. | ||
| charging = False | ||
|
|
||
| already_sent = False | ||
| last_state = None | ||
| soc = 0.0 | ||
|
|
||
| def power_level_cb(msg: PowerLevel) -> None: | ||
| nonlocal already_sent, charging, soc | ||
| if last_state is None: | ||
| return | ||
|
|
||
| soc = msg.soc_percentage | ||
| charging = msg.pack_current < 0 | ||
|
|
||
| if soc >= high_threshold and charging and \ | ||
| not last_state and not already_sent: | ||
rgov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| rospy.loginfo( | ||
| f'Enabling Starlink: SOC {soc}% >= {high_threshold}% and charging' | ||
| ) | ||
| outlet_pub.publish(StdBool(True)) | ||
| already_sent = True | ||
| elif soc < medium_threshold: | ||
| already_sent = False | ||
|
|
||
| rospy.Subscriber('/seatrac/power', PowerLevel, power_level_cb) | ||
|
|
||
|
|
||
| # Nag the operators if Starlink has been active for too long | ||
| nag_timer = None | ||
|
|
||
| def nag_operator() -> None: | ||
| nonlocal nag_timer | ||
| nag_timer = None | ||
| send_alerts(alerts, 'Starlink has been active for a while') | ||
|
|
||
| def outlet_status_cb(msg: OutletStatus) -> None: | ||
| nonlocal nag_timer, last_state | ||
| last_state = msg.is_active | ||
|
|
||
| # Set up the nag timer if Starlink is active (except if we are at a | ||
| # high state of charge and charging). When the outlet is off, cancel | ||
| # the nag timer. | ||
| if shutdown_reminder is None: | ||
| return | ||
|
|
||
| if msg.is_active and nag_timer is None and \ | ||
| not (soc >= high_threshold and charging): | ||
| # Assume we'll be getting outlet status messages regularly, so we | ||
| # can do a one-shot timer. | ||
| nag_timer = rospy.Timer( | ||
| shutdown_reminder, | ||
| nag_operator, | ||
| oneshot=True | ||
| ) | ||
| elif not msg.is_active and nag_timer: | ||
| nag_timer.shutdown() | ||
| nag_timer = None | ||
|
|
||
| rospy.Subscriber('/seatrac/outlet/starlink/status', OutletStatus, | ||
| outlet_status_cb) | ||
|
|
||
|
|
||
| # Schedule Starlink to turn on at a specific time every day | ||
| daily_timer = None | ||
|
|
||
| def schedule_daily_timer(): | ||
| nonlocal daily_timer | ||
| now = datetime.datetime.now(datetime.timezone.utc) | ||
| target = now.replace(hour=scheduled_on.hour, | ||
| minute=scheduled_on.minute, | ||
| second=0, microsecond=0) | ||
| if target <= now: | ||
| target += datetime.timedelta(days=1) | ||
|
|
||
| daily_timer = rospy.Timer( | ||
| rospy.Duration((target - now).total_seconds()), | ||
| daily_timer_cb, | ||
| oneshot=True | ||
| ) | ||
|
|
||
| def daily_timer_cb(event): | ||
| nonlocal already_sent | ||
|
|
||
| # Starlink is already enabled, no need to enable it again. We don't | ||
| # check already_sent because the operator may have manually turned it | ||
| # off yesterday, and we want to turn it on today. | ||
| if last_state: | ||
| return | ||
|
|
||
| if soc >= medium_threshold: | ||
| rospy.loginfo( | ||
| f'Enabling Starlink: SOC {soc:.1f}% >= {medium_threshold}% ' | ||
| 'at scheduled time' | ||
| ) | ||
| outlet_pub.publish(StdBool(True)) | ||
| already_sent = True | ||
| elif soc < medium_threshold: | ||
| send_alerts( | ||
| alerts, | ||
| 'Not enabling Starlink at scheduled time because ' | ||
| f'SOC {soc:.1f}% below medium threshold {medium_threshold}%' | ||
| ) | ||
| schedule_daily_timer() | ||
|
|
||
| if scheduled_on is not None: | ||
| schedule_daily_timer() | ||
|
|
||
| rospy.spin() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.