Files
swift2dcar/Sources/Swift2dCar/Vehicle.swift
2020-09-02 21:36:18 +09:30

57 lines
992 B
Swift

//
// Vehicle.swift
//
//
// Created by Michael Pivato on 8/5/20.
//
import Foundation
import SwiftyGPIO
public protocol Vehicle2D{
var throttle: Float {get set}
var steering: Float {get set}
}
class MockVehicle: Vehicle2D {
public var throttle: Float = 0
public var steering: Float = 0
}
open class RPiVehicle2D: Vehicle2D{
var pwmThrottle: Servo
var pwmSteering: Servo
public var throttle: Float{
get{
return pwmThrottle.value
}
set(value){
pwmThrottle.value = value
}
}
public var steering: Float{
get{
return pwmSteering.value
}
set(value){
pwmSteering.value = value
}
}
init(withThrottlePin: Servo, withSteeringPin: Servo){
pwmThrottle = withThrottlePin
pwmSteering = withSteeringPin
}
func stop(){
pwmThrottle.detach()
pwmSteering.detach()
}
}