aboutsummaryrefslogtreecommitdiff
path: root/car/elegoo
diff options
context:
space:
mode:
Diffstat (limited to 'car/elegoo')
-rw-r--r--car/elegoo/elegoo.pb.go70
-rw-r--r--car/elegoo/elegoo.proto12
-rw-r--r--car/elegoo/main.go63
3 files changed, 75 insertions, 70 deletions
diff --git a/car/elegoo/elegoo.pb.go b/car/elegoo/elegoo.pb.go
index b20c09c..0d779ee 100644
--- a/car/elegoo/elegoo.pb.go
+++ b/car/elegoo/elegoo.pb.go
@@ -29,12 +29,11 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
type Command struct {
- SpeedR int32 `protobuf:"zigzag32,1,opt,name=SpeedR" json:"SpeedR,omitempty"`
- SpeedL int32 `protobuf:"zigzag32,2,opt,name=SpeedL" json:"SpeedL,omitempty"`
- Stop bool `protobuf:"varint,3,opt,name=Stop" json:"Stop,omitempty"`
- Center bool `protobuf:"varint,4,opt,name=Center" json:"Center,omitempty"`
- TurnHead int32 `protobuf:"zigzag32,5,opt,name=TurnHead" json:"TurnHead,omitempty"`
- Trim int32 `protobuf:"zigzag32,6,opt,name=Trim" json:"Trim,omitempty"`
+ SpeedR int32 `protobuf:"zigzag32,1,opt,name=SpeedR" json:"SpeedR,omitempty"`
+ SpeedL int32 `protobuf:"zigzag32,2,opt,name=SpeedL" json:"SpeedL,omitempty"`
+ Stop bool `protobuf:"varint,3,opt,name=Stop" json:"Stop,omitempty"`
+ Center bool `protobuf:"varint,4,opt,name=Center" json:"Center,omitempty"`
+ Direction int32 `protobuf:"zigzag32,5,opt,name=Direction" json:"Direction,omitempty"`
}
func (m *Command) Reset() { *m = Command{} }
@@ -70,26 +69,20 @@ func (m *Command) GetCenter() bool {
return false
}
-func (m *Command) GetTurnHead() int32 {
+func (m *Command) GetDirection() int32 {
if m != nil {
- return m.TurnHead
- }
- return 0
-}
-
-func (m *Command) GetTrim() int32 {
- if m != nil {
- return m.Trim
+ return m.Direction
}
return 0
}
type Event struct {
- Distance uint32 `protobuf:"varint,1,opt,name=Distance" json:"Distance,omitempty"`
- SensorR bool `protobuf:"varint,2,opt,name=SensorR" json:"SensorR,omitempty"`
- SensorC bool `protobuf:"varint,3,opt,name=SensorC" json:"SensorC,omitempty"`
- SensorL bool `protobuf:"varint,4,opt,name=SensorL" json:"SensorL,omitempty"`
- KeyPress uint32 `protobuf:"varint,5,opt,name=KeyPress" json:"KeyPress,omitempty"`
+ Distance uint32 `protobuf:"varint,1,opt,name=Distance" json:"Distance,omitempty"`
+ Direction int32 `protobuf:"zigzag32,2,opt,name=Direction" json:"Direction,omitempty"`
+ SensorR bool `protobuf:"varint,3,opt,name=SensorR" json:"SensorR,omitempty"`
+ SensorC bool `protobuf:"varint,4,opt,name=SensorC" json:"SensorC,omitempty"`
+ SensorL bool `protobuf:"varint,5,opt,name=SensorL" json:"SensorL,omitempty"`
+ KeyPress uint32 `protobuf:"varint,6,opt,name=KeyPress" json:"KeyPress,omitempty"`
}
func (m *Event) Reset() { *m = Event{} }
@@ -104,6 +97,13 @@ func (m *Event) GetDistance() uint32 {
return 0
}
+func (m *Event) GetDirection() int32 {
+ if m != nil {
+ return m.Direction
+ }
+ return 0
+}
+
func (m *Event) GetSensorR() bool {
if m != nil {
return m.SensorR
@@ -140,19 +140,19 @@ func init() {
func init() { proto.RegisterFile("elegoo.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
- // 219 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xb1, 0x4a, 0xc5, 0x30,
- 0x14, 0x86, 0x89, 0xb6, 0x69, 0x09, 0x76, 0x30, 0x83, 0x04, 0xa7, 0xd2, 0xa9, 0x93, 0x8b, 0x6f,
- 0x60, 0x15, 0x04, 0x3b, 0x48, 0xda, 0xc9, 0x2d, 0xda, 0x83, 0x14, 0x4c, 0x52, 0x92, 0x28, 0xf8,
- 0x10, 0x8e, 0xbe, 0xef, 0x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0xff, 0xf5, 0x58,
+ 0xf9, 0x81, 0xbf, 0x64, 0x53, 0x6f, 0xec, 0x2b, 0x8f, 0x27, 0xbc, 0xff, 0x09, 0x00, 0x00, 0xff,
+ 0xff, 0x78, 0x67, 0x1b, 0x88, 0x52, 0x01, 0x00, 0x00,
}
diff --git a/car/elegoo/elegoo.proto b/car/elegoo/elegoo.proto
index bdf1b95..f9b13bf 100644
--- a/car/elegoo/elegoo.proto
+++ b/car/elegoo/elegoo.proto
@@ -7,14 +7,14 @@ message Command {
sint32 SpeedL = 2;
bool Stop = 3;
bool Center = 4;
- sint32 TurnHead = 5; // ±90 deg
- sint32 Trim = 6;
+ sint32 Direction = 5; // +90 left; -90 right
}
message Event {
uint32 Distance = 1;
- bool SensorR = 2;
- bool SensorC = 3;
- bool SensorL = 4;
- uint32 KeyPress = 5;
+ sint32 Direction = 2;
+ bool SensorR = 3;
+ bool SensorC = 4;
+ bool SensorL = 5;
+ uint32 KeyPress = 6;
}
diff --git a/car/elegoo/main.go b/car/elegoo/main.go
index df5dabc..e2f4e05 100644
--- a/car/elegoo/main.go
+++ b/car/elegoo/main.go
@@ -7,6 +7,7 @@ import (
"bufio"
"io"
"log"
+ "time"
"github.com/dim13/cobs"
"github.com/golang/protobuf/proto"
@@ -49,38 +50,42 @@ func main() {
defer s.Close()
go func() {
- cmd := &Command{}
- cmd.Trim = -10
- cmd.Center = true
- Write(s, cmd)
-
- /* MOTOR
- cmd.SpeedL = 200
- cmd.SpeedR = 0
- cmd.Stop = false
- Write(s, cmd)
- time.Sleep(3 * time.Second)
-
- cmd.SpeedL = 0
- cmd.SpeedR = 0
- cmd.Stop = true
- Write(s, cmd)
- time.Sleep(3 * time.Second)
-
- cmd.SpeedL = 0
- cmd.SpeedR = 200
- cmd.Stop = false
- Write(s, cmd)
- time.Sleep(3 * time.Second)
-
- cmd.SpeedL = 0
- cmd.SpeedR = 0
- cmd.Stop = true
- Write(s, cmd)
- */
+ time.Sleep(5 * time.Second)
+ Write(s, &Command{Direction: -45})
+ time.Sleep(time.Second)
+
+ Write(s, &Command{Direction: 45})
+ time.Sleep(time.Second)
+
+ Write(s, &Command{Center: true})
}()
+ /* MOTOR
+ cmd.SpeedL = 200
+ cmd.SpeedR = 0
+ cmd.Stop = false
+ Write(s, cmd)
+ time.Sleep(3 * time.Second)
+
+ cmd.SpeedL = 0
+ cmd.SpeedR = 0
+ cmd.Stop = true
+ Write(s, cmd)
+ time.Sleep(3 * time.Second)
+
+ cmd.SpeedL = 0
+ cmd.SpeedR = 200
+ cmd.Stop = false
+ Write(s, cmd)
+ time.Sleep(3 * time.Second)
+
+ cmd.SpeedL = 0
+ cmd.SpeedR = 0
+ cmd.Stop = true
+ Write(s, cmd)
+ */
+
buf := bufio.NewReader(s)
for {
evt := &Event{}