Initial Commit

This commit is contained in:
Piv
2020-08-31 22:47:00 +09:30
commit 2777d5c48d
9 changed files with 252 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
//
// 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()
}
}