Skip to content

Commit

Permalink
Fixed game state issues with prestart.
Browse files Browse the repository at this point in the history
  • Loading branch information
RMichaelSwan committed May 15, 2018
1 parent 55bc3e5 commit 86e6678
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions RoboticsGUI/GUI/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class Constants
//Default time motors spend moving in each direction.
public const int defaultMotorFwdTime = 1000; //milliseconds.
public const int defaultMotorBackTime = 1000; //milliseconds.
public const int defaultGameTime = 150; //seconds
public const int gameTime = 150; //total game time in seconds - may change this to be configurable later

//Scoring increments for the scoring areas.
public const uint platInc = 100; //Not sure which platform is the larger one, so use 100 increment for now.
Expand Down Expand Up @@ -39,7 +39,7 @@ public static class Constants
public const short bmotor1 = 4; //Motor1
public const short bmotor2 = 5; //Motor2

public const int preStartBlinkInterval = 250;
public const int preStartBlinkInterval = 50;
public const short keepAliveLed = 13; //Pin 13 is the built in Arduino pin we are using to physically show communication is OK
public const int keepAliveInterval = 500; //how often to blink LED in msec
}
Expand Down
8 changes: 5 additions & 3 deletions RoboticsGUI/GUI/Model/TeamGameModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ private set
private const int hoverTime = 30000; //hover time in total elapsed msecs before absolute end
private const int obstacleTime = 105000; //obstacle time in total elapsed msecs before absolute end
private const int platformTime = 150000; //platform time
private const double gameTimeTotalMS = Constants.gameTime * 1000; //game time in milliseconds
//Time left after above times have elapsed
private double startLeft;
private double hoverLeft;
Expand All @@ -71,8 +72,9 @@ private void OnTimeChange(object sender, PropertyChangedEventArgs e)
double timeLeft = _countdown.TimeRemaining.TotalMilliseconds;
switch (_state)
{
case gameState.PreStart:
case gameState.Idle:
if (timeLeft > 0 && timeLeft < _countdown.Timeout.TotalMilliseconds)
if (timeLeft > 0 && timeLeft < gameTimeTotalMS)
{
_state = gameState.Start;
_teamControl.StartLed.Value = true;
Expand Down Expand Up @@ -173,11 +175,11 @@ public void PreStart()
_state = gameState.PreStart;
_blinkTimer.Start();
}
else if (_state == gameState.PreStart)
else if (_state == gameState.PreStart) //toggle off
{
_blinkTimer.Stop();
_teamControl.StartLed.Value = false;
_state = gameState.Start;
_state = gameState.Idle;
}
}

Expand Down
2 changes: 1 addition & 1 deletion RoboticsGUI/GUI/View/MainWindowView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<Button Grid.Row="3" Grid.Column="7" Content="Start" Margin="7" Command="{Binding StartCommand}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" />
<Button Grid.Row="3" Grid.Column="8" Content="Stop" Margin="7" Command="{Binding StopCommand}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<Button Grid.Row="3" Grid.Column="9" Content="Reset" Margin="7" Command="{Binding ResetCommand}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<Button Grid.Row="4" Grid.Column="7" Content="Pre-Start" Margin="6" Command="{Binding PreStartCommand}" IsEnabled="{Binding Arduino.ComOK}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" />
<Viewbox Grid.Column="6" Grid.Row="4" Grid.ColumnSpan="2"/>
<Rectangle Grid.RowSpan="{Binding RowDefinitions.Count, ElementName=grid, Mode=OneWay}" Grid.Column="10" Fill="AliceBlue" Width="1" Margin="10,0" />

Expand Down Expand Up @@ -339,6 +340,5 @@
<Button Content="Force Stop" Grid.Column="8" Grid.Row="13" Command="{Binding T2MotorStop, Mode=OneWay}" Margin="0,0,0,2"/>
<Button Content="Test Pause" Grid.Column="9" Grid.Row="14" Grid.ColumnSpan="2" Margin="1,0,20,0" Command="{Binding T2MotorPause}"/>
<Label Content="T2 Motor Control" Grid.Column="7" HorizontalAlignment="Left" Margin="51,2,0,10" Grid.Row="12" Width="100" Grid.ColumnSpan="3"/>
<Button Grid.Row="4" Grid.Column="7" Content="Pre-Start" Margin="6" Command="{Binding PreStartCommand, Mode=OneWay}" IsEnabled="{Binding Arduino.ComOK}" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" />
</Grid>
</Window>
5 changes: 3 additions & 2 deletions RoboticsGUI/GUI/ViewModel/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public MainWindowViewModel()

}

public static CountdownModel Countdown { get; } = new CountdownModel(TimeSpan.FromSeconds(Constants.defaultGameTime));
public static CountdownModel Countdown { get; } = new CountdownModel(TimeSpan.FromSeconds(Constants.gameTime));

public static TeamDataModel Team1 { get; } = new TeamDataModel("Red Team", Countdown, Constants.rplat1, Constants.rplat2, Constants.robs1, Constants.robs2, Constants.rhover,
Constants.rstart, Constants.rmotor1, Constants.rmotor2, Properties.Settings.Default.RedMotorFwdTime, Properties.Settings.Default.RedMotorBackTime); //assumption: this is the red team
Expand Down Expand Up @@ -93,7 +93,8 @@ public bool StartLedUnionProperty
Team2.Reset();
//TODO reset scores as well.
}));
RelayCommand PreStartCommand => _cmdPreStart ?? (_cmdPreStart = new RelayCommand(execute => { Team1.TeamGame.PreStart();
public RelayCommand PreStartCommand => _cmdPreStart ?? (_cmdPreStart = new RelayCommand(execute => {
Team1.TeamGame.PreStart();
Team2.TeamGame.PreStart(); }, canExecute => { return Arduino.ComOK; }));

//T1 score and sensor control
Expand Down

0 comments on commit 86e6678

Please sign in to comment.