From 71c93f2e73b86ce699af8af000c6520553e54c7d Mon Sep 17 00:00:00 2001 From: Cyrille Nofficial Date: Tue, 12 Oct 2021 22:13:44 +0200 Subject: [PATCH] fix: default values --- cmd/rc-simulator/rc-simultator.go | 14 +++++------ pkg/gateway/gateway.go | 39 ++++++++++++++++--------------- pkg/simulator/simulator.go | 2 +- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/cmd/rc-simulator/rc-simultator.go b/cmd/rc-simulator/rc-simultator.go index ff6453f..2d168c8 100644 --- a/cmd/rc-simulator/rc-simultator.go +++ b/cmd/rc-simulator/rc-simultator.go @@ -63,7 +63,7 @@ func main() { flag.Float64Var(&cameraFishEyeX, "camera-fish-eye-x", 0.4, "") flag.Float64Var(&cameraFishEyeY, "camera-fish-eye-y", 0.7, "") flag.IntVar(&cameraImgW, "camera-img-w", 160, "image width") - flag.IntVar(&cameraImgH, "camera-img-h", 120, "image height") + flag.IntVar(&cameraImgH, "camera-img-h", 128, "image height") flag.IntVar(&cameraImgD, "camera-img-d", 3, "Image depth") flag.StringVar(&cameraImgEnc, "camera-img-enc", string(simulator.CameraImageEncJpeg), "") flag.Float64Var(&cameraOffsetX, "camera-offset-x", 0, "moves camera left/right") @@ -107,16 +107,16 @@ func main() { camera := simulator.CamConfigMsg{ MsgType: simulator.MsgTypeCameraConfig, Fov: strconv.Itoa(cameraFov), - FishEyeX: fmt.Sprintf("%f", cameraFishEyeX), - FishEyeY: fmt.Sprintf("%f",cameraFishEyeY), + FishEyeX: fmt.Sprintf("%.2f", cameraFishEyeX), + FishEyeY: fmt.Sprintf("%.2f",cameraFishEyeY), ImgW: strconv.Itoa(cameraImgW), ImgH: strconv.Itoa(cameraImgH), ImgD: strconv.Itoa(cameraImgD), ImgEnc: simulator.CameraImageEnc(cameraImgEnc), - OffsetX: fmt.Sprintf("%f",cameraOffsetX), - OffsetY: fmt.Sprintf("%f", cameraOffsetY), - OffsetZ: fmt.Sprintf("%f", cameraOffsetZ), - RotX: fmt.Sprintf("%f", cameraOffsetZ), + OffsetX: fmt.Sprintf("%.2f",cameraOffsetX), + OffsetY: fmt.Sprintf("%.2f", cameraOffsetY), + OffsetZ: fmt.Sprintf("%.2f", cameraOffsetZ), + RotX: fmt.Sprintf("%.2f", cameraRotX), } gtw := gateway.New(address, &carConfig, &racer, &camera) defer gtw.Stop() diff --git a/pkg/gateway/gateway.go b/pkg/gateway/gateway.go index c5b9f83..370f91c 100644 --- a/pkg/gateway/gateway.go +++ b/pkg/gateway/gateway.go @@ -43,11 +43,11 @@ func New(addressSimulator string, car *simulator.CarConfigMsg, racer *simulator. throttleSubscribers: make(map[chan<- *events.ThrottleMessage]interface{}), telemetrySubscribers: make(map[chan *simulator.TelemetryMsg]interface{}), carSubscribers: make(map[chan *simulator.Msg]interface{}), - racerSubscribers: make(map[chan *simulator.Msg]interface{}), - cameraSubscribers: make(map[chan *simulator.Msg]interface{}), + racerSubscribers: make(map[chan *simulator.Msg]interface{}), + cameraSubscribers: make(map[chan *simulator.Msg]interface{}), carConfig: car, racer: racer, - cameraConfig: camera, + cameraConfig: camera, } } @@ -72,11 +72,11 @@ type Gateway struct { telemetrySubscribers map[chan *simulator.TelemetryMsg]interface{} carSubscribers map[chan *simulator.Msg]interface{} - racerSubscribers map[chan *simulator.Msg]interface{} - cameraSubscribers map[chan *simulator.Msg]interface{} + racerSubscribers map[chan *simulator.Msg]interface{} + cameraSubscribers map[chan *simulator.Msg]interface{} - carConfig *simulator.CarConfigMsg - racer *simulator.RacerBioMsg + carConfig *simulator.CarConfigMsg + racer *simulator.RacerBioMsg cameraConfig *simulator.CamConfigMsg } @@ -87,14 +87,14 @@ func (g *Gateway) Start() error { go g.run() - err := g.writeCarConfig() - if err != nil { - return fmt.Errorf("unable to configure car to server: %v", err) - } - err = g.writeRacerConfig() + err := g.writeRacerConfig() if err != nil { return fmt.Errorf("unable to configure racer to server: %v", err) } + err = g.writeCarConfig() + if err != nil { + return fmt.Errorf("unable to configure car to server: %v", err) + } err = g.writeCameraConfig() if err != nil { return fmt.Errorf("unable to configure camera to server: %v", err) @@ -398,7 +398,7 @@ func (g *Gateway) writeCommand(content []byte) error { g.log.Errorf("unable to connect to simulator to send control command: %v", err) return nil } - log.Debugf("write command to simulator: %v", g.lastControl) + log.Debugf("write command to simulator: %v", string(content)) w := bufio.NewWriter(g.conn) _, err := w.Write(append(content, '\n')) @@ -458,6 +458,7 @@ func (g *Gateway) writeCarConfig() error { msg := <-carChan g.log.Infof("Car loaded: %v", msg) + time.Sleep(250 * time.Millisecond) return nil } @@ -477,10 +478,10 @@ func (g *Gateway) writeRacerConfig() error { return fmt.Errorf("unable to send racer config to simulator: %v", err) } - select{ - case msg := <-racerChan: - g.log.Infof("Racer loaded: %v", msg) - case <- time.Tick(25 * time.Millisecond): + select { + case msg := <-racerChan: + g.log.Infof("Racer loaded: %v", msg) + case <-time.Tick(250 * time.Millisecond): } return nil } @@ -501,10 +502,10 @@ func (g *Gateway) writeCameraConfig() error { return fmt.Errorf("unable to send camera config to simulator: %v", err) } - select{ + select { case msg := <-cameraChan: g.log.Infof("Camera configured: %v", msg) - case <- time.Tick(25 * time.Millisecond): + case <-time.Tick(250 * time.Millisecond): } return nil } diff --git a/pkg/simulator/simulator.go b/pkg/simulator/simulator.go index 270ba65..059bd70 100644 --- a/pkg/simulator/simulator.go +++ b/pkg/simulator/simulator.go @@ -104,7 +104,7 @@ type CamConfigMsg struct { MsgType MsgType `json:"msg_type"` Fov string `json:"fov"` FishEyeX string `json:"fish_eye_x"` - FishEyeY string `json:"fish_eye_Y"` + FishEyeY string `json:"fish_eye_y"` ImgW string `json:"img_w"` ImgH string `json:"img_h"` ImgD string `json:"img_d"`