Giter VIP home page Giter VIP logo

legoev3's People

Contributors

brianpeek avatar crutkas avatar hatsunea avatar lizlooney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

legoev3's Issues

Updated NuGet

Hey,
first of all, thanks for a great and fun library.

I was wondering if it'd be possible to get an updated NuGet package? I'd like to be able to use OutputReady() method, which isn't in the currently published package.

thanks again

Generic.KeyNotFoundException in ResponseManager.HandleResponse

This issue was imported from CodePlex

achalshah wrote 2014-09-01 at 21:41
I've been getting exceptions of type System.Collections.Generic.KeyNotFoundException from ResponseManager.HandleResponse. From my reading of the code, this means that a response with a specific sequence number was not found in the Responses collection.
Have you seen anything like this - any idea how this could happen?

Also, while I was trying to understand this code, one example of the path looks like this :

  1. Brick.PollSensorsAsync creates a new Command of DirectReply type. This also creates a Response object for the command which is stored in the Responses collection. The command is sent off using SendCommandAsyncInternal on which PollSensorsAsync blocks.
  2. Brick.SendCommandAsyncInternal sends the command and calls ResponseManager.WaitForResponseAsync to block for the response.
  3. If the response comes in (through the ICommunication object), ResponseManager.HandleResponse handles it and signals the response's Event so that ResponseManager.WaitForResponseAsync competes, and the response is removed from the Responses collection.
  4. If no response is received within a second, the reply type is set to error, but the response is not removed - in fact it does not look like it is ever removed.

The questions:

Is the behavior in 4 above normal in the error case, i.e. the response is not removed?

Is it possible for there to be a race condition between WaitForResponseAsync timing out on WaitOne and the response being handled?

I still can't explain the exception that I'm seeing, but is it possible that there is a race between the polling task and some other command (like one to apply power to the motors), such that both threads try to call ResponseManager.CreateResonse at the same
time? Is incrementing the sequence number atomic or exclusive?

Thanks,

-Achal

peekb wrote 2014-09-10 at 13:15
Is this happening on a specific platform? (Phone, Desktop, WinRT?)

achalshah wrote 2014-09-11 at 00:39
This is on Phone. Let me know if you want the stacks.

achalshah wrote 2014-09-13 at 00:46
Here is a possible scenario resulting in non-sequential write access to the Responses collection (in ResponseManager):

PollSensorAsync() in Brick.cs sends commands and waits on the response being handled (eventually by calling WaitForResponseAsync on the ResponseManager. WaitForResponseAsync waits on the response event.

PollInput in BTCommunication runs in a separate thread and calls HandleResponse in ResponseManager when new data comes in.

HandleResponse gets the sequence, takes it from the Responses collection, populates it and sets its event which WaitResponseAsync is waiting for. Once the event is signalled, WaitResponseAsync removes the response from the Responses collection.

Even though these 2 threads are pretty much synchronized by virtue of the fact that each command has a response which is waited on, a 3rd thread could send a command (e.g. from the UI), and now we could have two tasks waiting for responses.

The two responses would come back to back and HandleResponse could set both events before the two tasks waiting on the events are able to run. Eventually both run and try to remove items from the collection simultaneously and could corrupt it since access is
not protected.

Add blocking methods

This is a great library but cumbersome to use in console apps. Please consider adding blocking methods for the desktop version.

Two Ev3 Devices with Desktop

I have two Ev3 bricks with 4 motors each that I would like to control by sending them joystick values from a xinput joystick (im using sharpdx). I have tried using the code to run a program on one ev3, and, with daisy chain, control both ev3's. However the code (from pull request #18 ) crashes my ev3 after the program ends and does not allow me to send my data from a joystick to my ev3 easily. I have tried using the read/write file block in the ev3 labview. I have seen pull request #14 but I don't understand how it can help me. I am not using windows forms and am just running a console application to control the bricks. Any suggestions/help converting #14 to desktop will be much appreciated!

Communication Classes Need Changed

I have been working on downloading and building the projects on my machine so that I can use them for my UWP apps (although I can't claim to have been very successful yet), but one thing that I found that needs updated (I don't know if it should be updated in the existing one or only in the new modified one for UWP) is the implementation of ICommunication in BluetoothCommunication.cs, NetworkCommunication.cs, and UsbCommunication.cs. All three of these, even though they have the methods that are supposedly not implemented (ConnectAsync & WriteAsync), implement the methods as IAsyncAction instead of Task. I would guess this would be a reasonably thing to fix, but since async and communication are probably two of my weakest areas (not to mention I am usually VB.NET rather than C#), I'm not sure if I should be the one to make these changes, but I am mentioning them to do the best I can to help get a UWP compatible version out as soon as possible.

Steering block API

This issue was imported from CodePlex

peekb wrote 2014-02-19 at 13:05
@peekb,

Thanks for testing.

I see that others are making turns with no problem.

But, I'm still stuck with this odd behavior.

I will try again in a few days.

Work stuff comes first.

I wish you can add some functions to the API to mimic the Move Steering Block ( which has angle / degrees of turn )

which was so easy to use in Lego IDE.

Thanks, LA Guy

njsokalski wrote 2014-02-20 at 14:28
I am not trying to prevent features from being added; and some features could obviously be more useful or have more included in them than I thought. However, I always viewed the purpose of using .NET (or some other full fledged language) rather than the
Lego programming interface for EV3 as being having the option and capability to do more complex calculations and be more efficient. One of these things would be steering, since there are multiple types of steering, and how they are used will vary for every
robot. Steering, in my opinion, is one of the things that is so simple it is easier to simply write your own function or sub for each robot. But don't get me wrong, because I will admit that when I first learned .NET that's what I thought about some classes
that I didn't know about or didn't know how to use, but now I am glad that I know them. To put it simply, steering has never been one of the hard parts for me (even though navigation has been a significant function of my robots), but everybody finds different
parts harder than others, and I would be happy to share my basic steering algorithms with anybody who would like to see them.

StartProgram from brick, Windows Forms Application

Hello all,

I have an assignment for university to start a program from the brick from a Windows Forms Application via bluetooth, but I can find no such function to start.

I saw that there have been talks about it but I do not have the StartProgram method in my dll.
I added the dll as a reference to my Windows Forms Application.

Thank you!

Missing SystemCommands

Does not implement LIST_FILES or any receiving from brick commands. This makes it difficult to, for example, make an explorer tool, or get the current name of the brick (which can be found in ~/sys/settings/BrickName).
Documentation for these commands is in the EV3 sources.

[ASP.NET Core2 Bluetooth connection problem]

I can't connect to my EV3 via Bluetooth in a ASP.NET Core2 Web application, but with USB i can!

It says:
"An unhandled exception occurred while processing the request.
FileNotFoundException: Could not load file or assembly 'System.IO.Ports, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. System cannot find the file specified.
Lego.Ev3.Desktop.BluetoothCommunication..ctor(string port)"

Let me notice, it worked with Bluetooth in ASP.NET Framework and in WPF application, but in a Core2 app, it didn't...

Please fix this somehow or please help me how I can connect in Core2!

Event polling no more working with firmware 1.09H

this API do not works well with the 1.09H EV3 firmware.
Event are no more received. Sensor values are always same value as at startup. Even samples doesn't work well to refresh the sensor values, only initial values are shown.
When rollbacking my EV3 to 1.08H firmware version, all things goes back well :) and sensor values are updates and brick changed event is again called ...

Auto-find brick via wifi

This issue was imported from CodePlex

peekb wrote 2013-11-24 at 23:46
Hello, great job with this new EV3 API. I just made a small start project using the API but I have a small question. I used:

_brick = new Brick(new NetworkCommunication("192.168.178.19")); to make a wifi connection. It works but is there a way to get the used IP adres automaticly?

I looked at the sample but I can not understand how it works...... (not enough C# skills yet!)

greeting from Holland André

nuwans wrote 2013-12-01 at 13:27
Hello, this API has not implemented a way to get the ip address automatically yet. But I found a way to do that using some documentation found in monobrick web site. Basically, EV3 broadcast an identification UDP message on port 3015. This happens every
few seconds after it connects to the router. It has the string called "EV3" in it. So listen to this message on this port using UDP and then if the message contains the string "EV3" get the ip address from the receiving message. This is
what I do now until that functionality is integrated to the API. I guess there is a similar functionality to discover the Bluetooth port instead we having to provide it to the application.

The code I have is pretty simple

private const int listenPort = 3015;

    private static void StartListener()
    {
        bool done = false;

        UdpClient listener = new UdpClient(listenPort);
        IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
        try
        {
            while (!done)
            {
                Console.WriteLine("Waiting for broadcast");
                byte[] bytes = listener.Receive(ref groupEP);
                Console.WriteLine("Received broadcast from {0} :\n {1}\n", groupEP.ToString(), Encoding.ASCII.GetString(bytes, 0, bytes.Length));

                if (Encoding.ASCII.GetString(bytes, 0, bytes.Length).Contains("EV3"))
                {
                    Console.WriteLine("EV3 IP="+groupEP.Address.ToString());

                }

            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            listener.Close();
        }

Lego EV3 API for Windows 10

I have started working on a few EV3 apps for Windows 10 Universal Apps. However, several things I have noticed are that Batch Commands give an error when they are sent, along with several other problems in some methods. I have not completely finished testing everything and comparing everything to how they worked in Windows 8.1, but the fact that I was able to use DirectCommand but not BatchCommand was the most noticeable. Are there any Windows 10 issues that anybody knows of or has found?

Make the brick sleep for X milliseconds?

(Win7, WPF application in VS2015).
I have a button that, when clicked, makes a motor turn for a bit. However, I want it to pause, then turn the motor backwards. Right now I have this:

private async void Load_Card_Click(object sender, RoutedEventArgs e)
        {
            await _brick.DirectCommand.TurnMotorAtPowerForTimeAsync(OutputPort.D, 100, 450, false);
            System.Threading.Thread.Sleep(500);
            await _brick.DirectCommand.TurnMotorAtPowerForTimeAsync(OutputPort.D, -50, 450, true);
        }

It 'works', but this is inconsistent; sometimes the first or second DirectCommand isn't sent and the motor doesn't end up doing what I want. I checked the method list of DirectCommand and BatchCommand, and I didn't see a sleep or wait method. Is there a better method than what I've already tried?

continous drive

Hello,
First of all, great job creating this API. I am new to programming so please be patient if i ask wrong question.

  1. I had sed this api for 2 monh already and stopped yesterday. The problem is a don't know how to write a command to drive continuously. I mean that i know how to write a command to drive forward or backward for time and with power. But is there a way that iam mising to write a method that command to drive some time forward then turn left and then go forward for some time. I fought that if i create a button and add a code for example"

private void Button1Clicked(object sender, RoutedEventArgs routedEventArgs)
{
await brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A | OutputPort.B, 50, 5000);
await brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A, 50, 5000);
await brick.DirectCommand.TurnMotorAtPowerAsync(OutputPort.A | OutputPort.B, 50, 5000);
}
The brick only see a one command and dont do all of them.

  1. i wrote sth like this:

private void Button2Clicked(object sender, RoutedEventArgs routedEventArgs)
{
if(TextBox1.Text == "1")
GoForward(); // method for going forward for some time
else if(TextBox1.Text == "2")
GoBackward();
}

it worked when i used textbox and write something on it.
But how to use a data from sensor so it can behave deiferently. I tried to figure out how to do it from other language but i dont have knowlege to do so.

I will be very greatefull if anyone can help me with this.

ArgumentOutOfRangeException after connecting via bluetooth

Environment:
Win 8.1 Pro x64
Console application

I get an ArgumentOutOfRangeException within Lego.Ev3.Tester.Console after connecting the ev3 via bluetooth. The console application works fine with usb. Any ideas?

System.ArgumentOutOfRangeException wurde nicht behandelt.
HResult=-2146233086
Message=Nicht negative Zahl erforderlich.
Parametername: count
ParamName=count
Source=mscorlib
StackTrace:
bei System.IO.BinaryReader.ReadBytes(Int32 count)
bei Lego.Ev3.Desktop.BluetoothCommunication.SerialPortDataReceived(Object sender, SerialDataReceivedEventArgs e) in C:\Entw\Work\Mindstorm\Ev3\Lego.Ev3.Desktop\BluetoothCommunication.cs:Zeile 51.
bei System.IO.Ports.SerialPort.CatchReceivedEvents(Object src, SerialDataReceivedEventArgs e)
bei System.IO.Ports.SerialStream.EventLoopRunner.CallReceiveEvents(Object state)
bei System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
bei System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
bei System.Threading.ThreadPoolWorkQueue.Dispatch()
bei System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
InnerException:

EV3 moves a little then later commands get lost

I have firmware 1.07H - I'm running the Desktop code on OS X.

I have the blue tooth pairing working and on the EV3 the iPhone/iPod/iPad is off.

When I send a command it goes through the first time, EV3 moves + plays sound. If I try again I get random behavior. Sometime it will move again, sometimes it moves a different motor (same code). Most times after it has moved around a bit, it ignores all future commands and requires a reboot.

I modified the tester to Disconnect after each run, batch seemed to work a little better.

Any thoughts? thanks

Wait for motor to finish

I want to send a command (to turn a motor) and then wait for the motor to finish before doing anything else. Is there any way to:

  1. Raise an event when a motor stops. I know that the BrickChanged event is raised when a motor turns, but what I need is kind of the reverse of that, I need to know when a motor stops turning (sort of like a BrickNotChanged event)
    OR
  2. Detect whether a motor is turning (either a property of method)
    Without a way to be notified when a motor finishes, I'm not sure how to determine when I should start turning the next motor. Is there any way to do either of these things, or do you have any suggestions as to determine when to start the next motor (I don't have enough sensors to use that to determine when the motor finishes)? Thanks.

Run Program on Brick from SDK

This issue was imported from CodePlex

peekb wrote 2013-11-22 at 09:46
Is it possible to run a program on the brick from a Command?

LA_Guy wrote 2014-01-03 at 13:36
Lego provides a graphical drag and drop programming language which is downloaded to the Brick and run.

Is this possible using .Net EV3 API ?

Thanks

Best way for turn a specific number of degrees?

Hi,
my name is Mike and I'm trying to get into the functionality of the API.
I have a little robot that drives as 'tank'. Would you please tell me, what is the best way to turn the robot 90 degrees?

public async Task<bool> TurnRight90Degrees() { _brick.BatchCommand.StepMotorAtSpeed(_drivePortRight, _state.SpeedInverted, 200 /* try values here */, BRAKE); _brick.BatchCommand.StepMotorAtSpeed(_drivePortLeft, _state.Speed, 200, BRAKE); await _brick.BatchCommand.SendCommandAsync(); return true; }

also i can't find any hints what this method is for:
StepMotorSync

would you be so nice to explain it to me?

thanks!
cheers mike

Fix for issues with newer firmware

While trying to get this project to work, I came across the issue where the ResponseManager.HandleResponse is throwing some Key out of range errors.

The issue seems to be that the expected input is not compatible with this code. My device came with FW 1.07 and I upgraded to 1.09 so I have no idea if something has changed with older FWs but the problem is that the HandleResponse expects the first two bytes to be the sequence number. The Lego Communications documentation says the first two bytes are the size, so what happens is that the code tries to access a Response at the index that is the size of the message. Does not work that well.

The fix is actually quite simple. Up all the indexes with 2 so it skips the size.

internal static void HandleResponse(byte[] report)
        {
            if (report == null || report.Length < 3)
                return;

            ushort sequence = (ushort) (report[2] | (report[3] << 8));
            int replyType = report[4];

            if (sequence > 0)
            {
                try
                {
                    Response r = Responses[sequence];

                    if (Enum.IsDefined(typeof(ReplyType), replyType))
                        r.ReplyType = (ReplyType) replyType;

                    if (r.ReplyType == ReplyType.DirectReply || r.ReplyType == ReplyType.DirectReplyError)
                    {
                        r.Data = new byte[report.Length - 5];
                        Array.Copy(report, 5, r.Data, 0, report.Length - 5);
                    }
                    else if (r.ReplyType == ReplyType.SystemReply || r.ReplyType == ReplyType.SystemReplyError)
                    {
                        if (Enum.IsDefined(typeof(SystemOpcode), (int) report[4]))
                            r.SystemCommand = (SystemOpcode) report[4];

                        if (Enum.IsDefined(typeof(SystemReplyStatus), (int) report[6]))
                            r.SystemReplyStatus = (SystemReplyStatus) report[6];

                        r.Data = new byte[report.Length - 7];
                        Array.Copy(report, 7, r.Data, 0, report.Length - 7);
                    }

                    r.Event.Set();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                    throw;
                }
            }
        }

ClearChanges not working

This issue was imported from CodePlex

peekb wrote 2013-11-22 at 10:36
I worte following code but can't clear motor "RawValue"

private async void btnClearD_Click(object sender, RoutedEventArgs e)
{
    await this.Brick.DirectCommand.ClearChanges(InputPort.D);

    this.MotorD.Update(this.Brick);
}

Where I do wrong?

Access is denied when connecting using BlueTooth (WP)

This issue was imported from CodePlex

wmmihaa wrote 2014-08-06 at 05:42
We've developed a phone application using the .Net SDK. Everything works great when running the same code from a Desktop app, but when running it from a phone I get Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

peekb wrote 2014-08-06 at 11:46
Please verify you have modified the application manifest file as described in the Documentation section linked above.

Command.Initialize & CommandType.DirectReply

I have been looking for a good way to determine when the last of my BatchCommand(s) have been executed (knowing when the motors have stopped). I thought about finding a way to append a command to the BatchCommand that sends some sort of indicator when it is reached. I looked at the BatchCommand methods, and some of them (such as GetDeviceName, GetFirmwareVersion, etc.) looked like they returned a value (even though they were a Sub or returned void, rather than being a Function or returning some kind of value). I figured if I added one of these to my BatchCommand I could wait for it to send/return the value, but I don't know how to do that. How do I get the value returned from these commands?
NOTE: The reason (in this specific case, all there may be other scenarios) I want to know when the BatchCommand(s) finish is because I want to send more commands than the Brick can remember (I could end up sending anything from 5 or 6 to 10,000 or so), so I need to send them only a few at a time (a few meaning whatever the max is).

Non-Integer Turn Ratio in StepMotorSync

When using the StepMotorSync method, the turnRation parameter is of type Short (System.Int16), which is an integral value. How are we supposed to make the motors turn at ratios like 0.5, 1.25, etc.? The fact that it is of type Short obviously requires me to convert the value to a Short, which will cause rounding, almost defeating the purpose of having a ratio at all. Am I misunderstanding how this method is intended to be used? Thanks.

USB mode requires some fixes

Guys, I figured out how to make SDK work properly with brick via USB.

  1. All commands should wait reply (even DirectNoReplay and SystemNoReply types)
  2. Sensor reading subroutine should be turned off. Or it should be synchronized to prevent reading while a command is running or waiting for reply.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.