I've tried several methods for calling the API from a Visual C# project, but I just couldn't make it work properly. Could you provide a small example how should you start if you want to access the API via C#? Some more documentation on this would be useful.
You might want to look at https://github.com/yfakariya/msgpack-rpc-cli
I've gotten the same problem. Have you solved it, @henrik94 ?
Any body could provide a particular API for C# plz?
Thanks in advance~
We have made with @henrik94 a good progress and we are considering to make it public after some more stabilization.
Great, @totht91. I am really looking forward to your contribution.
Excited about using this as well.
@NextSim had been looking in to this as well: https://github.com/Microsoft/AirSim/issues/946
Any updates?
I took a look at the quickstart guide
https://github.com/yfakariya/msgpack-rpc-cli/wiki/Quick-start
but after installing the NuGet package for MsgPack.Cli, it doesn't contain a definition for RpcClientConfiguration.
Maybe I'm missing something
I finally got communication working over the api with c#.
I used the MessagePack serializer below
https://github.com/neuecc/MessagePack-CSharp
For the enable api and set car control I created the classes and helper functions below.
using MessagePack;
namespace Simulator
{
[MessagePackObject]
public class carControlHelper
{
[Key(0)]
public controlApiParams apiParams { get; set; }
}
[MessagePackObject]
public class enableApiHelper
{
[Key(0)]
public bool val { get; set; }
}
[MessagePackObject]
public class controlApiParams
{
[Key("throttle")]
public float throttle { get; set; }
[Key("steering")]
public float steering { get; set; }
[Key("brake")]
public float brake { get; set; }
[Key("handbrake")]
public bool handbrake { get; set; }
[Key("is_manual_gear")]
public bool is_manual_gear { get; set; }
[Key("manual_gear")]
public int manual_gear { get; set; }
[Key("gear_immediate")]
public bool gear_immediate { get; set; }
}
public static class msgPackRpcHelper
{
private static int msgCounter = 0;
public static byte[] enableApiHelper(int type, bool enable)
{
var helperObj = new object[] { type, msgCounter++, "enableApiControl", new enableApiHelper { val = enable } };
return MessagePackSerializer.Serialize(helperObj);
}
public static byte[] setCarControlHelper(int type, float accel, float strAngle, float brake, bool handbrake, bool isManual, int gear, bool gearImmediate)
{
var helperObj = new object[] { type, msgCounter++, "setCarControls", new carControlHelper{apiParams = new controlApiParams {
throttle = accel,
steering = strAngle,
brake = brake,
handbrake = handbrake,
is_manual_gear = isManual,
manual_gear = gear,
gear_immediate = gearImmediate
} } };
return MessagePackSerializer.Serialize(helperObj);
}
}
}
Very nice! We look forward to your pull request :).
Working on it. It's incomplete though, since classes have to be made for each api call and response, but there aren't any details on each api call so it is slow developing it.
@NextSim, I've been trying to do something similar, and I've made some progress calling the RPCs from C#. So far, though, I've been focused on the multirotor side of things. If you've got the time, you may want to take a look, specifically at the AirSimRpc and MsgPackRpc projects: https://github.com/brandtd/AirSimApp
Most helpful comment
@NextSim, I've been trying to do something similar, and I've made some progress calling the RPCs from C#. So far, though, I've been focused on the multirotor side of things. If you've got the time, you may want to take a look, specifically at the AirSimRpc and MsgPackRpc projects: https://github.com/brandtd/AirSimApp