Skip to content

Commit

Permalink
Enable latest analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
visose committed Aug 22, 2023
1 parent d0b96cf commit 3ed7b96
Show file tree
Hide file tree
Showing 41 changed files with 349 additions and 458 deletions.
549 changes: 227 additions & 322 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Product>Robots</Product>
<Version>1.6.5</Version>
<Version>1.6.6</Version>
<Authors>Robots Authors</Authors>
<Description>Create and simulate ABB, KUKA, UR, and Staubli robot programs.</Description>
<PackageTags>Robots;ABB;KUKA;UR;Staubli;Robotics</PackageTags>
Expand All @@ -21,7 +21,7 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<!--<AnalysisLevel>latest</AnalysisLevel>-->
<AnalysisLevel>latest</AnalysisLevel>
<NoWarn>MSB3270</NoWarn>
<RootDir>$(MSBuildThisFileDirectory)</RootDir>
<ArtifactsDir>$(RootDir)artifacts\</ArtifactsDir>
Expand Down
5 changes: 5 additions & 0 deletions RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
- version: 1.6.6
changes:
- Fixed UR pulseDO command
- Fixed KUKA custom external

- version: 1.6.5
changes:
- Added Orocos KDL solver for Franka Emika (Windows only)
Expand Down
2 changes: 1 addition & 1 deletion src/Robots.Grasshopper/Goos/GH_Joints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override bool CastFrom(object source)
{
if (string.IsNullOrWhiteSpace(text.Value))
{
Value = new double[0];
Value = Array.Empty<double>();
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Robots.Grasshopper/Obsolete/CreateProgram.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Grasshopper.Kernel.Types;
using Grasshopper.Kernel.Types;
using Grasshopper.Kernel.Data;

namespace Robots.Grasshopper;

[Obsolete]
[Obsolete("Replace with the new CreateProgram component")]
public class CreateProgram : GH_Component
{
public CreateProgram() : base("Create program", "Program", "Creates a program, checks for possible issues and fixes common mistakes.", "Robots", "Components") { }
Expand Down
6 changes: 3 additions & 3 deletions src/Robots.Grasshopper/Obsolete/Custom.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
namespace Robots.Grasshopper.Commands;
namespace Robots.Grasshopper.Commands;

[Obsolete]
[Obsolete("Replace with new Custom Command component")]
public class Custom : GH_Component
{
public Custom() : base(" command", "CustomCmd", "Custom command written in the manufacturer specific language", "Robots", "Commands") { }
public Custom() : base("Custom command", "CustomCmd", "Custom command written in the manufacturer specific language", "Robots", "Commands") { }
public override GH_Exposure Exposure => GH_Exposure.hidden;
public override bool Obsolete => true;
public override Guid ComponentGuid => new("{D15B1F9D-B3B9-4105-A365-234C1329B092}");
Expand Down
4 changes: 2 additions & 2 deletions src/Robots.Grasshopper/Program/Simulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public sealed class Simulation : GH_Component
{
SimulationForm? _form;
DateTime? _lastTime;
double _time = 0;
double _lastInputTime = 0;
double _time;
double _lastInputTime;

internal double Speed = 1;

Expand Down
12 changes: 6 additions & 6 deletions src/Robots.Grasshopper/RobotSystem/LibraryForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq.Expressions;
using System.Linq.Expressions;
using System.Diagnostics;
using Eto.Drawing;
using Eto.Forms;
Expand Down Expand Up @@ -137,15 +137,15 @@ async Task DownloadAsync()
_grid.DataStore = _grid.DataStore;
}

string ItemActions(LibraryItem item) => item switch
static string ItemActions(LibraryItem item) => item switch
{
{ IsDownloaded: true, IsUpdateAvailable: true } => "Update",
{ IsUpdateAvailable: true } => "Install",
{ IsDownloaded: true } => "Remove",
_ => ""
};

GridView Grid() => new()
static GridView Grid() => new()
{
Size = new Size(300, 300),
Border = BorderType.None,
Expand Down Expand Up @@ -205,7 +205,7 @@ async Task DownloadAsync()
}
};

string Description(LibraryItem item) => item switch
static string Description(LibraryItem item) => item switch
{
{ IsLocal: true, IsDownloaded: true } => "❕📁 Installed, local override",
{ IsLocal: true, IsOnline: true } => "📁 Local, available on-line",
Expand All @@ -226,7 +226,7 @@ StackLayout NewDetailButton()
return detailButton;
}

StackLayout NewAsyncButton(Func<Task> actionAsync, string? label = null, bool runOnce = false)
static StackLayout NewAsyncButton(Func<Task> actionAsync, string? label = null, bool runOnce = false)
{
Button button = new()
{
Expand Down Expand Up @@ -268,4 +268,4 @@ async Task ClickAsync()
spinner.Enabled = false;
}
}
}
}
6 changes: 3 additions & 3 deletions src/Robots.Grasshopper/RobotsInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public RobotsInfo()
public override string AuthorContact => GetCompany()[1];
public override Guid Id => new("0c4dd17f-db66-4895-9565-412eb167503f");

T GetInfo<T>() where T : Attribute
static T GetInfo<T>() where T : Attribute
{
var assembly = Assembly.GetExecutingAssembly();
return assembly.GetCustomAttribute<T>();
}

string[] GetCompany()
static string[] GetCompany()
{
var company = GetInfo<AssemblyCompanyAttribute>().Company;
return company.Split(new[] { " - " }, StringSplitOptions.None);
Expand Down Expand Up @@ -90,7 +90,7 @@ void UpdateToLibraryParams(GH_DocumentServer sender, GH_Document doc)
Rhino.RhinoApp.WriteLine($"Updated {count} robot library value list(s).");
}

string GetRobotsPath()
static string GetRobotsPath()
{
var robotsLib = Instances.ComponentServer.Libraries.FirstOrDefault(l => l.Name == "Robots");

Expand Down
8 changes: 5 additions & 3 deletions src/Robots.Grasshopper/Target/CreateTarget.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Drawing;
using System.Drawing;
using Rhino.Geometry;
using Grasshopper;
using Grasshopper.Kernel.Parameters;
Expand Down Expand Up @@ -140,7 +140,9 @@ protected override void SolveInstance(IGH_DataAccess DA)
{
string motionText = "Joint";
DA.GetData("Motion", ref motionText);
Enum.TryParse(motionText, out motion);

if (!Enum.TryParse(motionText, out motion))
throw new ArgumentException($"Motion {motionText} not valid.");
}
else if (sourceTarget is not null)
{
Expand Down Expand Up @@ -216,7 +218,7 @@ protected override void SolveInstance(IGH_DataAccess DA)
else
{
if (joints is null)
throw new ArgumentNullException(nameof(joints));
throw new ArgumentException("Joints should not be null");

target = new JointTarget(joints, tool, speed, zone, command, frame, external);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Robots/Commands/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ protected Command(string? name = null) : base(name) { }

protected virtual void ErrorChecking(RobotSystem robotSystem) { }
protected virtual void Populate() { }
public bool RunBefore { get; set; } = false;
public bool RunBefore { get; set; }
internal virtual IEnumerable<Command> Flatten()
{
if (this != Default)
Expand Down
4 changes: 2 additions & 2 deletions src/Robots/Commands/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public Group(IEnumerable<Command> commands) : base("GroupCommand")
// IList implementation
public Command this[int index]
{
get { return _commandList[index]; }
set { _commandList[index] = value; }
get => _commandList[index];
set => _commandList[index] = value;
}

public int IndexOf(Command item) => _commandList.IndexOf(item);
Expand Down
15 changes: 5 additions & 10 deletions src/Robots/Geometry/CircumcentreSolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ namespace Robots.Geometry;
class CircumcentreSolver
{
double _x, _y, _z;
double _radius;
readonly double[,] _p = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };

internal Point3d Center => new(_x, _y, _z);
internal double Radius => _radius;

/// <summary>
/// Computes the center of a sphere such that all four specified points in
Expand All @@ -25,10 +23,10 @@ class CircumcentreSolver
/// <param name="d">The fourth point (array of 3 doubles for X, Y, Z).</param>
internal CircumcentreSolver(Point3d pa, Point3d pb, Point3d pc, Point3d pd)
{
double[] a = new double[] { pa.X, pa.Y, pa.Z };
double[] b = new double[] { pb.X, pb.Y, pb.Z };
double[] c = new double[] { pc.X, pc.Y, pc.Z };
double[] d = new double[] { pd.X, pd.Y, pd.Z };
double[] a = { pa.X, pa.Y, pa.Z };
double[] b = { pb.X, pb.Y, pb.Z };
double[] c = { pc.X, pc.Y, pc.Z };
double[] d = { pd.X, pd.Y, pd.Z };
Compute(a, b, c, d);
}

Expand Down Expand Up @@ -56,7 +54,7 @@ void Compute(double[] a, double[] b, double[] c, double[] d)

void Sphere()
{
double m11, m12, m13, m14, m15;
double m11, m12, m13, m14;
double[,] a = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } };

// Find minor 1, 1.
Expand Down Expand Up @@ -107,22 +105,19 @@ void Sphere()
a[i, 2] = _p[i, 1];
a[i, 3] = _p[i, 2];
}
m15 = Determinant(a, 4);

// Calculate result.
if (m11 == 0)
{
_x = 0;
_y = 0;
_z = 0;
_radius = 0;
}
else
{
_x = 0.5 * m12 / m11;
_y = -0.5 * m13 / m11;
_z = 0.5 * m14 / m11;
_radius = Sqrt(_x * _x + _y * _y + _z * _z - m15 / m11);
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/Robots/IO/FileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ static RobotSystem CreateRobotSystem(XElement element, Plane basePlane, bool loa
&& (!Enum.TryParse<ElementType>(typeName, out var type)
|| type != ElementType.RobotSystem))
{
throw new ArgumentException($" Element '{typeName}' should be 'RobotSystem'", nameof(typeName));
throw new ArgumentException($" Element '{typeName}' should be 'RobotSystem'");
}

var name = element.GetAttribute("name");
var manufacturerAttribute = element.GetAttribute("manufacturer");

if (!Enum.TryParse<Manufacturers>(manufacturerAttribute, out var manufacturer))
throw new ArgumentException($" Manufacturer '{manufacturerAttribute}' not valid.", nameof(manufacturerAttribute));
throw new ArgumentException($" Manufacturer '{manufacturerAttribute}' not valid.");

var mechanicalGroups = new List<MechanicalGroup>();

Expand All @@ -168,7 +168,7 @@ static RobotSystem CreateRobotSystem(XElement element, Plane basePlane, bool loa
Manufacturers.FrankaEmika => new SystemFranka(name, (RobotFranka)mechanicalGroups[0].Robot, io, basePlane, environment),
Manufacturers.Doosan => new SystemDoosan(name, (RobotDoosan)mechanicalGroups[0].Robot, io, basePlane, environment),

_ => throw new ArgumentException($" Manufacturer '{manufacturer} is not supported.", nameof(manufacturer))
_ => throw new ArgumentException($" Manufacturer '{manufacturer} is not supported.")
};
}

Expand Down Expand Up @@ -227,7 +227,7 @@ static Mechanism CreateMechanism(XElement element, bool loadMeshes)
{
"Revolute" => new RevoluteJoint { Index = i, Number = number, A = a, D = d, Alpha = α, Theta = θ, Sign = sign, Range = range, MaxSpeed = maxSpeed, Mesh = mesh },
"Prismatic" => new PrismaticJoint { Index = i, Number = number, A = a, D = d, Alpha = α, Theta = θ, Sign = sign, Range = range, MaxSpeed = maxSpeed, Mesh = mesh },
_ => throw new ArgumentException(" Invalid joint type.", nameof(jointElement.Name.LocalName))
_ => throw new ArgumentException(" Invalid joint type.")
};
}

Expand All @@ -241,12 +241,12 @@ static Mechanism CreateMechanism(XElement element, bool loadMeshes)
Manufacturers.Staubli => new RobotStaubli(model, payload, basePlane, baseMesh, joints),
Manufacturers.FrankaEmika => new RobotFranka(model, payload, basePlane, baseMesh, joints),
Manufacturers.Doosan => new RobotDoosan(model, payload, basePlane, baseMesh, joints),
_ => throw new ArgumentException($" Manufacturer '{manufacturer}' not supported.", nameof(manufacturer)),
_ => throw new ArgumentException($" Manufacturer '{manufacturer}' not supported."),
},
"Positioner" => new Positioner(model, manufacturer, payload, basePlane, baseMesh, joints, movesRobot),
"Track" => new Track(model, manufacturer, payload, basePlane, baseMesh, joints, movesRobot),
"Custom" => new Custom(model, manufacturer, payload, basePlane, baseMesh, joints, movesRobot),
_ => throw new ArgumentException($" Unknown mechanism type '{element.Name}'.", nameof(element.Name))
_ => throw new ArgumentException($" Unknown mechanism type '{element.Name}'.")
};
}

Expand Down Expand Up @@ -277,7 +277,7 @@ static Tool CreateTool(XElement element)
var type = element.Name.LocalName;

if (type != "Tool")
throw new ArgumentException($" Element '{type}' should be 'Tool'", nameof(type));
throw new ArgumentException($" Element '{type}' should be 'Tool'");

var name = element.GetAttribute("name");

Expand All @@ -301,7 +301,7 @@ static Frame CreateFrame(XElement element)
var type = element.Name.LocalName;

if (type != "Frame")
throw new ArgumentException($" Element '{type}' should be 'Frame'", nameof(type));
throw new ArgumentException($" Element '{type}' should be 'Frame'");

var name = element.GetAttribute("name");
var useController = element.GetBoolAttributeOrDefault("useController");
Expand Down
8 changes: 4 additions & 4 deletions src/Robots/IO/OnlineLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async Task AddOnlineLibrariesAsync()
}
}

string? GetValidExtension(string fileName)
static string? GetValidExtension(string fileName)
{
foreach (var extension in new[] { ".xml", ".3dm" })
{
Expand Down Expand Up @@ -145,20 +145,20 @@ void AddDiskLibraries(string folder, bool isLocal)
}
}

string GetLocalSha(string xmlPath)
static string GetLocalSha(string xmlPath)
{
var shaXml = GetSha1(xmlPath);
var sha3dm = GetSha1(Path.ChangeExtension(xmlPath, ".3dm"));
return shaXml + sha3dm;
}

string GetSha1(string file)
static string GetSha1(string file)
{
var bytes = File.ReadAllBytes(file);
return GetSha1(bytes);
}

string GetSha1(byte[] contentBytes)
static string GetSha1(byte[] contentBytes)
{
var header = $"blob {contentBytes.Length}\0";
var encoding = new System.Text.UTF8Encoding();
Expand Down
8 changes: 4 additions & 4 deletions src/Robots/Kinematics/FrankaKdlKinematics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ protected override Transform[] ForwardKinematics(double[] joints)
return _ts;
}

Vector3d ToVector3d(K.Vector v) => new(v.x(), v.y(), v.z());
static Vector3d ToVector3d(K.Vector v) => new(v.x(), v.y(), v.z());

K.Frame ToFrame(Transform t)
static K.Frame ToFrame(Transform t)
{
using K.Rotation rotation = new(
t.M00, t.M01, t.M02,
Expand All @@ -135,7 +135,7 @@ K.Frame ToFrame(Transform t)
return new(rotation, vector);
}

double[] FromJntArray(K.JntArray ja)
static double[] FromJntArray(K.JntArray ja)
{
int count = (int)ja.rows();
var vals = new double[count];
Expand All @@ -146,7 +146,7 @@ double[] FromJntArray(K.JntArray ja)
return vals;
}

K.JntArray ToJntArray(double[] joints)
static K.JntArray ToJntArray(double[] joints)
{
var ja = new K.JntArray((uint)joints.Length);

Expand Down
2 changes: 1 addition & 1 deletion src/Robots/Kinematics/RobotCellKinematics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal IndustrialSystemKinematics(IndustrialSystem system, IEnumerable<Target>
if (coupledGroup != -1 && target.Frame.CoupledMechanism == -1)
{
if (coupledGroup == i)
throw new ArgumentException(" Cannot couple a robot with itself.", nameof(coupledGroup));
throw new ArgumentException(" Cannot couple a robot with itself.");

coupledPlane = Solutions[coupledGroup].Planes[Solutions[coupledGroup].Planes.Length - 2] as Plane?;
}
Expand Down
Loading

0 comments on commit 3ed7b96

Please sign in to comment.