This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to change relaxed stance from config
- Loading branch information
Showing
7 changed files
with
115 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,36 +1,61 @@ | ||
using System.Threading.Tasks; | ||
using System.Numerics; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Quadruped.WebInterface.RobotController; | ||
using Quadruped.WebInterface.VideoStreaming; | ||
|
||
namespace Quadruped.WebInterface.Pages | ||
{ | ||
public class SettingsPageModel : PageModel | ||
{ | ||
private readonly IVideoService _streamService; | ||
private readonly IRobot _robotController; | ||
|
||
public SettingsPageModel(IVideoService streamService) | ||
public SettingsPageModel(IVideoService streamService, IRobot robotController) | ||
{ | ||
_streamService = streamService; | ||
_robotController = robotController; | ||
} | ||
|
||
public void OnGet() | ||
{ | ||
StreamConfiguration = _streamService.StreamerConfiguration; | ||
var relaxed = _robotController.RelaxedStance; | ||
RelaxedStance = new Vector3Class{X = relaxed.X, Y = relaxed.Y, Z = relaxed.Z}; | ||
} | ||
|
||
[BindProperty] | ||
public StreamerConfig StreamConfiguration { get; set; } | ||
[BindProperty] | ||
public Vector3Class RelaxedStance { get; set; } | ||
|
||
public async Task<IActionResult> OnPostAsync() | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return Page(); | ||
} | ||
_streamService.StreamerConfiguration = StreamConfiguration; | ||
await _streamService.RestartAsync(); | ||
if (_streamService.StreamerConfiguration != StreamConfiguration) | ||
{ | ||
_streamService.StreamerConfiguration = StreamConfiguration; | ||
await _streamService.RestartAsync(); | ||
} | ||
_robotController.UpdateAboluteRelaxedStance((Vector3)RelaxedStance); | ||
return RedirectToPage("/VideoRobot"); | ||
} | ||
} | ||
|
||
public class Vector3Class | ||
{ | ||
public float X { get; set; } | ||
public float Y { get; set; } | ||
public float Z { get; set; } | ||
|
||
public static explicit operator Vector3(Vector3Class original) | ||
{ | ||
return new Vector3(original.X, original.Y, original.Z); | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,10 +1,57 @@ | ||
namespace Quadruped.WebInterface.VideoStreaming | ||
using System; | ||
|
||
namespace Quadruped.WebInterface.VideoStreaming | ||
{ | ||
public class StreamerConfig | ||
public class StreamerConfig : IEquatable<StreamerConfig> | ||
{ | ||
public int ImageQuality { get; set; } = 85; | ||
public int HorizontalResolution { get; set; } = 800; | ||
public int VerticalResolution { get; set; } = 600; | ||
public int Framerate { get; set; } = 10; | ||
|
||
public bool Equals(StreamerConfig other) | ||
{ | ||
if (ReferenceEquals(null, other)) return false; | ||
if (ReferenceEquals(this, other)) return true; | ||
return ImageQuality == other.ImageQuality && HorizontalResolution == other.HorizontalResolution && VerticalResolution == other.VerticalResolution && Framerate == other.Framerate; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) return false; | ||
if (ReferenceEquals(this, obj)) return true; | ||
if (obj.GetType() != this.GetType()) return false; | ||
return Equals((StreamerConfig) obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
unchecked | ||
{ | ||
var hashCode = ImageQuality; | ||
hashCode = (hashCode * 397) ^ HorizontalResolution; | ||
hashCode = (hashCode * 397) ^ VerticalResolution; | ||
hashCode = (hashCode * 397) ^ Framerate; | ||
return hashCode; | ||
} | ||
} | ||
|
||
public static bool operator ==(StreamerConfig a, StreamerConfig b) | ||
{ | ||
if (ReferenceEquals(a, null)) | ||
{ | ||
if (ReferenceEquals(b, null)) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
} | ||
return a.Equals(b); | ||
} | ||
|
||
public static bool operator !=(StreamerConfig a, StreamerConfig b) | ||
{ | ||
return !(a == b); | ||
} | ||
} | ||
} |
This file contains 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