Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture packets to figure out how to move a interactive motor to a precise angle #18

Open
helje5 opened this issue Aug 30, 2017 · 6 comments

Comments

@helje5
Copy link
Contributor

helje5 commented Aug 30, 2017

I’m a little stuck w/ the interactive motor. The angle based motor movement works kinda ok, but if I move forward and backward by say 40 degrees, the movement isn’t exact (also it is a move-by, not a move-to-angle). i.e. Vernie’s head doesn’t end up in the same position.

My assumption was that the interactive motto should be able to do this? And maybe even report the current position (but subscribing to the port values on 0x2 gives seemingly random values?)

However, it seems like the iPad app can do this. Shaking the head, it always seems to return the head to the 0-degree position.
It would be great to get some packets which reveal how to do this. I would think there is either a different command than the angle-one we currently have (a turn(to: angle) instead of turn(by: angle)), or there are notifications which report the current angle (so that the application can adjust it until it hits 0-degree).

Thanks! :-)

@JorgePe
Copy link
Owner

JorgePe commented Aug 30, 2017

OK, I'll try.

The problem with capturing is that I have to establish several sessions until one gets captured and even then just for a while so have to be quick. Not sure if it is a problem with my Android phone (I don't have an Android tablet with BLE), BOOST, my laptop or even ubertooth sniffer itself.

Will also give some whole capture files for everybody to look at it instead of just waiting for my findings.

I only capture late at night because it requires full attention so expect just a few captures each night.

@JorgePe
Copy link
Owner

JorgePe commented Sep 1, 2017

OK, I got it.

motor A 50º at 100%:
0e:00:81:37:11:0b:32:00:00:00:64:64:7f:03
4th byte = 37h = motor A
7th byte = 32h = 50d
117th byte = 64h = 100d

motor A 1º at 100%:
0e:00:81:37:11:0b:01:00:00:00:64:64:7f:03

motor A 25º (19h) at 50% (32h):
0e:00:81:37:11:0b:19:00:00:00:32:64:7f:03

I can turn motor A by 1º at 100% duty cycle with:
gatttool -b 00:16:53:A4:CD:7E --char-write-req --handle=0x0e --value=0e008137110b0100000064647f03

Sorry but don't have capture files. Today I can't capture not even one initiall connection session. I'm at work (my first captures were at home and then I went on holidays) and there are a few laptops and smartphones around... I think my ubertooth sniffer needs a clean environment to work.

To get this captures I had to keep pressing the green start/run/play/whatever block until something was captured.

@JorgePe
Copy link
Owner

JorgePe commented Sep 1, 2017

I tried to capture a long rotation command but cannot capture anything else and I'm getting warnings that battery is low (but it is not, at least the battery level shown when selecting the LEGO Move Hub is Full).

But the maximum angle that the App allows is 9999 or 27 full rotations and a bit more than 3/4 (9999 = 27x360+270+9 degrees) that will be 270Fh so only two bytes are needed.

@helje5
Copy link
Contributor Author

helje5 commented Sep 1, 2017

I think @hobbyquaker got sniffing equipment as well now and may soon provide captures as well.

Wrt my original issue, I can do this know. The motor-angle notifications report the location of the motor, and you can simply rotate until you reach the desired state (w/ a low dutycycle to keep it precise). We have all that is necessary documented.

I'm keeping this issue open, since I still wonder whether there might be an additional "turn-to" packet in addition to the "turn-by" and "duration" ones we already have.

@JorgePe
Copy link
Owner

JorgePe commented Sep 1, 2017

If such a command exists we need a block in the App to generate it for capture or keep trying issuing our own commands randomly.

But honestly I don't expect it. I don't see the BOOST designed as a robotic product. Perhaps things change and future firmware versions make me change my opinion.

@glebreutov
Copy link

glebreutov commented Aug 15, 2021

Going through Lego BLE doc, and I think their "GotoAbsolutePosition" is just what you need.

Here is a quick example of command in Swift. Though, no guarantee that it works properly

    public let portId: PortId
    public let absPos: Int32

    public let speed: Int8
    public let maxPower: UInt8
    
    public init(portId: PortId, absPos: Int32, speed: Int8, maxPower: UInt8 = 100) {
        self.portId = portId
        self.absPos = absPos
        self.speed = speed
        self.maxPower = maxPower
    }
    
    public var data: Data {
        let speed = UInt8(bitPattern: self.speed)
        let degreeBytes = withUnsafeBytes(of: absPos.littleEndian, Array.init)

        var d = Data([0x09, 0x00, 0x81, portId, 0x11, 0x0D])
            d.append(contentsOf: degreeBytes)
            d.append(speed)
            d.append(maxPower)
            d.append(EndState.breakFlag.rawValue)
        return d
    }
    
}```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants