// // Vehicle.swift // // // Created by Michael Pivato on 8/5/20. // import Foundation import SwiftyGPIO protocol Vehicle2D{ var throttle: Float {get set} var steering: Float {get set} mutating func move2D(magnitude: Float, angle: Float) } class MockVehicle: Vehicle2D { var throttle: Float = 0 var steering: Float = 0 func move2D(magnitude: Float, angle: Float) { } } class RPiVehicle2D: Vehicle2D{ public var pwmThrottle: Servo public var pwmSteering: Servo var throttle: Float{ get{ return pwmThrottle.value } set(value){ pwmThrottle.value = value } } var steering: Float{ get{ return pwmSteering.value } set(value){ pwmSteering.value = value } } init(withThrottlePin: Servo, withSteeringPin: Servo){ pwmThrottle = withThrottlePin pwmSteering = withSteeringPin } func calibrate(){ // Define a function that indicates how the throttle/steering should be set for given magnitude/angle to move. } func move2D(magnitude: Float, angle: Float) { } func stop(){ pwmThrottle.detach() pwmSteering.detach() } }