Skip to content

Commit

Permalink
WIP - working with parallel actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Dec 20, 2023
1 parent 0dbea06 commit b775d06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@ struct RobotKitExperimentView: View {
Button("Launch Synchronous Sequence", systemImage: "play.circle") {
self.robotkit.append(actions: [
.motion(.spin(.clockwise, speed: 1), duration: .seconds(4), parallel: []),
.motion(.stop, duration: .seconds(3), parallel: [
// .lights(.full(.belt, in: .red), duration: .seconds(3)),
.motion(.stop, duration: .seconds(3), parallel: []),
.motion(.spin(.counterclockwise, speed: 0.8), duration: .seconds(4), parallel: [
.blink(.seconds(0.2), duration: .seconds(2), parallel: []),
]),
.blink(.seconds(0.2), duration: .seconds(5), parallel: []),
// .motion(.spin(.counterclockwise, speed: 0.8), duration: .seconds(4), parallel: [
// .blink(.seconds(0.2), duration: .seconds(2), parallel: []),
// ]),
// .pause(duration: .infinity),
])

self.robotkit.executeSync()
Expand Down
8 changes: 8 additions & 0 deletions Modules/RobotKit/Sources/RobotKit/ActionMotion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ final class ActionMotion: RobotActionProtocol {
}
log.debug("motion - start task - move")
self.robot.move(self.motion)
for action in self.parallelActions {
log.debug("motion - start task - parallel action \(action)")
Task {
try await action.object.execute()
}
// /* async let _ = */ try action.object.execute()
log.debug("motion - start task - parallel action \(action)")
}
try await Task.sleep(for: self.duration)
log.debug("motion - end task")
}
Expand Down
3 changes: 2 additions & 1 deletion Modules/RobotKit/Sources/RobotKit/RobotAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import Foundation

public enum RobotAction {
case motion(Robot.Motion, duration: Duration, parallel: [RobotAction] = [])
// case lights(Robot.Lights, duration: Duration, parallel: [RobotAction] = [])

case blink(Duration, duration: Duration, parallel: [RobotAction] = [])
// case lights(Robot.Lights, duration: Duration, parallel: [RobotAction] = [])
// case pause(duration: Duration)

// MARK: Public
Expand Down

0 comments on commit b775d06

Please sign in to comment.