Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Add option to change relaxed stance from config
Browse files Browse the repository at this point in the history
  • Loading branch information
dmweis committed Nov 12, 2017
1 parent 3ca494c commit fb4a0c1
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 8 deletions.
8 changes: 7 additions & 1 deletion Quadruped.WebInterface/Pages/SettingsPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@
<div>Framerate <input asp-for="StreamConfiguration.Framerate" /></div>
<div>HorizontalResolution <input asp-for="StreamConfiguration.HorizontalResolution"/></div>
<div>VerticalResolution <input asp-for="StreamConfiguration.VerticalResolution" /></div>
<div>ImageQuality <input asp-for="StreamConfiguration.ImageQuality"/></div>
<div>ImageQuality <input asp-for="StreamConfiguration.ImageQuality" /></div>

<h3>Relaxed stance adjustment</h3>
<div>X:<input asp-for="RelaxedStance.X" /></div>
<div>Y:<input asp-for="RelaxedStance.Y" /></div>
<div>Z:<input asp-for="RelaxedStance.Z" /></div>

<input type="submit"/>
</form>
</div>
33 changes: 29 additions & 4 deletions Quadruped.WebInterface/Pages/SettingsPage.cshtml.cs
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);
}
}
}
2 changes: 2 additions & 0 deletions Quadruped.WebInterface/RobotController/IRobot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface IRobot
Vector2 Direction { get; set; }
float Rotation { get; set; }
void StartRobot();
Vector3 RelaxedStance { get; }
void UpdateAboluteRelaxedStance(Vector3 transform);
Task DisableMotors();
}
}
7 changes: 7 additions & 0 deletions Quadruped.WebInterface/RobotController/MockRobot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public void StartRobot()

}

public Vector3 RelaxedStance { get; private set; }

public void UpdateAboluteRelaxedStance(Vector3 transform)
{
RelaxedStance = transform;
}

public Task DisableMotors()
{
return Task.CompletedTask;
Expand Down
10 changes: 10 additions & 0 deletions Quadruped.WebInterface/RobotController/Robot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public void StartRobot()
_robotRunnerTask = Task.Run((Action)RobotRunnerLoop);
}

public Vector3 RelaxedStance { get; private set; } = Vector3.Zero;

public void UpdateAboluteRelaxedStance(Vector3 transform)
{
RelaxedStance = transform;
var newRelaxed = _basicQuadrupedGaitEngine.RelaxedStance;
newRelaxed.Transform(transform);
_basicQuadrupedGaitEngine.RelaxedStance = newRelaxed;
}

private void RobotRunnerLoop()
{
while (_keepRunning)
Expand Down
51 changes: 49 additions & 2 deletions Quadruped.WebInterface/VideoStreaming/StreamerConfig.cs
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);
}
}
}
12 changes: 11 additions & 1 deletion Quadruped/BasicQuadrupedGaitEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,30 @@ public class BasicQuadrupedGaitEngine : QuadrupedGaitEngine
private const int LegDistanceLongitudinal = 15;
private const int LegDistanceLateral = 15;

private LegPositions RelaxedStance => new LegPositions
private LegPositions OriginalRelaxedStance => new LegPositions
{
LeftFront = new Vector3(-LegDistanceLateral, LegDistanceLongitudinal, LegHeight),
RightFront = new Vector3(LegDistanceLateral, LegDistanceLongitudinal, LegHeight),
LeftRear = new Vector3(-LegDistanceLateral, -LegDistanceLongitudinal, LegHeight),
RightRear = new Vector3(LegDistanceLateral, -LegDistanceLongitudinal, LegHeight)
};

private LegPositions _relaxedStance;

public LegPositions RelaxedStance
{
get => _relaxedStance.Copy();
set => _relaxedStance = value;
}


private LegPositions _lastWrittenPosition;

public bool IsComamndQueueEmpty => _moveQueueSingal.IsSet && _moves.IsEmpty;

public BasicQuadrupedGaitEngine(QuadrupedIkDriver driver) : base(driver)
{
_relaxedStance = OriginalRelaxedStance;
Driver.Setup();
EnqueueInitialStandup();
if (_moves.TryDequeue(out var deqeueuedLegPosition))
Expand Down

0 comments on commit fb4a0c1

Please sign in to comment.