-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
76 lines (63 loc) · 2.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2020 Author Name. All rights reserved.
// Use of this source code is governed by the Apache License, Version 2.0
// that can be found in the LICENSE file.
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright (c) 2020 Author Name. All rights reserved.
// Use of this source code is governed by the Apache License, Version 2.0
// that can be found in the LICENSE file.
package main
import (
//"log"
"fmt"
"time"
"github.com/kelceydamage/robo-go/lib/drivers"
"github.com/kelceydamage/robo-go/lib/sensors"
)
/**************************************************
ff 55 len idx action device port slot data a
0 1 2 3 4 5 6 7 8
**************************************************
[]byte{255, 85, 6, 0, 2, 10, port, speed}
*/
// Global objects
var sensorPackage sensors.SensorPackage
var sensorFeed = make(chan sensors.SensorReading, 512)
func init() {
// Configure communications
options := drivers.OpenOptions{
PortName: "/dev/ttyTHS1",
BaudRate: 76800, // Best|stable option for using Jetson and Megapi
DataBits: 8,
StopBits: 1,
MinimumReadSize: 4,
InterCharacterTimeout: 1,
}
drivers.SerialState.Open(options)
sensors.LoadSensorTypes()
sensorPackage.Initialize()
sensorPackage.WriteLength(1)
// Configure sensors
sensors.Ultrasonic.Initialize()
sensorPackage.SetSensor(&sensors.Ultrasonic)
}
func main() {
defer drivers.SerialState.Close()
sensors.BufferSensors(sensorPackage, sensorFeed)
time.Sleep(1 * time.Second)
// Main loop
counter := 0
for {
result := <-sensorFeed
fmt.Printf("Receiving: %v\n", result.GetValue())
counter++
fmt.Printf("Receiving Count: %v Channel Occupancy: %v\n", counter, len(sensorFeed))
}
//fmt.Println("main finished")
}