Files
swift2dcar/Sources/Swift2dCar/Vehicle.swift
2020-09-02 23:05:26 +09:30

60 lines
1.0 KiB
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}
}
public class MockVehicle: Vehicle2D {
public var throttle: Float = 0
public var steering: Float = 0
public init(){
}
}
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
}
}
public init(withThrottlePin: Servo, withSteeringPin: Servo){
pwmThrottle = withThrottlePin
pwmSteering = withSteeringPin
}
func stop(){
pwmThrottle.detach()
pwmSteering.detach()
}
}