repo_id
stringlengths
19
138
file_path
stringlengths
32
200
content
stringlengths
1
12.9M
__index_level_0__
int64
0
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_conf/camera_left_fisheye.pb.txt
camera_dev: "/dev/camera/left_fisheye" frame_id: "camera_left_fisheye" pixel_format: "yuyv" io_method: IO_METHOD_MMAP width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 2 trigger_internal: 0 trigger_fps: 20 channel_name: "/apollo/sensor/camera/left_fisheye/image" device_wait_ms: 2000 spin_rate: 200 output_type: RGB compress_conf { output_channel: "/apollo/sensor/camera/left_fisheye/image/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_conf/camera_right_front.pb.txt
camera_dev: "/dev/camera/right_front" frame_id: "camera_right_front" pixel_format: "yuyv" io_method: IO_METHOD_MMAP width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 2 trigger_internal: 0 trigger_fps: 20 channel_name: "/apollo/sensor/camera/right_front/image" device_wait_ms: 2000 spin_rate: 200 output_type: RGB compress_conf { output_channel: "/apollo/sensor/camera/right_front/image/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_conf/camera_front_6mm.pb.txt
camera_dev: "/dev/camera/front_6mm" frame_id: "camera_front_6mm" pixel_format: "yuyv" io_method: IO_METHOD_MMAP width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 2 trigger_internal: 0 trigger_fps: 20 channel_name: "/apollo/sensor/camera/front_6mm/image" device_wait_ms: 2000 spin_rate: 200 output_type: RGB compress_conf { output_channel: "/apollo/sensor/camera/front_6mm/image/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_conf/camera_front_fisheye.pb.txt
camera_dev: "/dev/camera/front_fisheye" frame_id: "camera_front_fisheye" pixel_format: "yuyv" io_method: IO_METHOD_MMAP width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 2 trigger_internal: 0 trigger_fps: 20 channel_name: "/apollo/sensor/camera/front_fisheye/image" device_wait_ms: 2000 spin_rate: 200 output_type: RGB compress_conf { output_channel: "/apollo/sensor/camera/front_fisheye/image/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_conf/camera_left_rear.pb.txt
camera_dev: "/dev/camera/left_rear" frame_id: "camera_left_rear" pixel_format: "yuyv" io_method: IO_METHOD_MMAP width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 2 trigger_internal: 0 trigger_fps: 20 channel_name: "/apollo/sensor/camera/left_rear/image" device_wait_ms: 2000 spin_rate: 200 output_type: RGB compress_conf { output_channel: "/apollo/sensor/camera/left_rear/image/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_conf/camera_front_12mm.pb.txt
camera_dev: "/dev/camera/front_12mm" frame_id: "camera_front_12mm" pixel_format: "yuyv" io_method: IO_METHOD_MMAP width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 2 trigger_internal: 0 trigger_fps: 20 channel_name: "/apollo/sensor/camera/front_12mm/image" device_wait_ms: 2000 spin_rate: 200 output_type: RGB compress_conf { output_channel: "/apollo/sensor/camera/front_12mm/image/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/radar_params/radar_front_extrinsics.yaml
header: seq: 0 stamp: secs: 0 nsecs: 0 frame_id: velodyne128 transform: rotation: x: 0.001157270061175516 y: -0.002570299059995321 z: 0.002244856861040311 w: 0.9999935074321339 translation: x: 2.174618901328785 y: 0.08853404186055373 z: -1.206228759485085 child_frame_id: radar_front
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/radar_params/radar_extrinsics.yaml
header: seq: 0 stamp: secs: 0 nsecs: 0 frame_id: short_camera child_frame_id: radar transform: rotation: x: 0.5370174871300957 y: 0.5197173008295932 z: 0.4623163722908032 w: -0.4772522578749639 translation: x: 0.04894393984902981 y: 1.168500489918554 z: 1.371936986822701
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/gnss_conf/gnss_conf.pb.txt
data { format: NOVATEL_BINARY serial { device: "/dev/novatel0" baud_rate: 115200 } } rtk_from { format: RTCM_V3 ntrip { address: "<IP>" port: <PORT> mount_point: "<MOUNTPOINT>" user: "<USER>" password: "<PASSWORD>" timeout_s: 5 } push_location: true } rtk_to { format: NOVATEL_BINARY serial { device: "/dev/novatel1" baud_rate: 115200 } } command { format: NOVATEL_BINARY serial { device: "/dev/novatel2" baud_rate: 115200 } } rtk_solution_type: RTK_RECEIVER_SOLUTION imu_type: G320N proj4_text: "+proj=utm +zone=10 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs" tf { frame_id: "world" child_frame_id: "novatel" } # If given, the driver will send velocity info into novatel one time per second wheel_parameters: "SETWHEELPARAMETERS 100 1 1\r\n" gpsbin_folder: "/apollo/data/gpsbin" ######################################################################### # notice: only for debug, won't configure device through driver online!!! ######################################################################### # login_commands: "UNLOGALL THISPORT\r\n" # login_commands: "LOG COM2 GPRMC ONTIME 1.0 0.25\r\n" # login_commands: "EVENTOUTCONTROL MARK2 ENABLE POSITIVE 999999990 10\r\n" # login_commands: "EVENTOUTCONTROL MARK1 ENABLE POSITIVE 500000000 500000000\r\n" # login_commands: "LOG GPGGA ONTIME 1.0\r\n" # login_commands: "log bestgnssposb ontime 1\r\n" # login_commands: "log bestgnssvelb ontime 1\r\n" # login_commands: "log bestposb ontime 1\r\n" # login_commands: "log INSPVAXB ontime 0.5\r\n" # login_commands: "log INSPVASB ontime 0.01\r\n" # login_commands: "log CORRIMUDATASB ontime 0.01\r\n" # login_commands: "log RAWIMUSXB onnew 0 0\r\n" # login_commands: "log INSCOVSB ontime 1\r\n" # login_commands: "log mark1pvab onnew\r\n" # login_commands: "log rangeb ontime 0.2\r\n" # login_commands: "log bdsephemerisb\r\n" # login_commands: "log gpsephemb\r\n" # login_commands: "log gloephemerisb\r\n" # login_commands: "log bdsephemerisb ontime 15\r\n" # login_commands: "log gpsephemb ontime 15\r\n" # login_commands: "log gloephemerisb ontime 15\r\n" # login_commands: "log imutoantoffsetsb once\r\n" # login_commands: "log vehiclebodyrotationb onchanged\r\n" logout_commands: "EVENTOUTCONTROL MARK2 DISABLE\r\n" logout_commands: "EVENTOUTCONTROL MARK1 DISABLE\r\n"
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_params/velodyne64_height.yaml
vehicle: parameters: height: 1.89 height_var: 0.0045
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_params/64E_S3_calibration_example.yaml
lasers: - {dist_correction: 1.2752063, dist_correction_x: 1.3139189, dist_correction_y: 1.3201204000000002, focal_distance: 23.0, focal_slope: 0.80000001, horiz_offset_correction: 0.025999999, laser_id: 0, min_intensity: 40, rot_correction: -0.07883297231288532, vert_correction: -0.1225589730984748, vert_offset_correction: 0.21543011} - {dist_correction: 1.354117, dist_correction_x: 1.3893244999999999, dist_correction_y: 1.3824525, focal_distance: 11.1, focal_slope: 1.3, horiz_offset_correction: -0.025999999, laser_id: 1, min_intensity: 40, rot_correction: -0.04257169063286875, vert_correction: -0.11732028531813898, vert_offset_correction: 0.21504793} - {dist_correction: 1.3552602999999999, dist_correction_x: 1.4380073999999998, dist_correction_y: 1.4320663, focal_distance: 24.0, focal_slope: 0.69999999, horiz_offset_correction: 0.025999999, laser_id: 2, min_intensity: 40, rot_correction: 0.0576001797697238, vert_correction: 0.006831742116548479, vert_offset_correction: 0.20608189} - {dist_correction: 1.3331795, dist_correction_x: 1.3594026, dist_correction_y: 1.3993605, focal_distance: 23.0, focal_slope: 0.94999999, horiz_offset_correction: -0.025999999, laser_id: 3, min_intensity: 40, rot_correction: 0.09708671122503676, vert_correction: 0.011737269755557637, vert_offset_correction: 0.2057291} - {dist_correction: 1.272046, dist_correction_x: 1.3137018, dist_correction_y: 1.2978722, focal_distance: 24.0, focal_slope: 0.69999999, horiz_offset_correction: 0.025999999, laser_id: 4, min_intensity: 40, rot_correction: -0.004134042716809833, vert_correction: -0.11106570246674108, vert_offset_correction: 0.21459229000000002} - {dist_correction: 1.1886112, dist_correction_x: 1.2300569000000001, dist_correction_y: 1.2463203, focal_distance: 24.0, focal_slope: 1.2, horiz_offset_correction: -0.025999999, laser_id: 5, min_intensity: 40, rot_correction: 0.03539678170426023, vert_correction: -0.1054088809215172, vert_offset_correction: 0.21418074} - {dist_correction: 1.2976839000000002, dist_correction_x: 1.3396898, dist_correction_y: 1.3132230999999999, focal_distance: 24.0, focal_slope: 0.89999998, horiz_offset_correction: 0.025999999, laser_id: 6, min_intensity: 40, rot_correction: -0.01812813105654391, vert_correction: -0.14704592330533348, vert_offset_correction: 0.2172233} - {dist_correction: 1.2863681, dist_correction_x: 1.3238104000000002, dist_correction_y: 1.3377951, focal_distance: 14.0, focal_slope: 1.25, horiz_offset_correction: -0.025999999, laser_id: 7, min_intensity: 40, rot_correction: 0.020696316728341994, vert_correction: -0.14023825084996633, vert_offset_correction: 0.21672356} - {dist_correction: 1.2849046000000002, dist_correction_x: 1.3267589000000002, dist_correction_y: 1.3180791, focal_distance: 24.0, focal_slope: 0.60000002, horiz_offset_correction: 0.025999999, laser_id: 8, min_intensity: 40, rot_correction: 0.0709183561953673, vert_correction: -0.09954287817478333, vert_offset_correction: 0.21375446} - {dist_correction: 1.3211784, dist_correction_x: 1.3745055, dist_correction_y: 1.3908893, focal_distance: 17.5, focal_slope: 1.2, horiz_offset_correction: -0.025999999, laser_id: 9, min_intensity: 40, rot_correction: 0.11014432221066224, vert_correction: -0.09387264202892864, vert_offset_correction: 0.21334291} - {dist_correction: 1.2667397, dist_correction_x: 1.3151773, dist_correction_y: 1.3144638000000002, focal_distance: 10.0, focal_slope: 1.8, horiz_offset_correction: 0.025999999, laser_id: 10, min_intensity: 40, rot_correction: 0.05752680089198221, vert_correction: -0.1352242183602887, vert_offset_correction: 0.21635611000000002} - {dist_correction: 1.2552061, dist_correction_x: 1.2864645, dist_correction_y: 1.313914, focal_distance: 17.0, focal_slope: 1.4, horiz_offset_correction: -0.025999999, laser_id: 11, min_intensity: 40, rot_correction: 0.09560686749622178, vert_correction: -0.12939936000534133, vert_offset_correction: 0.21592983000000002} - {dist_correction: 1.2950737, dist_correction_x: 1.3264038, dist_correction_y: 1.3272704, focal_distance: 24.0, focal_slope: 1.3, horiz_offset_correction: 0.025999999, laser_id: 12, min_intensity: 10, rot_correction: -0.07894119668914298, vert_correction: -0.05117740128364046, vert_offset_correction: 0.21025623} - {dist_correction: 1.3314511, dist_correction_x: 1.3439276000000002, dist_correction_y: 1.3750456, focal_distance: 24.0, focal_slope: 1.2, horiz_offset_correction: -0.025999999, laser_id: 13, min_intensity: 25, rot_correction: -0.039590087075821526, vert_correction: -0.04567113183969363, vert_offset_correction: 0.20985937} - {dist_correction: 1.2853152, dist_correction_x: 1.3545485, dist_correction_y: 1.32582, focal_distance: 20.0, focal_slope: 1.15, horiz_offset_correction: 0.025999999, laser_id: 14, min_intensity: 40, rot_correction: -0.09264152866247388, vert_correction: -0.08697921631142325, vert_offset_correction: 0.21284317000000003} - {dist_correction: 1.1956883999999999, dist_correction_x: 1.2309952, dist_correction_y: 1.2384804, focal_distance: 19.5, focal_slope: 1.15, horiz_offset_correction: -0.025999999, laser_id: 15, min_intensity: 40, rot_correction: -0.053828922936562766, vert_correction: -0.08088988123360417, vert_offset_correction: 0.21240220999999998} - {dist_correction: 1.2622006000000001, dist_correction_x: 1.3391359, dist_correction_y: 1.3450137000000002, focal_distance: 24.0, focal_slope: 1.05, horiz_offset_correction: 0.025999999, laser_id: 16, min_intensity: 25, rot_correction: -0.004196640695761861, vert_correction: -0.040366165181013325, vert_offset_correction: 0.20947721000000002} - {dist_correction: 1.3882208, dist_correction_x: 1.4129477, dist_correction_y: 1.4390656000000002, focal_distance: 24.0, focal_slope: 1.1, horiz_offset_correction: -0.025999999, laser_id: 17, min_intensity: 20, rot_correction: 0.035191251731545366, vert_correction: -0.03485476621439488, vert_offset_correction: 0.20908035000000003} - {dist_correction: 1.270416, dist_correction_x: 1.3805045999999999, dist_correction_y: 1.3587926, focal_distance: 24.0, focal_slope: 0.64999998, horiz_offset_correction: 0.025999999, laser_id: 18, min_intensity: 40, rot_correction: -0.01796702320395082, vert_correction: -0.07621729099615271, vert_offset_correction: 0.21206415} - {dist_correction: 1.4391471999999998, dist_correction_x: 1.4701469, dist_correction_y: 1.4810228, focal_distance: 24.0, focal_slope: 1.15, horiz_offset_correction: -0.025999999, laser_id: 19, min_intensity: 10, rot_correction: 0.021402925493316658, vert_correction: -0.07052442491121666, vert_offset_correction: 0.21165258} - {dist_correction: 1.3115741, dist_correction_x: 1.4043790000000003, dist_correction_y: 1.3746985, focal_distance: 24.0, focal_slope: 1.1, horiz_offset_correction: 0.025999999, laser_id: 20, min_intensity: 40, rot_correction: 0.07015680097488135, vert_correction: -0.02893277679591552, vert_offset_correction: 0.20865412} - {dist_correction: 1.3147861, dist_correction_x: 1.3458926, dist_correction_y: 1.3786374000000001, focal_distance: 22.0, focal_slope: 1.0, horiz_offset_correction: -0.025999999, laser_id: 21, min_intensity: 15, rot_correction: 0.10896112162283324, vert_correction: -0.022600128857734412, vert_offset_correction: 0.20819845} - {dist_correction: 1.2870654, dist_correction_x: 1.3318181000000002, dist_correction_y: 1.3219449, focal_distance: 21.0, focal_slope: 0.89999998, horiz_offset_correction: 0.025999999, laser_id: 22, min_intensity: 5, rot_correction: 0.056491201053665105, vert_correction: -0.06441985659968617, vert_offset_correction: 0.21121164} - {dist_correction: 1.3116136, dist_correction_x: 1.3367073, dist_correction_y: 1.3722873999999998, focal_distance: 24.0, focal_slope: 0.94999999, horiz_offset_correction: -0.025999999, laser_id: 23, min_intensity: 5, rot_correction: 0.09605195612607761, vert_correction: -0.058717920038627504, vert_offset_correction: 0.21080008} - {dist_correction: 1.334183, dist_correction_x: 1.3770262, dist_correction_y: 1.3650365, focal_distance: 15.0, focal_slope: 1.5, horiz_offset_correction: 0.025999999, laser_id: 24, min_intensity: 10, rot_correction: -0.07814212387105615, vert_correction: 0.01868575851656834, vert_offset_correction: 0.20522938000000002} - {dist_correction: 1.3277109999999999, dist_correction_x: 1.3308896, dist_correction_y: 1.3380003, focal_distance: 16.0, focal_slope: 1.3, horiz_offset_correction: -0.025999999, laser_id: 25, min_intensity: 20, rot_correction: -0.04068591124530794, vert_correction: 0.02481530248969487, vert_offset_correction: 0.20478842} - {dist_correction: 1.3784187, dist_correction_x: 1.4020284, dist_correction_y: 1.4110085, focal_distance: 21.0, focal_slope: 1.15, horiz_offset_correction: 0.025999999, laser_id: 26, min_intensity: 40, rot_correction: -0.09248550146333334, vert_correction: -0.015856927119606682, vert_offset_correction: 0.20771341} - {dist_correction: 1.3299843000000002, dist_correction_x: 1.3475424, dist_correction_y: 1.3875761, focal_distance: 24.0, focal_slope: 1.15, horiz_offset_correction: -0.025999999, laser_id: 27, rot_correction: -0.05342781834918644, vert_correction: -0.01033868471699117, vert_offset_correction: 0.20731655000000002} - {dist_correction: 1.3601752, dist_correction_x: 1.4000146000000002, dist_correction_y: 1.3781789, focal_distance: 24.0, focal_slope: 0.44999999, horiz_offset_correction: 0.025999999, laser_id: 28, rot_correction: -0.004424292891278668, vert_correction: 0.029513378024883952, vert_offset_correction: 0.20445036000000003} - {dist_correction: 1.3607886, dist_correction_x: 1.4001455999999999, dist_correction_y: 1.4214912000000002, focal_distance: 24.0, focal_slope: 0.75, horiz_offset_correction: -0.025999999, laser_id: 29, rot_correction: 0.03487417427567706, vert_correction: 0.03625176439960543, vert_offset_correction: 0.2039653} - {dist_correction: 1.3876024000000002, dist_correction_x: 1.4266457, dist_correction_y: 1.3987584000000002, focal_distance: 24.0, focal_slope: 1.25, horiz_offset_correction: 0.025999999, laser_id: 30, rot_correction: -0.018163875399624756, vert_correction: -0.004615383580558845, vert_offset_correction: 0.20690498000000002} - {dist_correction: 1.3872712999999999, dist_correction_x: 1.409449, dist_correction_y: 1.4333896, focal_distance: 23.0, focal_slope: 0.94999999, horiz_offset_correction: -0.025999999, laser_id: 31, rot_correction: 0.020882827848197862, vert_correction: 0.001312627241293188, vert_offset_correction: 0.20647875} - {dist_correction: 1.3152968000000003, dist_correction_x: 1.3551462, dist_correction_y: 1.3403419, focal_distance: 24.0, focal_slope: 0.40000001, horiz_offset_correction: 0.025999999, laser_id: 32, rot_correction: -0.12998286720751434, vert_correction: -0.3917846862503118, vert_offset_correction: 0.15982219} - {dist_correction: 1.1306184000000001, dist_correction_x: 1.1613448, dist_correction_y: 1.1695766, focal_distance: 0.25, focal_slope: 1.0, horiz_offset_correction: -0.025999999, laser_id: 33, rot_correction: -0.06963576259729572, vert_correction: -0.38355018793281753, vert_offset_correction: 0.15922519} - {dist_correction: 1.2786647, dist_correction_x: 1.3059875, dist_correction_y: 1.3299147, focal_distance: 24.0, focal_slope: 0.44999999, horiz_offset_correction: 0.025999999, laser_id: 34, rot_correction: 0.08608836360929105, vert_correction: -0.1973354249839361, vert_offset_correction: 0.14657393000000002} - {dist_correction: 1.3474704, dist_correction_x: 1.3588457, dist_correction_y: 1.3945218, focal_distance: 11.0, focal_slope: 1.9, horiz_offset_correction: -0.025999999, laser_id: 35, rot_correction: 0.14181459383312406, vert_correction: -0.18432959791721729, vert_offset_correction: 0.14573559} - {dist_correction: 1.2310821, dist_correction_x: 1.2938965, dist_correction_y: 1.2814186, focal_distance: 16.0, focal_slope: 0.40000001, horiz_offset_correction: 0.025999999, laser_id: 36, rot_correction: -0.009213370242732586, vert_correction: -0.37561450743655717, vert_offset_correction: 0.1586536} - {dist_correction: 1.2136781, dist_correction_x: 1.2622253, dist_correction_y: 1.2666883, focal_distance: 8.0, focal_slope: 0.44999999, horiz_offset_correction: -0.025999999, laser_id: 37, rot_correction: 0.05153091946896116, vert_correction: -0.36709468269294687, vert_offset_correction: 0.1580439} - {dist_correction: 1.3207919000000001, dist_correction_x: 1.3694466, dist_correction_y: 1.3758972, focal_distance: 0.25, focal_slope: 0.43000001, horiz_offset_correction: 0.025999999, laser_id: 38, rot_correction: -0.032988304130995134, vert_correction: -0.42738242167398816, vert_offset_correction: 0.16245152000000002} - {dist_correction: 1.254662, dist_correction_x: 1.2655572, dist_correction_y: 1.2925728, focal_distance: 0.25, focal_slope: 1.1, horiz_offset_correction: -0.025999999, laser_id: 39, rot_correction: 0.02996149305566275, vert_correction: -0.4197376875640353, vert_offset_correction: 0.16187992} - {dist_correction: 1.2326976, dist_correction_x: 1.2977957, dist_correction_y: 1.2959807, focal_distance: 0.25, focal_slope: 0.94999999, horiz_offset_correction: 0.025999999, laser_id: 40, rot_correction: 0.11124875259869024, vert_correction: -0.35546799734786144, vert_offset_correction: 0.15721827} - {dist_correction: 1.2586923, dist_correction_x: 1.2898768999999999, dist_correction_y: 1.2877043000000001, focal_distance: 8.0, focal_slope: 1.55, horiz_offset_correction: -0.025999999, laser_id: 41, rot_correction: 0.17148979704092368, vert_correction: -0.34319637793757907, vert_offset_correction: 0.15635452000000002} - {dist_correction: 1.2951652999999999, dist_correction_x: 1.3469331, dist_correction_y: 1.3253401, focal_distance: 0.25, focal_slope: 0.94999999, horiz_offset_correction: 0.025999999, laser_id: 42, rot_correction: 0.08973073485850933, vert_correction: -0.4113537192494002, vert_offset_correction: 0.16125753} - {dist_correction: 1.2491970000000001, dist_correction_x: 1.2513244000000001, dist_correction_y: 1.2672708000000001, focal_distance: 6.0, focal_slope: 1.45, horiz_offset_correction: -0.025999999, laser_id: 43, rot_correction: 0.15193096025532546, vert_correction: -0.398922524385608, vert_offset_correction: 0.16034298} - {dist_correction: 1.3504793000000002, dist_correction_x: 1.3742923, dist_correction_y: 1.3776834, focal_distance: 11.0, focal_slope: 1.9, horiz_offset_correction: 0.025999999, laser_id: 44, rot_correction: -0.12746921783885332, vert_correction: -0.2851614052352569, vert_offset_correction: 0.15236607} - {dist_correction: 1.3194353, dist_correction_x: 1.3555048, dist_correction_y: 1.3676692, focal_distance: 5.0, focal_slope: 0.55000001, horiz_offset_correction: -0.025999999, laser_id: 45, rot_correction: -0.0670297922925212, vert_correction: -0.27515581660600885, vert_offset_correction: 0.15169286} - {dist_correction: 1.2517572, dist_correction_x: 1.3298462000000002, dist_correction_y: 1.2881517, focal_distance: 9.5, focal_slope: 1.65, horiz_offset_correction: 0.025999999, laser_id: 46, rot_correction: -0.1522074465887801, vert_correction: -0.33538020013520276, vert_offset_correction: 0.15580834} - {dist_correction: 1.214207, dist_correction_x: 1.2622674, dist_correction_y: 1.2687372000000001, focal_distance: 0.25, focal_slope: 0.75, horiz_offset_correction: -0.025999999, laser_id: 47, rot_correction: -0.08983663794686182, vert_correction: -0.3282540382526024, vert_offset_correction: 0.15531295} - {dist_correction: 1.1414406, dist_correction_x: 1.2080206, dist_correction_y: 1.1919655, focal_distance: 8.5, focal_slope: 1.3, horiz_offset_correction: 0.025999999, laser_id: 48, rot_correction: -0.008088342700603029, vert_correction: -0.26946698572230343, vert_offset_correction: 0.1513118} - {dist_correction: 1.1837295, dist_correction_x: 1.2247887, dist_correction_y: 1.2112551, focal_distance: 15.0, focal_slope: 0.69999999, horiz_offset_correction: -0.025999999, laser_id: 49, rot_correction: 0.05046789701743674, vert_correction: -0.2601368046069921, vert_offset_correction: 0.1506894} - {dist_correction: 1.2635911, dist_correction_x: 1.3508514, dist_correction_y: 1.3295909000000001, focal_distance: 13.0, focal_slope: 0.55000001, horiz_offset_correction: 0.025999999, laser_id: 50, rot_correction: -0.03103305540321719, vert_correction: -0.32109314431788744, vert_offset_correction: 0.15481757000000002} - {dist_correction: 1.0956693, dist_correction_x: 1.1582519, dist_correction_y: 1.1591959, focal_distance: 10.5, focal_slope: 0.85000002, horiz_offset_correction: -0.025999999, laser_id: 51, rot_correction: 0.029237828933237592, vert_correction: -0.3140828722976195, vert_offset_correction: 0.15433489} - {dist_correction: 1.2680698, dist_correction_x: 1.3010519, dist_correction_y: 1.3118181999999998, focal_distance: 0.25, focal_slope: 0.69999999, horiz_offset_correction: 0.025999999, laser_id: 52, rot_correction: 0.10784944462775096, vert_correction: -0.2509518697920318, vert_offset_correction: 0.1500797} - {dist_correction: 1.3034142, dist_correction_x: 1.3091043, dist_correction_y: 1.3535146, focal_distance: 11.0, focal_slope: 2.0, horiz_offset_correction: -0.025999999, laser_id: 53, rot_correction: 0.16523614619534635, vert_correction: -0.23940972819591302, vert_offset_correction: 0.14931756999999998} - {dist_correction: 1.3151974000000002, dist_correction_x: 1.3637082, dist_correction_y: 1.3533908, focal_distance: 0.25, focal_slope: 0.40000001, horiz_offset_correction: 0.025999999, laser_id: 54, rot_correction: 0.0869574695089434, vert_correction: -0.30294892830695713, vert_offset_correction: 0.15357277} - {dist_correction: 1.2776234, dist_correction_x: 1.289026, dist_correction_y: 1.3073460000000001, focal_distance: 11.5, focal_slope: 1.85, horiz_offset_correction: -0.025999999, laser_id: 55, rot_correction: 0.1464806513031853, vert_correction: -0.29229936554360075, vert_offset_correction: 0.15284875} - {dist_correction: 1.3890512000000002, dist_correction_x: 1.3877768000000001, dist_correction_y: 1.3785843, focal_distance: 0.25, focal_slope: 1.2, horiz_offset_correction: 0.025999999, laser_id: 56, rot_correction: -0.1252743738020201, vert_correction: -0.17582174613227564, vert_offset_correction: 0.1451894} - {dist_correction: 1.3896303, dist_correction_x: 1.4135710000000001, dist_correction_y: 1.4434415999999999, focal_distance: 0.25, focal_slope: 1.05, horiz_offset_correction: -0.025999999, laser_id: 57, rot_correction: -0.0668689252953649, vert_correction: -0.16848034151967312, vert_offset_correction: 0.14471942000000002} - {dist_correction: 1.4813303, dist_correction_x: 1.5015753, dist_correction_y: 1.5009795, focal_distance: 7.0, focal_slope: 1.65, horiz_offset_correction: 0.025999999, laser_id: 58, rot_correction: -0.14694131176062744, vert_correction: -0.230128800272093, vert_offset_correction: 0.14870787} - {dist_correction: 1.3051801, dist_correction_x: 1.3334875, dist_correction_y: 1.356346, focal_distance: 4.0, focal_slope: 0.94999999, horiz_offset_correction: -0.025999999, laser_id: 59, rot_correction: -0.08817857864812571, vert_correction: -0.2219747092732381, vert_offset_correction: 0.14817439000000002} - {dist_correction: 1.300378, dist_correction_x: 1.3379957999999998, dist_correction_y: 1.3313292, focal_distance: 0.25, focal_slope: 0.60000002, horiz_offset_correction: 0.025999999, laser_id: 60, rot_correction: -0.0084572566097885, vert_correction: -0.16012465801089584, vert_offset_correction: 0.14418593} - {dist_correction: 1.2581644, dist_correction_x: 1.3149522, dist_correction_y: 1.2930194000000002, focal_distance: 0.25, focal_slope: 0.89999998, horiz_offset_correction: -0.025999999, laser_id: 61, rot_correction: 0.048843297425790605, vert_correction: -0.1511470421311337, vert_offset_correction: 0.14361434} - {dist_correction: 1.2993362, dist_correction_x: 1.3299077, dist_correction_y: 1.324184, focal_distance: 10.0, focal_slope: 0.80000001, horiz_offset_correction: 0.025999999, laser_id: 62, rot_correction: -0.030143852037228126, vert_correction: -0.21457119711920336, vert_offset_correction: 0.14769171} - {dist_correction: 1.3722379, dist_correction_x: 1.3900346, dist_correction_y: 1.4076549, focal_distance: 13.0, focal_slope: 0.40000001, horiz_offset_correction: -0.025999999, laser_id: 63, rot_correction: 0.02800567535054865, vert_correction: -0.20577295745331492, vert_offset_correction: 0.14712011} num_lasers: 64
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_params/velodyne64_novatel_extrinsics_example.yaml
child_frame_id: velodyne64 transform: rotation: x: 0.0178712428342356 y: -0.01105483165178439 z: 0.7086047865380262 w: 0.7052926101074 translation: x: -0.0008540722033043019 y: 1.410303305307884 z: 1.397 header: seq: 0 stamp: secs: 1502870042 nsecs: 0 frame_id: novatel
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/vehicle_params/vehicle_imu_extrinsics.yaml
transform: translation: x: 0.0 y: 0.0 z: 0.0 rotation: x: 0.0 y: 0.0 z: 0.0 w: 1.0
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/video_conf/video_left_fisheye.pb.txt
udp_port: 2000 frame_id: "video_left_fisheye" pixel_format: "yuyv" trigger_param: "f2ff" metric_error_code: 32 record:0 width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 3 fpga_dev_number: 0 camera_seq_number: 6 compress_conf { output_channel: "/apollo/sensor/camera/left_fisheye/video/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/video_conf/video_front_6mm.pb.txt
udp_port: 2004 frame_id: "video_front_6mm" pixel_format: "yuyv" trigger_param: "f2ff" metric_error_code: 18 record:0 width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 3 fpga_dev_number: 0 camera_seq_number: 3 compress_conf { output_channel: "/apollo/sensor/camera/front_6mm/video/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/video_conf/video_front_12mm.pb.txt
udp_port: 2003 frame_id: "video_front_12mm" pixel_format: "yuyv" trigger_param: "f2ff" metric_error_code: 17 record:0 width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 3 fpga_dev_number: 0 camera_seq_number: 2 compress_conf { output_channel: "/apollo/sensor/camera/front_12mm/video/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/video_conf/video_right_fisheye.pb.txt
udp_port: 2001 frame_id: "video_right_fisheye" pixel_format: "yuyv" trigger_param: "f2ff" metric_error_code: 33 record:0 width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 3 fpga_dev_number: 0 camera_seq_number: 7 compress_conf { output_channel: "/apollo/sensor/camera/right_fisheye/video/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/video_conf/video_rear_6mm.pb.txt
udp_port: 2002 frame_id: "video_rear_6mm" pixel_format: "yuyv" trigger_param: "f2ff" metric_error_code: 18 record:0 width: 1920 height: 1080 frame_rate: 20 monochrome: false brightness: -1 contrast: -1 saturation: -1 sharpness: -1 gain: -1 auto_focus: false focus: -1 auto_exposure: true exposure: 100 auto_white_balance: true white_balance: 4000 bytes_per_pixel: 3 fpga_dev_number: 0 camera_seq_number: 3 compress_conf { output_channel: "/apollo/sensor/camera/rear_6mm/video/compressed" image_pool_size: 100 }
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/radar_conf/radar_front_conf.pb.txt
can_conf { can_card_parameter { brand:HERMES_CAN type: PCI_CARD channel_id: CHANNEL_ID_ONE } enable_debug_mode: false enable_receiver_log: false } radar_conf { max_distance_valid: true sensor_id_valid: false radar_power_valid: false output_type_valid: true send_quality_valid: true send_ext_info_valid: true sort_index_valid: false store_in_nvm_valid: true ctrl_relay_valid: false rcs_threshold_valid: true max_distance: 250 sensor_id: 0 output_type: OUTPUT_TYPE_OBJECTS radar_power: 0 ctrl_relay: 0 send_ext_info: true send_quality: true sort_index: 0 store_in_nvm: 1 rcs_threshold: RCS_THRESHOLD_STANDARD # unit: nanoseconds, 20ms for 50Hz input_send_interval: 20000000 } radar_channel: "/apollo/sensor/radar/front"
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/radar_conf/radar_rear_conf.pb.txt
can_conf { can_card_parameter { brand:HERMES_CAN type: PCI_CARD channel_id: CHANNEL_ID_TWO } enable_debug_mode: false enable_receiver_log: false } radar_conf { max_distance_valid: true sensor_id_valid: false radar_power_valid: false output_type_valid: true send_quality_valid: true send_ext_info_valid: true sort_index_valid: false store_in_nvm_valid: true ctrl_relay_valid: false rcs_threshold_valid: true max_distance: 250 sensor_id: 0 output_type: OUTPUT_TYPE_OBJECTS radar_power: 0 ctrl_relay: 0 send_ext_info: true send_quality: true sort_index: 0 store_in_nvm: 1 rcs_threshold: RCS_THRESHOLD_STANDARD # unit: nanoseconds, 20ms for 50Hz input_send_interval: 20000000 } radar_channel: "/apollo/sensor/radar/rear"
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_conf/velodyne16_front_center_conf.pb.txt
frame_id: "velodyne16_front_center" scan_channel: "/apollo/sensor/lidar16/front/center/Scan" rpm: 600.0 model: VLP16 mode: STRONGEST prefix_angle: 18000 firing_data_port: 2370 positioning_data_port: 8310 use_sensor_sync: false max_range: 100.0 min_range: 0.9 use_gps_time: true calibration_online: false calibration_file: "/apollo/modules/drivers/velodyne/params/VLP16_calibration.yaml" organized: false convert_channel_name: "/apollo/sensor/lidar16/front/center/PointCloud2" use_poll_sync: true is_main_frame: false
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_conf/velodyne128_conf.pb.txt
frame_id: "velodyne128" scan_channel: "/apollo/sensor/lidar128/Scan" rpm: 600.0 model: VLS128 mode: STRONGEST prefix_angle: 18000 firing_data_port: 2368 positioning_data_port: 8308 use_sensor_sync: false max_range: 100.0 min_range: 0.9 use_gps_time: true calibration_online: false calibration_file: "/apollo/modules/drivers/velodyne/params/velodyne128_VLS_calibration.yaml" organized: false convert_channel_name: "/apollo/sensor/lidar128/PointCloud2" use_poll_sync: true is_main_frame: true
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_conf/velodyne16_fusion_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lidar16/fusion/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_conf/velodyne16_rear_left_conf.pb.txt
frame_id: "velodyne16_rear_left" scan_channel: "/apollo/sensor/lidar16/rear/left/Scan" rpm: 600.0 model: VLP16 mode: STRONGEST prefix_angle: 18000 firing_data_port: 2369 positioning_data_port: 8309 use_sensor_sync: false max_range: 100.0 min_range: 0.9 use_gps_time: true calibration_online: false calibration_file: "/apollo/modules/drivers/velodyne/params/VLP16_calibration.yaml" organized: false convert_channel_name: "/apollo/sensor/lidar16/rear/left/PointCloud2" use_poll_sync: true is_main_frame: false
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_conf/velodyne16_rear_right_conf.pb.txt
frame_id: "velodyne16_rear_right" scan_channel: "/apollo/sensor/lidar16/rear/right/Scan" rpm: 600.0 model: VLP16 mode: STRONGEST prefix_angle: 18000 firing_data_port: 2371 positioning_data_port: 8311 use_sensor_sync: false max_range: 100.0 min_range: 0.9 use_gps_time: true calibration_online: false calibration_file: "/apollo/modules/drivers/velodyne/params/VLP16_calibration.yaml" organized: false convert_channel_name: "/apollo/sensor/lidar16/rear/right/PointCloud2" use_poll_sync: true is_main_frame: false
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_conf/velodyne16_up_center_conf.pb.txt
frame_id: "velodyne16_front_center" scan_channel: "/apollo/sensor/lidar16/up/center/Scan" rpm: 600.0 model: VLP16 mode: STRONGEST prefix_angle: 18000 firing_data_port: 2372 positioning_data_port: 8312 use_sensor_sync: false max_range: 100.0 min_range: 0.9 use_gps_time: true calibration_online: false calibration_file: "/apollo/modules/drivers/velodyne/params/VLP16_calibration.yaml" organized: false convert_channel_name: "/apollo/sensor/lidar16/up/center/PointCloud2" use_poll_sync: true is_main_frame: false
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_conf/velodyne64_conf.pb.txt
frame_id: "velodyne64" scan_channel: "/apollo/sensor/lidar64/Scan" rpm: 600.0 model: HDL64E_S3D mode: STRONGEST prefix_angle: 18000 firing_data_port: 2368 use_sensor_sync: false max_range: 100.0 min_range: 0.9 use_gps_time: true calibration_online: true calibration_file: "/apollo/modules/drivers/velodyne/params/velodyne64_S3_calibration.yaml" organized: false convert_channel_name: "/apollo/sensor/velodyne64/PointCloud2" compensator_channel_name: "/apollo/sensor/velodyne64/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_conf/velodyne128_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lidar128/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/velodyne_conf/velodyne128_fusion_compensator.pb.txt
world_frame_id: "world" transform_query_timeout: 0.02 output_channel: "/apollo/sensor/lidar128/compensator/PointCloud2"
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_params/short_camera_extrinsics.yaml
header: stamp: secs: 0 nsecs: 0 seq: 0 frame_id: Velodyne64 child_frame_id: short_camera transform: translation: x: 0.9356324324557267 z: -0.5427650640523064 y: -0.2485193364771597 rotation: w: 0.5171207069875965 x: -0.4789595241079692 y: 0.5018481750475685 z: -0.5013305874094867
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_params/short_camera_intrinsics.yaml
header: seq: 0 stamp: secs: 0 nsecs: 0 frame_id: '' height: 1080 width: 1920 distortion_model: plumb_bob D: [-0.45662683, 0.2749429, 0.00274883, 0.00161324, -0.18475847] K: [2032.79246, 0.000000, 927.659048, 0.000000, 2034.56668, 485.900506, 0.000000, 0.000000, 1.000000] R: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] P: [1707.62097, 0.000000, 934.679858, 0.000000, 0.000000, 1713.51990, 484.207658, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000] binning_x: 0 binning_y: 0 roi: x_offset: 0 y_offset: 0 height: 0 width: 0 do_rectify: False
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_params/long_camera_extrinsics.yaml
header: seq: 0 stamp: secs: 0 nsecs: 0 frame_id: short_camera child_frame_id: long_camera transform: rotation: x: -0.005389246 y: 0.01850062 z: -0.000099768 w: 0.99981511 translation: x: 0.275 y: 0 z: 0
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_params/long_camera_intrinsics.yaml
header: seq: 0 stamp: secs: 0 nsecs: 0 frame_id: '' height: 1080 width: 1920 distortion_model: plumb_bob D: [0, 0, 0, 0, 0] K: [8347.37928, 0.0, 1089.36465, 0.0, 8457.68897, 507.338605, 0.0, 0.0, 1.0] R: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] P: [8346.81445, 0.0, 1089.21417, 0.0, 0.0, 8441.38086, 503.224501, 0.0, 0.0, 0.0, 1.0, 0.0] binning_x: 0 binning_y: 0 roi: x_offset: 0 y_offset: 0 height: 0 width: 0 do_rectify: False
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_params/front_camera_intrinsics.yaml
#MKZ header: seq: 0 stamp: secs: 0 nsecs: 0 frame_id: white_mkz_onsemi_obstacle height: 1080 width: 1920 distortion_model: plumb_bob D: [-0.54336, 0.26653, -0.00099, -0.00170, 0.00000] K: [2033.39968, 0.0, 929.01881, 0.0, 2046.55356, 572.81049, 0.0, 0.0, 1.0] R: [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0] P: [1729.4515380859375, 0.0, 997.0791139046996, 0.0, 0.0, 1926.0577392578125, 571.4609883012963, 0.0, 0.0, 0.0, 1.0, 0.0] binning_x: 0 binning_y: 0 roi: x_offset: 0 y_offset: 0 height: 0 width: 0 do_rectify: False
0
apollo_public_repos/apollo/modules/calibration/data/mkz_example
apollo_public_repos/apollo/modules/calibration/data/mkz_example/camera_params/front_camera_extrinsics.yaml
#MKZ header: seq: 0 stamp: secs: 0 nsecs: 0 frame_id: white_mkz child_frame_id: onsemi_obstacle transform: rotation: x: 0.4917522 y: -0.4917522 z: 0.5081139 w: -0.5081139 translation: x: 1.895 y: -0.235 z: 1.256 # when Z=0 is ground # z: 0.956 # when Z=0 is the rear wheel axle
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/udp_bridge_sender_component.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/bridge/udp_bridge_sender_component.h" #include "modules/bridge/common/bridge_proto_serialized_buf.h" #include "modules/bridge/common/macro.h" #include "modules/bridge/common/util.h" namespace apollo { namespace bridge { #define BRIDGE_IMPL(pb_msg) template class UDPBridgeSenderComponent<pb_msg> using apollo::bridge::UDPBridgeSenderRemoteInfo; using apollo::cyber::io::Session; using apollo::localization::LocalizationEstimate; template <typename T> bool UDPBridgeSenderComponent<T>::Init() { AINFO << "UDP bridge sender init, startin..."; apollo::bridge::UDPBridgeSenderRemoteInfo udp_bridge_remote; if (!this->GetProtoConfig(&udp_bridge_remote)) { AINFO << "load udp bridge component proto param failed"; return false; } remote_ip_ = udp_bridge_remote.remote_ip(); remote_port_ = udp_bridge_remote.remote_port(); proto_name_ = udp_bridge_remote.proto_name(); ADEBUG << "UDP Bridge remote ip is: " << remote_ip_; ADEBUG << "UDP Bridge remote port is: " << remote_port_; ADEBUG << "UDP Bridge for Proto is: " << proto_name_; return true; } template <typename T> bool UDPBridgeSenderComponent<T>::Proc(const std::shared_ptr<T> &pb_msg) { if (remote_port_ == 0 || remote_ip_.empty()) { AERROR << "remote info is invalid!"; return false; } if (pb_msg == nullptr) { AERROR << "proto msg is not ready!"; return false; } struct sockaddr_in server_addr; server_addr.sin_addr.s_addr = inet_addr(remote_ip_.c_str()); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(static_cast<uint16_t>(remote_port_)); int sock_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0); int res = connect(sock_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)); if (res < 0) { close(sock_fd); return false; } BridgeProtoSerializedBuf<T> proto_buf; proto_buf.Serialize(pb_msg, proto_name_); for (size_t j = 0; j < proto_buf.GetSerializedBufCount(); j++) { ssize_t nbytes = send(sock_fd, proto_buf.GetSerializedBuf(j), proto_buf.GetSerializedBufSize(j), 0); if (nbytes != static_cast<ssize_t>(proto_buf.GetSerializedBufSize(j))) { break; } } close(sock_fd); return true; } BRIDGE_IMPL(LocalizationEstimate); BRIDGE_IMPL(planning::ADCTrajectory); } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/udp_bridge_multi_receiver_component.h
/****************************************************************************** * Copyright 2018 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <netinet/in.h> #include <sys/socket.h> #include <cstdlib> #include <iostream> #include <memory> #include <string> #include <vector> #include "modules/bridge/proto/udp_bridge_remote_info.pb.h" #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "cyber/class_loader/class_loader.h" #include "cyber/component/component.h" #include "cyber/cyber.h" #include "cyber/init.h" #include "cyber/scheduler/scheduler_factory.h" #include "modules/bridge/common/bridge_gflags.h" #include "modules/bridge/common/bridge_header.h" #include "modules/bridge/common/bridge_proto_diserialized_buf.h" #include "modules/bridge/common/udp_listener.h" #include "modules/common/monitor_log/monitor_log_buffer.h" namespace apollo { namespace bridge { class UDPBridgeMultiReceiverComponent final : public cyber::Component<> { public: UDPBridgeMultiReceiverComponent(); ~UDPBridgeMultiReceiverComponent() = default; bool Init() override; std::string Name() const { return FLAGS_bridge_module_name; } std::shared_ptr<ProtoDiserializedBufBase> CreateBridgeProtoBuf( const BridgeHeader &header); bool IsProtoExist(const BridgeHeader &header); bool IsTimeout(double time_stamp); void MsgDispatcher(); bool InitSession(uint16_t port); bool MsgHandle(int fd); private: bool RemoveInvalidBuf(uint32_t msg_id, const std::string &msg_name); private: common::monitor::MonitorLogBuffer monitor_logger_buffer_; std::shared_ptr<UDPListener<UDPBridgeMultiReceiverComponent>> listener_ = std::make_shared<UDPListener<UDPBridgeMultiReceiverComponent>>(); unsigned int bind_port_ = 0; bool enable_timeout_ = true; std::mutex mutex_; std::vector<std::shared_ptr<ProtoDiserializedBufBase>> proto_list_; }; CYBER_REGISTER_COMPONENT(UDPBridgeMultiReceiverComponent) } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/udp_bridge_multi_receiver_component.cc
/****************************************************************************** * Copyright 2018 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/bridge/udp_bridge_multi_receiver_component.h" #include "cyber/time/clock.h" #include "modules/bridge/common/bridge_proto_diser_buf_factory.h" #include "modules/bridge/common/macro.h" #include "modules/bridge/common/util.h" namespace apollo { namespace bridge { UDPBridgeMultiReceiverComponent::UDPBridgeMultiReceiverComponent() : monitor_logger_buffer_(common::monitor::MonitorMessageItem::CONTROL) {} bool UDPBridgeMultiReceiverComponent::Init() { AINFO << "UDP bridge multi :receiver init, startin..."; apollo::bridge::UDPBridgeReceiverRemoteInfo udp_bridge_remote; if (!this->GetProtoConfig(&udp_bridge_remote)) { AINFO << "load udp bridge component proto param failed"; return false; } bind_port_ = udp_bridge_remote.bind_port(); enable_timeout_ = udp_bridge_remote.enable_timeout(); ADEBUG << "UDP Bridge remote port is: " << bind_port_; if (!InitSession((uint16_t)bind_port_)) { return false; } ADEBUG << "initialize session successful."; MsgDispatcher(); return true; } bool UDPBridgeMultiReceiverComponent::InitSession(uint16_t port) { return listener_->Initialize( this, &UDPBridgeMultiReceiverComponent::MsgHandle, port); } void UDPBridgeMultiReceiverComponent::MsgDispatcher() { ADEBUG << "msg dispatcher start successful."; listener_->Listen(); } std::shared_ptr<ProtoDiserializedBufBase> UDPBridgeMultiReceiverComponent::CreateBridgeProtoBuf( const BridgeHeader &header) { std::shared_ptr<ProtoDiserializedBufBase> proto_buf; if (IsTimeout(header.GetTimeStamp())) { std::vector<std::shared_ptr<ProtoDiserializedBufBase>>::iterator itor = proto_list_.begin(); for (; itor != proto_list_.end();) { if ((*itor)->IsTheProto(header)) { itor = proto_list_.erase(itor); break; } ++itor; } return proto_buf; } for (auto proto : proto_list_) { if (proto->IsTheProto(header)) { return proto; } } proto_buf = ProtoDiserializedBufBaseFactory::CreateObj(header); if (!proto_buf) { return proto_buf; } proto_buf->Initialize(header, node_); proto_list_.push_back(proto_buf); return proto_buf; } bool UDPBridgeMultiReceiverComponent::IsProtoExist(const BridgeHeader &header) { for (auto proto : proto_list_) { if (proto->IsTheProto(header)) { return true; } } return false; } bool UDPBridgeMultiReceiverComponent::IsTimeout(double time_stamp) { if (enable_timeout_ == false) { return false; } double cur_time = apollo::cyber::Clock::NowInSeconds(); if (cur_time < time_stamp) { return true; } if (FLAGS_timeout < cur_time - time_stamp) { return true; } return false; } bool UDPBridgeMultiReceiverComponent::MsgHandle(int fd) { struct sockaddr_in client_addr; socklen_t sock_len = static_cast<socklen_t>(sizeof(client_addr)); int total_recv = 2 * FRAME_SIZE; char total_buf[2 * FRAME_SIZE] = {0}; int bytes = static_cast<int>(recvfrom(fd, total_buf, total_recv, 0, (struct sockaddr *)&client_addr, &sock_len)); if (bytes <= 0 || bytes > total_recv) { return false; } if (strncmp(total_buf, BRIDGE_HEADER_FLAG, HEADER_FLAG_SIZE) != 0) { AERROR << "Header flag didn't match!"; return false; } size_t offset = HEADER_FLAG_SIZE + 1; const char *cursor = total_buf + offset; hsize header_size = *(reinterpret_cast<const hsize *>(cursor)); offset += sizeof(hsize) + 1; if (header_size < offset || header_size > FRAME_SIZE) { AERROR << "header size is more than FRAME_SIZE!"; return false; } cursor = total_buf + offset; size_t buf_size = header_size - offset; BridgeHeader header; if (!header.Diserialize(cursor, buf_size)) { AERROR << "header diserialize failed!"; return false; } ADEBUG << "proto name : " << header.GetMsgName().c_str(); ADEBUG << "proto sequence num: " << header.GetMsgID(); ADEBUG << "proto total frames: " << header.GetTotalFrames(); ADEBUG << "proto frame index: " << header.GetIndex(); std::lock_guard<std::mutex> lock(mutex_); std::shared_ptr<ProtoDiserializedBufBase> proto_buf = CreateBridgeProtoBuf(header); if (!proto_buf) { return false; } cursor = total_buf + header_size; char *buf = proto_buf->GetBuf(header.GetFramePos()); memcpy(buf, cursor, header.GetFrameSize()); proto_buf->UpdateStatus(header.GetIndex()); if (proto_buf->IsReadyDiserialize()) { proto_buf->DiserializedAndPub(); RemoveInvalidBuf(proto_buf->GetMsgID(), proto_buf->GetMsgName()); RemoveItem(&proto_list_, proto_buf); } return true; } bool UDPBridgeMultiReceiverComponent::RemoveInvalidBuf( uint32_t msg_id, const std::string &msg_name) { if (msg_id == 0) { return false; } std::vector<std::shared_ptr<ProtoDiserializedBufBase>>::iterator itor = proto_list_.begin(); for (; itor != proto_list_.end();) { if ((*itor)->GetMsgID() < msg_id && strcmp((*itor)->GetMsgName().c_str(), msg_name.c_str()) == 0) { itor = proto_list_.erase(itor); continue; } ++itor; } return true; } } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/cyberfile.xml
<package format="2"> <name>bridge</name> <version>local</version> <description> This module provides a way for other Apollo modules interactiving with process outside of Apollo by socket. It includes sender and receiver components. </description> <maintainer email="apollo-support@baidu.com">Apollo</maintainer> <license>Apache License 2.0</license> <url type="website">https://www.apollo.auto/</url> <url type="repository">https://github.com/ApolloAuto/apollo</url> <url type="bugtracker">https://github.com/ApolloAuto/apollo/issues</url> <type>module</type> <src_path url="https://github.com/ApolloAuto/apollo">//modules/bridge</src_path> <depend type="binary" repo_name="cyber">cyber-dev</depend> <depend type="binary" repo_name="common" lib_names="common">common-dev</depend> <depend repo_name="com_github_gflags_gflags" lib_names="gflags">3rd-gflags-dev</depend> <depend repo_name="com_google_googletest" lib_names="gtest,gtest_main">3rd-gtest-dev</depend> <depend repo_name="common-msgs" lib_names="common-msgs">common-msgs-dev</depend> <depend>3rd-mkl-dev</depend> <depend expose="False">3rd-rules-python-dev</depend> <depend expose="False">3rd-grpc-dev</depend> <depend expose="False">3rd-bazel-skylib-dev</depend> <depend expose="False">3rd-rules-proto-dev</depend> <depend expose="False">3rd-py-dev</depend> </package>
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/udp_bridge_sender_component.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <netinet/in.h> #include <sys/socket.h> #include <cstdlib> #include <iostream> #include <memory> #include <string> #include <vector> #include "modules/bridge/proto/udp_bridge_remote_info.pb.h" #include "modules/common_msgs/planning_msgs/planning.pb.h" #include "cyber/class_loader/class_loader.h" #include "cyber/component/component.h" #include "cyber/cyber.h" #include "cyber/init.h" #include "cyber/io/session.h" #include "cyber/scheduler/scheduler_factory.h" #include "modules/bridge/common/bridge_gflags.h" #include "modules/common/monitor_log/monitor_log_buffer.h" #include "modules/common/util/util.h" namespace apollo { namespace bridge { #define BRIDGE_COMPONENT_REGISTER(pb_msg) \ CYBER_REGISTER_COMPONENT(UDPBridgeSenderComponent<pb_msg>) template <typename T> class UDPBridgeSenderComponent final : public cyber::Component<T> { public: UDPBridgeSenderComponent() : monitor_logger_buffer_(common::monitor::MonitorMessageItem::CONTROL) {} bool Init() override; bool Proc(const std::shared_ptr<T> &pb_msg) override; std::string Name() const { return FLAGS_bridge_module_name; } private: common::monitor::MonitorLogBuffer monitor_logger_buffer_; unsigned int remote_port_ = 0; std::string remote_ip_ = ""; std::string proto_name_ = ""; std::mutex mutex_; }; BRIDGE_COMPONENT_REGISTER(planning::ADCTrajectory) BRIDGE_COMPONENT_REGISTER(localization::LocalizationEstimate) } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/bridge.BUILD
load("@rules_cc//cc:defs.bzl", "cc_library") cc_library( name = "bridge", includes = ["include"], hdrs = glob(["include/**/*.h"]), srcs = glob(["lib/**/*.so*"]), include_prefix = "modules/bridge", strip_include_prefix = "include", visibility = ["//visibility:public"], )
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/udp_bridge_component_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "gtest/gtest.h" #include "cyber/init.h" #include "modules/bridge/udp_bridge_sender_component.h" namespace apollo { namespace bridge { TEST(UDPBridgeSenderComponentTest, Simple) { cyber::Init("udp_bridge_component_test"); UDPBridgeSenderComponent<planning::ADCTrajectory> udp_bridge_component; EXPECT_EQ(udp_bridge_component.Name(), "Bridge"); } } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/README.md
# Bridge ## Introduction This module provides a way for other Apollo modules interactiving with process outside of Apollo by socket. It includes sender and receiver components. ## Input In sender component, there is only one input, which is the proto struct sender handled. In receiver comonent, its input is different with others. Its input comes from UDP socket. ## Output Sender's output is by way of UDP socket. Receiver has one output which is receiver handled. ## Launch The startup of Bridge is consistent with the startup of other modules. Bridge contains two sub-modules, other than: sender and receiver. The sender is responsible for sending the udp data, and the receiver is responsible for receiving the data packet sent by the udp client, and parsing it, and then sending it to the module that has registered to respond to the message. The start command of Sender is as follows. ``` $ cyber_launch start /apollo/modules/bridge/launch/bridge_receiver.launch ``` The start command of Receiver is as follows: ``` $ cyber_launch start /apollo/modules/bridge/launch/bridge_sender.launch ``` ## modify the configuration - Receiver listens to port 8900 by default, and can change the port number to be monitored by modifying its corresponding configuration file. The corresponding configuration file can be queried in the dag file, as shown in the following figure. ![](images/Picture1.png) Its configuration file: /Apollo/modules/bridge/conf/udp_bridge_receiver_chassis.pb.txt ![](images/Picture2.png) Note: If you want to receive data from the client outside the docker, you need to do port mapping with the -p parameter when starting docker, you need to modify the docker/scripts/dev_start.sh file, as shown below. ![](images/Picture3.png) Add a new line -p 8900:8900 after -d \. This allows you to map the internal and external ports of docker, and you can accept the data sent by the external client of docker. - The sender configuration file is searched in the same way as the receiver. The sender that sends the ADCTrajectory is sent to 127.0.0.1:8900 by default; the sender that sends the LocalizationEstimate is sent to 127.0.0.1:8901 by default. The above ip address and port number can be modified through the corresponding configuration file. The configuration file information is as shown below. ![](images/Picture4.png) ## Add new message To send/receive new messages via udp, you can add two lines of code to the corresponding file. If you want to add the message apollo::test::PbTest, as shown below. ![](images/Picture5.png) Add a new line after the 80th line of this file udp_bridge_receiver_component.h: ``` RECEIVER_BRIDGE_COMPONENT_REGISTER(test::PbTest) ``` Also add after 197 lines of udp_bridge_receiver_component.cc ``` BRIDGE_RECV_IMPL(test::PbTest) ``` ![](images/Picture6.png) The addition of Sender is consistent with the receiver. After the code is modified, save it, then add the corresponding configuration file, startup file, and dag file. Recompile the code and start it.
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/udp_bridge_receiver_component.cc
/****************************************************************************** * Copyright 2018 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/bridge/udp_bridge_receiver_component.h" #include "cyber/time/clock.h" #include "modules/bridge/common/macro.h" #include "modules/bridge/common/util.h" namespace apollo { namespace bridge { #define BRIDGE_RECV_IMPL(pb_msg) \ template class UDPBridgeReceiverComponent<pb_msg> template <typename T> UDPBridgeReceiverComponent<T>::UDPBridgeReceiverComponent() : monitor_logger_buffer_(common::monitor::MonitorMessageItem::CONTROL) {} template <typename T> UDPBridgeReceiverComponent<T>::~UDPBridgeReceiverComponent() { for (auto proto : proto_list_) { FREE_POINTER(proto); } } template <typename T> bool UDPBridgeReceiverComponent<T>::Init() { AINFO << "UDP bridge receiver init, startin..."; apollo::bridge::UDPBridgeReceiverRemoteInfo udp_bridge_remote; if (!this->GetProtoConfig(&udp_bridge_remote)) { AINFO << "load udp bridge component proto param failed"; return false; } bind_port_ = udp_bridge_remote.bind_port(); proto_name_ = udp_bridge_remote.proto_name(); topic_name_ = udp_bridge_remote.topic_name(); enable_timeout_ = udp_bridge_remote.enable_timeout(); ADEBUG << "UDP Bridge remote port is: " << bind_port_; ADEBUG << "UDP Bridge for Proto is: " << proto_name_; writer_ = node_->CreateWriter<T>(topic_name_.c_str()); if (!InitSession((uint16_t)bind_port_)) { return false; } ADEBUG << "initialize session successful."; MsgDispatcher(); return true; } template <typename T> bool UDPBridgeReceiverComponent<T>::InitSession(uint16_t port) { return listener_->Initialize(this, &UDPBridgeReceiverComponent<T>::MsgHandle, port); } template <typename T> void UDPBridgeReceiverComponent<T>::MsgDispatcher() { ADEBUG << "msg dispatcher start successful."; listener_->Listen(); } template <typename T> BridgeProtoDiserializedBuf<T> *UDPBridgeReceiverComponent<T>::CreateBridgeProtoBuf( const BridgeHeader &header) { if (IsTimeout(header.GetTimeStamp())) { typename std::vector<BridgeProtoDiserializedBuf<T> *>::iterator itor = proto_list_.begin(); for (; itor != proto_list_.end();) { if ((*itor)->IsTheProto(header)) { BridgeProtoDiserializedBuf<T> *tmp = *itor; FREE_POINTER(tmp); itor = proto_list_.erase(itor); break; } ++itor; } return nullptr; } for (auto proto : proto_list_) { if (proto->IsTheProto(header)) { return proto; } } BridgeProtoDiserializedBuf<T> *proto_buf = new BridgeProtoDiserializedBuf<T>; if (!proto_buf) { return nullptr; } proto_buf->Initialize(header); proto_list_.push_back(proto_buf); return proto_buf; } template <typename T> bool UDPBridgeReceiverComponent<T>::IsProtoExist(const BridgeHeader &header) { for (auto proto : proto_list_) { if (proto->IsTheProto(header)) { return true; } } return false; } template <typename T> bool UDPBridgeReceiverComponent<T>::IsTimeout(double time_stamp) { if (enable_timeout_ == false) { return false; } double cur_time = apollo::cyber::Clock::NowInSeconds(); if (cur_time < time_stamp) { return true; } if (FLAGS_timeout < cur_time - time_stamp) { return true; } return false; } template <typename T> bool UDPBridgeReceiverComponent<T>::MsgHandle(int fd) { struct sockaddr_in client_addr; socklen_t sock_len = static_cast<socklen_t>(sizeof(client_addr)); int bytes = 0; int total_recv = 2 * FRAME_SIZE; char total_buf[2 * FRAME_SIZE] = {0}; bytes = static_cast<int>(recvfrom(fd, total_buf, total_recv, 0, (struct sockaddr *)&client_addr, &sock_len)); ADEBUG << "total recv " << bytes; if (bytes <= 0 || bytes > total_recv) { return false; } char header_flag[sizeof(BRIDGE_HEADER_FLAG) + 1] = {0}; size_t offset = 0; memcpy(header_flag, total_buf, HEADER_FLAG_SIZE); if (strcmp(header_flag, BRIDGE_HEADER_FLAG) != 0) { AINFO << "header flag not match!"; return false; } offset += sizeof(BRIDGE_HEADER_FLAG) + 1; char header_size_buf[sizeof(hsize) + 1] = {0}; const char *cursor = total_buf + offset; memcpy(header_size_buf, cursor, sizeof(hsize)); hsize header_size = *(reinterpret_cast<hsize *>(header_size_buf)); if (header_size > FRAME_SIZE) { AINFO << "header size is more than FRAME_SIZE!"; return false; } offset += sizeof(hsize) + 1; BridgeHeader header; size_t buf_size = header_size - offset; cursor = total_buf + offset; if (!header.Diserialize(cursor, buf_size)) { AINFO << "header diserialize failed!"; return false; } ADEBUG << "proto name : " << header.GetMsgName().c_str(); ADEBUG << "proto sequence num: " << header.GetMsgID(); ADEBUG << "proto total frames: " << header.GetTotalFrames(); ADEBUG << "proto frame index: " << header.GetIndex(); std::lock_guard<std::mutex> lock(mutex_); BridgeProtoDiserializedBuf<T> *proto_buf = CreateBridgeProtoBuf(header); if (!proto_buf) { return false; } cursor = total_buf + header_size; char *buf = proto_buf->GetBuf(header.GetFramePos()); memcpy(buf, cursor, header.GetFrameSize()); proto_buf->UpdateStatus(header.GetIndex()); if (proto_buf->IsReadyDiserialize()) { auto pb_msg = std::make_shared<T>(); proto_buf->Diserialized(pb_msg); writer_->Write(pb_msg); RemoveInvalidBuf(proto_buf->GetMsgID()); RemoveItem(&proto_list_, proto_buf); } return true; } template <typename T> bool UDPBridgeReceiverComponent<T>::RemoveInvalidBuf(uint32_t msg_id) { if (msg_id == 0) { return false; } typename std::vector<BridgeProtoDiserializedBuf<T> *>::iterator itor = proto_list_.begin(); for (; itor != proto_list_.end();) { if ((*itor)->GetMsgID() < msg_id) { BridgeProtoDiserializedBuf<T> *tmp = *itor; FREE_POINTER(tmp); itor = proto_list_.erase(itor); continue; } ++itor; } return true; } BRIDGE_RECV_IMPL(canbus::Chassis); } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/udp_bridge_receiver_component.h
/****************************************************************************** * Copyright 2018 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <netinet/in.h> #include <sys/socket.h> #include <cstdlib> #include <iostream> #include <memory> #include <string> #include <vector> #include "modules/bridge/proto/udp_bridge_remote_info.pb.h" #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "cyber/class_loader/class_loader.h" #include "cyber/component/component.h" #include "cyber/cyber.h" #include "cyber/init.h" #include "cyber/scheduler/scheduler_factory.h" #include "modules/bridge/common/bridge_gflags.h" #include "modules/bridge/common/bridge_header.h" #include "modules/bridge/common/bridge_proto_diserialized_buf.h" #include "modules/bridge/common/udp_listener.h" #include "modules/common/monitor_log/monitor_log_buffer.h" namespace apollo { namespace bridge { #define RECEIVER_BRIDGE_COMPONENT_REGISTER(pb_msg) \ CYBER_REGISTER_COMPONENT(UDPBridgeReceiverComponent<pb_msg>) template <typename T> class UDPBridgeReceiverComponent final : public cyber::Component<> { public: UDPBridgeReceiverComponent(); ~UDPBridgeReceiverComponent(); bool Init() override; std::string Name() const { return FLAGS_bridge_module_name; } bool MsgHandle(int fd); private: bool InitSession(uint16_t port); void MsgDispatcher(); bool IsProtoExist(const BridgeHeader &header); BridgeProtoDiserializedBuf<T> *CreateBridgeProtoBuf( const BridgeHeader &header); bool IsTimeout(double time_stamp); bool RemoveInvalidBuf(uint32_t msg_id); private: common::monitor::MonitorLogBuffer monitor_logger_buffer_; unsigned int bind_port_ = 0; std::string proto_name_ = ""; std::string topic_name_ = ""; bool enable_timeout_ = true; std::shared_ptr<cyber::Writer<T>> writer_; std::mutex mutex_; std::shared_ptr<UDPListener<UDPBridgeReceiverComponent<T>>> listener_ = std::make_shared<UDPListener<UDPBridgeReceiverComponent<T>>>(); std::vector<BridgeProtoDiserializedBuf<T> *> proto_list_; }; RECEIVER_BRIDGE_COMPONENT_REGISTER(canbus::Chassis) } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/bridge/BUILD
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") load("//tools/install:install.bzl", "install", "install_files", "install_src_files") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) BRIDGE_COPTS = ['-DMODULE_NAME=\\"bridge\\"'] filegroup( name = "runtime_data", srcs = glob([ "conf/*.txt", "dag/*.dag", "launch/*.launch", ]), ) install( name = "install", library_dest = "bridge/lib", data_dest = "bridge", data = [ ":runtime_data", "cyberfile.xml", "bridge.BUILD" ], targets = [ ":libudp_bridge_sender_component.so", ":libudp_bridge_receiver_component.so", ":libudp_bridge_multi_receiver_component.so", ], deps = [ "//modules/bridge/test:install", "//modules/bridge/proto:py_pb_bridge", "//modules/bridge/common:install", ], ) install( name = "pb_hdrs", data_dest = "bridge/include", data = [ "//modules/bridge/proto:udp_bridge_remote_info_cc_proto", ], ) cc_library( name = "udp_bridge", copts = BRIDGE_COPTS, deps = [ "//cyber", "//modules/bridge/common:bridge_gflags", "//modules/bridge/common:bridge_header", "//modules/bridge/common:bridge_proto_diser_buf_factory", "//modules/bridge/common:bridge_proto_diserialized_buf", "//modules/bridge/common:bridge_proto_serialized_buf", "//modules/bridge/common:macro", "//modules/bridge/common:util", "//modules/bridge/proto:udp_bridge_remote_info_cc_proto", "//modules/common_msgs/chassis_msgs:chassis_cc_proto", "//modules/common_msgs/planning_msgs:planning_cc_proto", "//modules/common/monitor_log", "//modules/common/util", ], ) cc_library( name = "udp_bridge_sender", srcs = ["udp_bridge_sender_component.cc"], hdrs = ["udp_bridge_sender_component.h"], copts = BRIDGE_COPTS, alwayslink = True, deps = [ ":udp_bridge", ], ) cc_library( name = "udp_bridge_receiver", srcs = ["udp_bridge_receiver_component.cc"], hdrs = ["udp_bridge_receiver_component.h"], copts = BRIDGE_COPTS, alwayslink = True, deps = [ ":udp_bridge", "//modules/bridge/common:udp_listener", ], ) cc_library( name = "udp_bridge_multi_receiver", srcs = ["udp_bridge_multi_receiver_component.cc"], hdrs = ["udp_bridge_multi_receiver_component.h"], copts = BRIDGE_COPTS, alwayslink = True, deps = [ ":udp_bridge", "//modules/bridge/common:udp_listener", ], ) cc_binary( name = "libudp_bridge_sender_component.so", linkshared = True, linkstatic = True, deps = [":udp_bridge_sender"], ) cc_binary( name = "libudp_bridge_receiver_component.so", linkshared = True, linkstatic = True, deps = [":udp_bridge_receiver"], ) cc_binary( name = "libudp_bridge_multi_receiver_component.so", linkshared = True, linkstatic = True, deps = [":udp_bridge_multi_receiver"], ) cc_test( name = "udp_bridge_component_test", size = "small", srcs = ["udp_bridge_component_test.cc"], deps = [ ":udp_bridge_sender", "@com_google_googletest//:gtest_main", ], linkstatic = True, ) install_src_files( name = "install_src", deps = [ ":install_bridge_src", ":install_bridge_hdrs" ], ) install_src_files( name = "install_bridge_src", src_dir = ["."], dest = "bridge/src", filter = "*", ) install_src_files( name = "install_bridge_hdrs", src_dir = ["."], dest = "bridge/include", filter = "*.h", ) cpplint()
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/proto/udp_bridge_remote_info.proto
syntax = "proto2"; package apollo.bridge; message UDPBridgeSenderRemoteInfo { optional string remote_ip = 1 [default = "127.0.0.1"]; optional int32 remote_port = 2 [default = 8900]; optional string proto_name = 3 [default = "ProtoMsgName"]; } message UDPBridgeReceiverRemoteInfo { optional string topic_name = 1 [default = ""]; optional int32 bind_port = 2 [default = 8500]; optional string proto_name = 3 [default = "ProtoMsgName"]; optional bool enable_timeout = 4 [default = true]; }
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/proto/BUILD
## Auto generated by `proto_build_generator.py` load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("//tools:python_rules.bzl", "py_proto_library") load("//tools/install:install.bzl", "install", "install_files") package(default_visibility = ["//visibility:public"]) cc_proto_library( name = "udp_bridge_remote_info_cc_proto", deps = [ ":udp_bridge_remote_info_proto", ], ) proto_library( name = "udp_bridge_remote_info_proto", srcs = ["udp_bridge_remote_info.proto"], ) py_proto_library( name = "udp_bridge_remote_info_py_pb2", deps = [ ":udp_bridge_remote_info_proto", ], ) install_files( name = "py_pb_bridge", dest = "bridge/python/modules/bridge/proto", files = [ "udp_bridge_remote_info_py_pb2", ] )
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/test/bridge_sender_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include <arpa/inet.h> #include <netinet/in.h> #include <sys/socket.h> #include <unistd.h> #include <cstdlib> #include <thread> #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "cyber/common/log.h" #include "cyber/scheduler/scheduler_factory.h" #include "cyber/time/clock.h" #include "modules/bridge/common/bridge_proto_serialized_buf.h" using apollo::cyber::Clock; bool send(const std::string &remote_ip, uint16_t remote_port, uint32_t count) { if (count == 0) { count = 10000; } float total = static_cast<float>(count); float hundred = 100.00; for (uint32_t i = 0; i < count; i++) { double timestamp_ = Clock::NowInSeconds() + 2.0; float coefficient = static_cast<float>(i); auto pb_msg = std::make_shared<apollo::canbus::Chassis>(); pb_msg->mutable_header()->set_sequence_num(i); pb_msg->mutable_header()->set_timestamp_sec(timestamp_); pb_msg->set_engine_started(true); pb_msg->set_engine_rpm(static_cast<float>(coefficient * 2.0)); pb_msg->set_odometer_m(coefficient); pb_msg->set_fuel_range_m(100); pb_msg->set_throttle_percentage(coefficient * hundred / total); pb_msg->set_brake_percentage(coefficient * hundred / total); pb_msg->set_steering_percentage(coefficient * hundred / total); pb_msg->set_steering_torque_nm(coefficient); pb_msg->set_parking_brake(i % 2); pb_msg->set_high_beam_signal(false); pb_msg->set_low_beam_signal(true); pb_msg->set_left_turn_signal(false); pb_msg->set_right_turn_signal(false); pb_msg->set_horn(false); pb_msg->set_wiper(false); pb_msg->set_disengage_status(false); pb_msg->set_driving_mode(apollo::canbus::Chassis::COMPLETE_MANUAL); pb_msg->set_error_code(apollo::canbus::Chassis::NO_ERROR); pb_msg->set_gear_location(apollo::canbus::Chassis::GEAR_NEUTRAL); struct sockaddr_in server_addr; server_addr.sin_addr.s_addr = inet_addr(remote_ip.c_str()); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(remote_port); ADEBUG << "connecting to server... "; int sock_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0); int res = connect(sock_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)); if (res < 0) { ADEBUG << "connected server failed "; continue; } ADEBUG << "connected to server success. port [" << remote_port << "]"; apollo::bridge::BridgeProtoSerializedBuf<apollo::canbus::Chassis> proto_buf; proto_buf.Serialize(pb_msg, "Chassis"); for (size_t j = 0; j < proto_buf.GetSerializedBufCount(); j++) { ssize_t nbytes = send(sock_fd, proto_buf.GetSerializedBuf(j), proto_buf.GetSerializedBufSize(j), 0); if (nbytes != static_cast<ssize_t>(proto_buf.GetSerializedBufSize(j))) { ADEBUG << "sent msg failed "; break; } ADEBUG << "sent " << nbytes << " bytes to server with sequence num " << i; } close(sock_fd); // 1000Hz std::this_thread::sleep_for(std::chrono::milliseconds(1)); } return true; } int main(int argc, char *argv[]) { uint32_t count = 0; if (argc < 2) { count = 10000; } else { count = atoi(argv[1]); CHECK_LE(count, 20000U); } send("127.0.0.1", 8900, count); return 0; }
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/test/BUILD
load("@rules_cc//cc:defs.bzl", "cc_binary") load("//tools:cpplint.bzl", "cpplint") load("//tools/install:install.bzl", "install") package(default_visibility = ["//visibility:public"]) install( name = "install", runtime_dest = "bridge/bin", targets = [ ":bridge_receiver_test", ":bridge_sender_test", ], visibility = ["//visibility:public"], ) cc_binary( name = "bridge_receiver_test", srcs = ["bridge_receiver_test.cc"], deps = [ "//cyber", "//modules/bridge:udp_bridge", "//modules/bridge/common:udp_listener", ], ) cc_binary( name = "bridge_sender_test", srcs = ["bridge_sender_test.cc"], deps = [ "//cyber", "//modules/bridge:udp_bridge", ], ) cpplint()
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/test/bridge_receiver_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include <arpa/inet.h> #include <fcntl.h> #include <netinet/in.h> #include <pthread.h> #include <sys/epoll.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <cstdlib> #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "cyber/common/log.h" #include "modules/bridge/common/bridge_proto_diserialized_buf.h" #include "modules/bridge/common/macro.h" #include "modules/bridge/common/udp_listener.h" #include "modules/bridge/common/util.h" using apollo::bridge::BRIDGE_HEADER_FLAG; using apollo::bridge::BridgeHeader; using apollo::bridge::FRAME_SIZE; using apollo::bridge::HEADER_FLAG_SIZE; using apollo::bridge::hsize; using apollo::bridge::MAXEPOLLSIZE; using apollo::canbus::Chassis; using BPDBChassis = apollo::bridge::BridgeProtoDiserializedBuf<Chassis>; void *pthread_handle_message(void *pfd) { struct sockaddr_in client_addr; socklen_t sock_len = static_cast<socklen_t>(sizeof(client_addr)); int bytes = 0; int total_recv = 2 * FRAME_SIZE; char total_buf[2 * FRAME_SIZE] = {0}; bytes = static_cast<int>(recvfrom(*static_cast<int *>(pfd), total_buf, total_recv, 0, (struct sockaddr *)&client_addr, &sock_len)); ADEBUG << "total recv " << bytes; if (bytes <= 0 || bytes > total_recv) { pthread_exit(nullptr); } char header_flag[sizeof(BRIDGE_HEADER_FLAG) + 1] = {0}; size_t offset = 0; memcpy(header_flag, total_buf, HEADER_FLAG_SIZE); if (strcmp(header_flag, BRIDGE_HEADER_FLAG) != 0) { ADEBUG << "header flag not match!"; pthread_exit(nullptr); } offset += sizeof(BRIDGE_HEADER_FLAG) + 1; char header_size_buf[sizeof(hsize) + 1] = {0}; const char *cursor = total_buf + offset; memcpy(header_size_buf, cursor, sizeof(hsize)); hsize header_size = *(reinterpret_cast<hsize *>(header_size_buf)); if (header_size > FRAME_SIZE) { ADEBUG << "header size is more than FRAME_SIZE!"; pthread_exit(nullptr); } offset += sizeof(hsize) + 1; BridgeHeader header; size_t buf_size = header_size - offset; cursor = total_buf + offset; if (!header.Diserialize(cursor, buf_size)) { ADEBUG << "header diserialize failed!"; pthread_exit(nullptr); } ADEBUG << "proto name : " << header.GetMsgName().c_str(); ADEBUG << "proto sequence num: " << header.GetMsgID(); ADEBUG << "proto total frames: " << header.GetTotalFrames(); ADEBUG << "proto frame index: " << header.GetIndex(); BPDBChassis *proto_buf = new BPDBChassis(); proto_buf->Initialize(header); if (!proto_buf) { pthread_exit(nullptr); } cursor = total_buf + header_size; char *buf = proto_buf->GetBuf(header.GetFramePos()); memcpy(buf, cursor, header.GetFrameSize()); proto_buf->UpdateStatus(header.GetIndex()); if (proto_buf->IsReadyDiserialize()) { auto pb_msg = std::make_shared<Chassis>(); proto_buf->Diserialized(pb_msg); ADEBUG << "sequence num: " << pb_msg->header().sequence_num(); ADEBUG << "timestamp sec: " << pb_msg->header().timestamp_sec(); ADEBUG << "engine rpm: " << pb_msg->engine_rpm(); ADEBUG << "odometer m: " << pb_msg->odometer_m(); ADEBUG << "throttle percentage: " << pb_msg->throttle_percentage(); ADEBUG << "brake percentage: " << pb_msg->brake_percentage(); ADEBUG << "steering percentage: " << pb_msg->steering_percentage(); ADEBUG << "steering torque nm: " << pb_msg->steering_torque_nm(); ADEBUG << "parking brake: " << pb_msg->parking_brake(); } pthread_exit(nullptr); } bool receive(uint16_t port) { struct rlimit rt; rt.rlim_max = rt.rlim_cur = MAXEPOLLSIZE; if (setrlimit(RLIMIT_NOFILE, &rt) == -1) { ADEBUG << "set resource limitation failed"; return false; } int listener_sock = socket(AF_INET, SOCK_DGRAM, 0); if (listener_sock == -1) { ADEBUG << "create socket failed"; return false; } int opt = SO_REUSEADDR; setsockopt(listener_sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); if (fcntl(listener_sock, F_SETFL, fcntl(listener_sock, F_GETFD, 0) | O_NONBLOCK) == -1) { ADEBUG << "set nonblocking failed"; return false; } struct sockaddr_in serv_addr; serv_addr.sin_family = PF_INET; serv_addr.sin_port = htons((uint16_t)port); serv_addr.sin_addr.s_addr = INADDR_ANY; if (bind(listener_sock, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1) { close(listener_sock); ADEBUG << "bind socket failed"; return false; } int kdpfd = epoll_create(MAXEPOLLSIZE); struct epoll_event ev; ev.events = EPOLLIN | EPOLLET; ev.data.fd = listener_sock; if (epoll_ctl(kdpfd, EPOLL_CTL_ADD, listener_sock, &ev) < 0) { ADEBUG << "set control interface for an epoll descriptor failed"; close(listener_sock); return false; } ADEBUG << "Ready!"; int nfds = -1; bool res = true; struct epoll_event events[MAXEPOLLSIZE]; while (true) { nfds = epoll_wait(kdpfd, events, 10000, -1); if (nfds == -1) { ADEBUG << "some error occurs while waiting for I/O event"; res = false; break; } for (int i = 0; i < nfds; ++i) { if (events[i].data.fd == listener_sock) { pthread_t thread; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if (pthread_create(&thread, &attr, &pthread_handle_message, reinterpret_cast<void *>(&events[i].data.fd))) { ADEBUG << "message handler creation failed"; res = false; break; } } } if (!res) { break; } } close(listener_sock); return res; } int main(int argc, char *argv[]) { receive(8900); return 0; }
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/launch/bridge_receiver.launch
<cyber> <module> <name>bridge_receiver</name> <dag_conf>/apollo/modules/bridge/dag/bridge_receiver.dag</dag_conf> <process_name>udp_bridge_receiver</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/launch/bridge_multi_receiver.launch
<cyber> <module> <name>bridge_multi_receiver</name> <dag_conf>/apollo/modules/bridge/dag/bridge_multi_receiver.dag</dag_conf> <process_name>udp_bridge_multi_receiver</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/launch/bridge_sender.launch
<cyber> <module> <name>bridge_sender</name> <dag_conf>/apollo/modules/bridge/dag/bridge_sender.dag</dag_conf> <process_name>udp_bridge_sender</process_name> </module> </cyber>
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/dag/bridge_receiver.dag
module_config { module_library: "/apollo/bazel-bin/modules/bridge/libudp_bridge_receiver_component.so" components { class_name: "UDPBridgeReceiverComponent<canbus::Chassis>" config { name: "bridge_receiver_Chassis" config_file_path: "/apollo/modules/bridge/conf/udp_bridge_receiver_chassis.pb.txt" } } }
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/dag/bridge_multi_receiver.dag
module_config { module_library: "/apollo/bazel-bin/modules/bridge/libudp_bridge_multi_receiver_component.so" components { class_name: "UDPBridgeMultiReceiverComponent" config { name: "bridge_receiver_Chassis" config_file_path: "/apollo/modules/bridge/conf/udp_bridge_receiver_chassis.pb.txt" } } }
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/dag/bridge_sender.dag
module_config { module_library: "/apollo/bazel-bin/modules/bridge/libudp_bridge_sender_component.so" components { class_name: "UDPBridgeSenderComponent<planning::ADCTrajectory>" config { name: "bridge_sender_ADCTrajectory" config_file_path: "/apollo/modules/bridge/conf/udp_bridge_sender_adctrajectory.pb.txt" readers { channel: "/apollo/planning" } } } components { class_name: "UDPBridgeSenderComponent<localization::LocalizationEstimate>" config { name: "bridge_sender_LocalizationEstimate" config_file_path: "/apollo/modules/bridge/conf/udp_bridge_sender_localization.pb.txt" readers { channel: "/apollo/localization/pose" } } } }
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_header_item.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <string> namespace apollo { namespace bridge { typedef uint32_t bsize; enum HType { Header_Ver, Msg_Name, Msg_ID, Msg_Size, Msg_Frames, Frame_Size, Frame_Pos, Frame_Index, Time_Stamp, Header_Tail, }; class HeaderItemBase { public: HeaderItemBase() = default; virtual ~HeaderItemBase() {} public: virtual char *SerializeItem(char *buf, size_t buf_size) = 0; virtual const char *DiserializeItem(const char *buf, const size_t buf_size, size_t *diserialized_size) = 0; virtual HType GetType() const = 0; }; template <enum HType t, typename T> struct HeaderItem; template <enum HType t, typename T> char *SerializeItemImp(const HeaderItem<t, T> &item, char *buf, size_t buf_size) { if (!buf || buf_size == 0 || buf_size < size_t(sizeof(t) + sizeof(bsize) + item.ValueSize() + 3)) { return nullptr; } char *res = buf; // item.ValueSize() get the size of T type data, // the maximum of which is proto_name // when transfer data, bsize can save sizeof(proto_name). // The type needs to be kept consistent during serialize and diserialize. bsize item_size = static_cast<bsize>(item.ValueSize()); HType type = t; memcpy(res, &type, sizeof(HType)); res[sizeof(HType)] = ':'; res = res + sizeof(HType) + 1; memcpy(res, &item_size, sizeof(bsize)); res[sizeof(bsize)] = ':'; res = res + sizeof(bsize) + 1; memcpy(res, item.GetValuePtr(), item.ValueSize()); res[item.ValueSize()] = '\n'; res += item.ValueSize() + 1; return res; } template <enum HType t, typename T> const char *DiserializeItemImp(HeaderItem<t, T> *item, const char *buf, const size_t buf_size, size_t *diserialized_size) { if (!buf || !diserialized_size || buf_size < size_t(sizeof(HType) + sizeof(bsize) + 2)) { return nullptr; } const char *res = buf; char p_type[sizeof(HType)] = {0}; memcpy(p_type, buf, sizeof(HType)); HType type = *(reinterpret_cast<HType *>(p_type)); if (type != t) { return nullptr; } res += sizeof(HType) + 1; *diserialized_size += sizeof(HType) + 1; char p_size[sizeof(bsize)] = {0}; memcpy(p_size, res, sizeof(bsize)); bsize size = *(reinterpret_cast<bsize *>(p_size)); res += sizeof(bsize) + 1; *diserialized_size += sizeof(bsize) + 1; if (buf_size < size_t(sizeof(HType) + sizeof(bsize) + size + 3)) { return nullptr; } item->SetValue(res); res += size + 1; *diserialized_size += size + 1; return res; } template <enum HType t, typename T> struct HeaderItem : public HeaderItemBase { T value_; operator T() { return value_; } HeaderItem &operator=(const T &val) { value_ = val; return *this; } HType GetType() const override { return t; } size_t ValueSize() const { return sizeof(value_); } const T *GetValuePtr() const { return &value_; } void SetValue(const char *buf) { if (!buf) { return; } value_ = *(reinterpret_cast<const T *>(buf)); } char *SerializeItem(char *buf, size_t buf_size) override { return SerializeItemImp(*this, buf, buf_size); } const char *DiserializeItem(const char *buf, size_t buf_size, size_t *diserialized_size) override { return DiserializeItemImp(this, buf, buf_size, diserialized_size); } }; template <enum HType t> struct HeaderItem<t, std::string> : public HeaderItemBase { std::string value_; operator std::string() { return value_; } HeaderItem &operator=(const std::string &val) { value_ = val; return *this; } size_t ValueSize() const { return value_.length() + 1; } HType GetType() const override { return t; } const char *GetValuePtr() const { return value_.c_str(); } void SetValue(const char *buf) { if (!buf) { return; } value_ = std::string(buf); } char *SerializeItem(char *buf, size_t buf_size) override { return SerializeItemImp(*this, buf, buf_size); } const char *DiserializeItem(const char *buf, size_t buf_size, size_t *diserialized_size) override { return DiserializeItemImp(this, buf, buf_size, diserialized_size); } }; } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_proto_diserialized_buf.h
/******************************************************************************der * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <memory> #include <string> #include <vector> #include "cyber/cyber.h" #include "modules/bridge/common/bridge_header.h" #include "modules/bridge/common/macro.h" namespace apollo { namespace bridge { constexpr uint32_t INT_BITS = static_cast<uint32_t>(sizeof(uint32_t) * 8); class ProtoDiserializedBufBase { public: ProtoDiserializedBufBase() {} virtual ~ProtoDiserializedBufBase() {} virtual bool Initialize(const BridgeHeader &header, std::shared_ptr<cyber::Node> node) = 0; virtual bool DiserializedAndPub() = 0; virtual bool IsReadyDiserialize() const = 0; virtual bool IsTheProto(const BridgeHeader &header) = 0; virtual void UpdateStatus(uint32_t frame_index) = 0; virtual uint32_t GetMsgID() const = 0; virtual std::string GetMsgName() const = 0; virtual char *GetBuf(size_t offset) = 0; }; template <typename T> class BridgeProtoDiserializedBuf : public ProtoDiserializedBufBase { public: BridgeProtoDiserializedBuf() {} explicit BridgeProtoDiserializedBuf(const std::string &topic_name) : topic_name_(topic_name) {} virtual ~BridgeProtoDiserializedBuf(); virtual bool DiserializedAndPub(); virtual bool Initialize(const BridgeHeader &header, std::shared_ptr<cyber::Node> node); virtual bool IsReadyDiserialize() const { return is_ready_diser; } virtual void UpdateStatus(uint32_t frame_index); virtual bool IsTheProto(const BridgeHeader &header); bool Initialize(const BridgeHeader &header); bool Diserialized(std::shared_ptr<T> proto); virtual char *GetBuf(size_t offset) { return proto_buf_ + offset; } virtual uint32_t GetMsgID() const { return sequence_num_; } virtual std::string GetMsgName() const { return proto_name_; } private: size_t total_frames_ = 0; size_t total_size_ = 0; std::string proto_name_ = ""; std::vector<uint32_t> status_list_; char *proto_buf_ = nullptr; bool is_ready_diser = false; uint32_t sequence_num_ = 0; std::shared_ptr<cyber::Writer<T>> writer_; std::string topic_name_ = ""; }; template <typename T> BridgeProtoDiserializedBuf<T>::~BridgeProtoDiserializedBuf() { FREE_ARRY(proto_buf_); } template <typename T> bool BridgeProtoDiserializedBuf<T>::Diserialized(std::shared_ptr<T> proto) { if (!proto_buf_ || !proto) { return false; } proto->ParseFromArray(proto_buf_, static_cast<int>(total_size_)); return true; } template <typename T> void BridgeProtoDiserializedBuf<T>::UpdateStatus(uint32_t frame_index) { size_t status_size = status_list_.size(); if (status_size == 0) { is_ready_diser = false; return; } uint32_t status_index = frame_index / INT_BITS; status_list_[status_index] |= (1 << (frame_index % INT_BITS)); for (size_t i = 0; i < status_size; i++) { if (i == status_size - 1) { if (static_cast<int>(status_list_[i]) == (1 << total_frames_ % INT_BITS) - 1) { AINFO << "diserialized is ready"; is_ready_diser = true; } else { is_ready_diser = false; break; } } else { if (status_list_[i] != 0xffffffff) { is_ready_diser = false; break; } is_ready_diser = true; } } } template <typename T> bool BridgeProtoDiserializedBuf<T>::IsTheProto(const BridgeHeader &header) { if (strcmp(proto_name_.c_str(), header.GetMsgName().c_str()) == 0 && sequence_num_ == header.GetMsgID()) { return true; } return false; } template <typename T> bool BridgeProtoDiserializedBuf<T>::Initialize(const BridgeHeader &header) { total_size_ = header.GetMsgSize(); total_frames_ = header.GetTotalFrames(); proto_name_ = header.GetMsgName(); sequence_num_ = header.GetMsgID(); if (total_frames_ == 0) { return false; } int status_size = static_cast<int>(total_frames_ / INT_BITS + ((total_frames_ % INT_BITS) ? 1 : 0)); if (status_list_.empty()) { for (int i = 0; i < status_size; i++) { status_list_.push_back(0); } } if (!proto_buf_) { proto_buf_ = new char[total_size_]; } return true; } template <typename T> bool BridgeProtoDiserializedBuf<T>::Initialize( const BridgeHeader &header, std::shared_ptr<cyber::Node> node) { writer_ = node->CreateWriter<T>(topic_name_.c_str()); return Initialize(header); } template <typename T> bool BridgeProtoDiserializedBuf<T>::DiserializedAndPub() { auto pb_msg = std::make_shared<T>(); if (!Diserialized(pb_msg)) { return false; } writer_->Write(pb_msg); return true; } } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_buffer.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <mutex> namespace apollo { namespace bridge { template <typename T> class BridgeBuffer { public: BridgeBuffer(); explicit BridgeBuffer(size_t size); virtual ~BridgeBuffer(); operator T *(); void reset(size_t size); size_t size() const { return size_; } size_t capacity() const { return capacity_; } void write(size_t index, const T *data, size_t size); private: T *buf_ = nullptr; size_t size_ = 0; size_t capacity_ = 0; std::mutex mutex_; BridgeBuffer(const BridgeBuffer &) = delete; BridgeBuffer &operator=(const BridgeBuffer &) = delete; }; } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_proto_buf_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "gtest/gtest.h" #include "modules/common_msgs/planning_msgs/planning.pb.h" #include "cyber/init.h" #include "modules/bridge/common/bridge_proto_diserialized_buf.h" #include "modules/bridge/common/bridge_proto_serialized_buf.h" namespace apollo { namespace bridge { TEST(BridgeProtoBufTest, Simple) { cyber::Init("bridge_proto_buf_test"); BridgeProtoSerializedBuf<planning::ADCTrajectory> proto_buf; auto adc_trajectory = std::make_shared<planning::ADCTrajectory>(); double x = 1.0; double y = 1.0; for (size_t i = 0; i < 100; ++i) { auto *point = adc_trajectory->add_trajectory_point(); double offset = 0.1 * static_cast<double>(i); point->mutable_path_point()->set_x(x + offset); point->mutable_path_point()->set_y(y + offset); } adc_trajectory->mutable_header()->set_sequence_num(123); proto_buf.Serialize(adc_trajectory, "planning::ADCTrajectory"); BridgeProtoDiserializedBuf<planning::ADCTrajectory> proto_recv_buf; size_t frame_count = proto_buf.GetSerializedBufCount(); for (size_t i = 0; i < frame_count; i++) { char header_flag[sizeof(BRIDGE_HEADER_FLAG) + 1] = {0}; bsize offset = 0; memcpy(header_flag, proto_buf.GetSerializedBuf(i), HEADER_FLAG_SIZE); EXPECT_STREQ(header_flag, BRIDGE_HEADER_FLAG); offset += static_cast<bsize>(sizeof(BRIDGE_HEADER_FLAG) + 1); char header_size_buf[sizeof(hsize) + 1] = {0}; const char *cursor = proto_buf.GetSerializedBuf(i) + offset; memcpy(header_size_buf, cursor, sizeof(hsize)); hsize header_size = *(reinterpret_cast<hsize *>(header_size_buf)); EXPECT_EQ(header_size, 184); offset += static_cast<bsize>(sizeof(hsize) + 1); BridgeHeader header; bsize buf_size = header_size - offset; cursor = proto_buf.GetSerializedBuf(i) + offset; EXPECT_TRUE(header.Diserialize(cursor, buf_size)); EXPECT_STREQ(header.GetMsgName().c_str(), "planning::ADCTrajectory"); EXPECT_EQ(header.GetMsgID(), 123); proto_recv_buf.Initialize(header); char *buf = proto_recv_buf.GetBuf(header.GetFramePos()); cursor = proto_buf.GetSerializedBuf(i) + header_size; memcpy(buf, cursor, header.GetFrameSize()); proto_recv_buf.UpdateStatus(header.GetIndex()); if (i < frame_count - 1) { EXPECT_FALSE(proto_recv_buf.IsReadyDiserialize()); } else { EXPECT_TRUE(proto_recv_buf.IsReadyDiserialize()); } } auto pb_msg = std::make_shared<planning::ADCTrajectory>(); proto_recv_buf.Diserialized(pb_msg); EXPECT_EQ(pb_msg->header().sequence_num(), adc_trajectory->header().sequence_num()); EXPECT_EQ(pb_msg->trajectory_point_size(), adc_trajectory->trajectory_point_size()); int traj_size = adc_trajectory->trajectory_point_size(); EXPECT_EQ(traj_size, 100); for (int i = 0; i < traj_size; ++i) { EXPECT_EQ(adc_trajectory->trajectory_point(i).path_point().x(), pb_msg->trajectory_point(i).path_point().x()); EXPECT_EQ(adc_trajectory->trajectory_point(i).path_point().y(), pb_msg->trajectory_point(i).path_point().x()); } } } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_proto_serialized_buf.h
/******************************************************************************der * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <memory> #include <string> #include <vector> #include "modules/bridge/common/bridge_header.h" #include "modules/bridge/common/macro.h" namespace apollo { namespace bridge { template <typename T> class BridgeProtoSerializedBuf { public: BridgeProtoSerializedBuf() {} ~BridgeProtoSerializedBuf(); char *GetFrame(size_t index); bool Serialize(const std::shared_ptr<T> &proto, const std::string &msg_name); const char *GetSerializedBuf(size_t index) const { return frames_[index].buf_; } size_t GetSerializedBufCount() const { return frames_.size(); } size_t GetSerializedBufSize(size_t index) const { return frames_[index].buf_len_; } private: struct Buf { char *buf_; size_t buf_len_; }; private: std::vector<Buf> frames_; }; template <typename T> BridgeProtoSerializedBuf<T>::~BridgeProtoSerializedBuf() { for (auto frame : frames_) { FREE_ARRY(frame.buf_); } } template <typename T> bool BridgeProtoSerializedBuf<T>::Serialize(const std::shared_ptr<T> &proto, const std::string &msg_name) { bsize msg_len = static_cast<bsize>(proto->ByteSizeLong()); char *tmp = new char[msg_len](); if (!proto->SerializeToArray(tmp, static_cast<int>(msg_len))) { FREE_ARRY(tmp); return false; } bsize offset = 0; bsize frame_index = 0; uint32_t total_frames = static_cast<uint32_t>(msg_len / FRAME_SIZE + (msg_len % FRAME_SIZE ? 1 : 0)); while (offset < msg_len) { bsize left = msg_len - frame_index * FRAME_SIZE; bsize cpy_size = (left > FRAME_SIZE) ? FRAME_SIZE : left; BridgeHeader header; header.SetHeaderVer(0); header.SetMsgName(msg_name); header.SetMsgID(proto->header().sequence_num()); header.SetTimeStamp(proto->header().timestamp_sec()); header.SetMsgSize(msg_len); header.SetTotalFrames(total_frames); header.SetFrameSize(cpy_size); header.SetIndex(frame_index); header.SetFramePos(frame_index * FRAME_SIZE); hsize header_size = header.GetHeaderSize(); Buf buf; buf.buf_ = new char[cpy_size + header_size]; buf.buf_len_ = cpy_size + header_size; header.Serialize(buf.buf_, buf.buf_len_); memcpy(buf.buf_ + header_size, tmp + frame_index * FRAME_SIZE, cpy_size); frames_.push_back(buf); frame_index++; offset += cpy_size; } FREE_ARRY(tmp); return true; } } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_gflags.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/bridge/common/bridge_gflags.h" DEFINE_string(bridge_module_name, "Bridge", "Bridge module name"); DEFINE_double(timeout, 1.0, "receive/send proto msg time out");
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_header.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/bridge/common/bridge_header.h" #include <cstring> namespace apollo { namespace bridge { bool BridgeHeader::Serialize(char *buf, size_t size) { if (!buf || size == 0) { return false; } char *cursor = buf; char *p_header_size = nullptr; cursor = SerializeHeaderFlag(cursor, size); p_header_size = cursor; cursor += sizeof(hsize) + 1; for (int i = 0; i < Header_Tail; i++) { cursor = header_item[i]->SerializeItem(cursor, size); } if (!SerializeHeaderSize(p_header_size, size)) { return false; } return true; } bool BridgeHeader::Diserialize(const char *buf, size_t buf_size) { const char *cursor = buf; int i = static_cast<int>(buf_size); while (i > 0) { HType type = *(reinterpret_cast<const HType *>(cursor)); if (type >= Header_Tail || type < 0) { cursor += sizeof(HType) + 1; bsize size = *(reinterpret_cast<const bsize *>(cursor)); cursor += sizeof(bsize) + size + 2; i -= static_cast<int>(sizeof(HType) + sizeof(bsize) + size + 3); continue; } for (int j = 0; j < Header_Tail; j++) { if (type == header_item[j]->GetType()) { size_t value_size = 0; cursor = header_item[j]->DiserializeItem(cursor, static_cast<size_t>(i), &value_size); i -= static_cast<int>(value_size); if (cursor == nullptr) { return false; } break; } } } return true; } bool BridgeHeader::IsAvailable(const char *buf) { if (!buf) { return false; } if (memcmp(BRIDGE_HEADER_FLAG, buf, sizeof(BRIDGE_HEADER_FLAG) - 1) != 0) { return false; } return true; } char *BridgeHeader::SerializeHeaderFlag(char *buf, size_t size) { if (!buf || size == 0) { return nullptr; } return SerializeBasicType<char, sizeof(BRIDGE_HEADER_FLAG)>( BRIDGE_HEADER_FLAG, buf, size); } char *BridgeHeader::SerializeHeaderSize(char *buf, size_t size) { hsize header_size = GetHeaderSize(); return SerializeBasicType<hsize, sizeof(hsize)>(&header_size, buf, size); } } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/macro.h
/****************************************************************************** * Copyright 2018 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once namespace apollo { namespace bridge { #define _1K 1024 #define FREE_ARRY(arry) \ if (arry) { \ delete[] arry; \ } \ arry = nullptr #define FREE_POINTER(p) \ if (p) { \ delete p; \ } \ p = nullptr constexpr uint32_t FRAME_SIZE = 1024; } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_gflags.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include "gflags/gflags.h" DECLARE_string(bridge_module_name); DECLARE_double(timeout);
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_header.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <cstring> #include <string> #include "modules/bridge/common/bridge_header_item.h" namespace apollo { namespace bridge { typedef uint32_t hsize; constexpr char BRIDGE_HEADER_FLAG[] = "ApolloBridgeHeader"; constexpr size_t HEADER_FLAG_SIZE = sizeof(BRIDGE_HEADER_FLAG); constexpr size_t Item_Header_Size = sizeof(HType) + sizeof(bsize) + 2; class BridgeHeader { public: BridgeHeader() = default; ~BridgeHeader() = default; public: bool Serialize(char *buf, size_t size); bool Diserialize(const char *buf, size_t buf_size); bool IsAvailable(const char *buf); uint32_t GetHeaderVer() const { return header_ver_.value_; } hsize GetHeaderSize() const { return static_cast<hsize>(header_body_size_ + HEADER_FLAG_SIZE + sizeof(hsize) + 2); } bsize GetHeaderBodySize() const { return header_body_size_; } std::string GetMsgName() const { return msg_name_.value_; } uint32_t GetMsgID() const { return msg_id_.value_; } uint32_t GetTotalFrames() const { return total_frames_.value_; } uint32_t GetIndex() const { return index_.value_; } double GetTimeStamp() const { return time_stamp_.value_; } bsize GetMsgSize() const { return msg_size_.value_; } bsize GetFrameSize() const { return frame_size_.value_; } bsize GetFramePos() const { return frame_pos_.value_; } void SetHeaderVer(uint32_t header_ver) { header_ver_ = header_ver; header_body_size_ += static_cast<hsize>(Item_Header_Size + 1 + sizeof(uint32_t)); } void SetMsgName(const std::string &msg_name) { msg_name_ = msg_name; header_body_size_ += static_cast<hsize>(Item_Header_Size + 1 + msg_name.length() + 1); } void SetMsgID(uint32_t msg_id) { msg_id_ = msg_id; header_body_size_ += static_cast<hsize>(Item_Header_Size + 1 + sizeof(uint32_t)); } void SetTotalFrames(uint32_t total_frames) { total_frames_ = total_frames; header_body_size_ += static_cast<hsize>(Item_Header_Size + 1 + sizeof(uint32_t)); } void SetFrameSize(bsize frame_size) { frame_size_ = frame_size; header_body_size_ += static_cast<hsize>(Item_Header_Size + 1 + sizeof(bsize)); } void SetFramePos(bsize frame_pos) { frame_pos_ = frame_pos; header_body_size_ += static_cast<hsize>(Item_Header_Size + 1 + sizeof(bsize)); } void SetIndex(uint32_t index) { index_ = index; header_body_size_ += static_cast<hsize>(Item_Header_Size + 1 + sizeof(uint32_t)); } void SetTimeStamp(double time_stamp) { time_stamp_ = time_stamp; header_body_size_ += static_cast<hsize>(Item_Header_Size + 1 + sizeof(double)); } void SetMsgSize(bsize msg_size) { msg_size_ = msg_size; header_body_size_ += static_cast<hsize>(Item_Header_Size + 1 + sizeof(bsize)); } private: template <typename T, size_t S> char *SerializeBasicType(const T *value, char *buf, size_t size) { if (!buf || size < S) { return nullptr; } char *res = buf; memcpy(res, value, S); res[S] = '\n'; res += S + 1; return res; } template <typename T, size_t S> bool DiserializeBasicType(T *value, const char *buf) { if (!buf) { return false; } char temp[S] = {0}; memcpy(temp, buf, S); *value = *(reinterpret_cast<T *>(temp)); return true; } char *SerializeHeaderFlag(char *buf, size_t size); char *SerializeHeaderSize(char *buf, size_t size); private: HeaderItem<Header_Ver, uint32_t> header_ver_; HeaderItem<Msg_Name, std::string> msg_name_; HeaderItem<Msg_ID, uint32_t> msg_id_; HeaderItem<Msg_Size, bsize> msg_size_; HeaderItem<Msg_Frames, uint32_t> total_frames_; HeaderItem<Frame_Size, bsize> frame_size_; HeaderItem<Frame_Pos, bsize> frame_pos_; HeaderItem<Frame_Index, uint32_t> index_; HeaderItem<Time_Stamp, double> time_stamp_; hsize header_body_size_ = 0; HeaderItemBase *header_item[Header_Tail] = { &header_ver_, &msg_name_, &msg_id_, &msg_size_, &total_frames_, &frame_size_, &frame_pos_, &index_, &time_stamp_, }; }; } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/util.cc
/****************************************************************************** * Copyright 2018 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/bridge/common/util.h" namespace apollo { namespace bridge { int GetProtoSize(const char *buf, size_t size) { if (size != sizeof(size_t)) { return 0; } char size_buf[sizeof(size_t)] = {0}; memcpy(size_buf, buf, sizeof(size_t)); int proto_size = *(reinterpret_cast<int *>(size_buf)); return proto_size; } } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/util.h
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <cstring> #include <memory> #include <string> #include <vector> #include "modules/bridge/common/bridge_buffer.h" #include "modules/bridge/common/macro.h" namespace apollo { namespace bridge { const int HEADER_BUF_SIZE = sizeof(size_t); template <typename T> void WriteToBuffer(BridgeBuffer<char> *buf, const std::shared_ptr<T> &pb_msg) { if (!buf) { return; } size_t msg_len = pb_msg->ByteSize(); size_t total_size = HEADER_BUF_SIZE + msg_len; buf->reset(total_size); buf->write(0, reinterpret_cast<char *>(&msg_len), sizeof(size_t)); pb_msg->SerializeToArray(reinterpret_cast<char *>(buf + sizeof(size_t)), static_cast<int>(msg_len)); } template <typename T> bool RemoveItem(std::vector<T *> *list, const T *t) { if (!list) { return false; } typename std::vector<T *>::iterator itor = list->begin(); for (; itor != list->end();) { if (*itor == t) { T *tmp = *itor; FREE_POINTER(tmp); itor = list->erase(itor); continue; } ++itor; } return true; } template <typename T> bool RemoveItem(std::vector<std::shared_ptr<T>> *list, std::shared_ptr<T> t) { if (!list) { return false; } typename std::vector<std::shared_ptr<T>>::iterator itor = list->begin(); for (; itor != list->end();) { if (itor->get() == t.get()) { itor = list->erase(itor); continue; } ++itor; } return true; } int GetProtoSize(const char *buf, size_t size); } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_buffer_test.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/bridge/common/bridge_buffer.h" #include <cstdio> #include <string> #include "gtest/gtest.h" namespace apollo { namespace bridge { TEST(BridgeBufferTest, bridge_buf_test) { BridgeBuffer<char> buf; char *p = buf; EXPECT_EQ(0, buf.capacity()); EXPECT_EQ(0, buf.size()); buf.reset(100); char *p1 = buf; EXPECT_EQ(100, buf.capacity()); EXPECT_EQ(100, buf.size()); EXPECT_NE(p, p1); std::string str("hello world"); snprintf(buf, str.length() + 1, "%s", str.c_str()); EXPECT_STREQ(buf, str.c_str()); buf.reset(80); char *p2 = buf; EXPECT_EQ(100, buf.capacity()); EXPECT_EQ(80, buf.size()); EXPECT_EQ(p2, p1); std::string str1("hi world"); snprintf(buf, str1.length() + 1, "%s", str1.c_str()); EXPECT_STREQ(buf, str1.c_str()); } } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/udp_listener.h
/****************************************************************************** * Copyright 2018 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <arpa/inet.h> #include <fcntl.h> #include <netinet/in.h> #include <pthread.h> #include <sys/epoll.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> namespace apollo { namespace bridge { constexpr int MAXEPOLLSIZE = 100; template <typename T> class UDPListener { public: typedef bool (T::*func)(int fd); UDPListener() {} UDPListener(T *receiver, uint16_t port, func msg_handle) { receiver_ = receiver; listened_port_ = port; msg_handle_ = msg_handle; } ~UDPListener() { if (listener_sock_ != -1) { close(listener_sock_); } } void SetMsgHandle(func msg_handle) { msg_handle_ = msg_handle; } bool Initialize(T *receiver, func msg_handle, uint16_t port); bool Listen(); static void *pthread_handle_message(void *param); public: struct Param { int fd_ = 0; UDPListener<T> *listener_ = nullptr; }; private: bool setnonblocking(int sockfd); void MessageHandle(int fd); private: T *receiver_ = nullptr; uint16_t listened_port_ = 0; int listener_sock_ = -1; func msg_handle_ = nullptr; int kdpfd_ = 0; }; template <typename T> bool UDPListener<T>::Initialize(T *receiver, func msg_handle, uint16_t port) { msg_handle_ = msg_handle; if (!msg_handle_) { return false; } receiver_ = receiver; if (!receiver_) { return false; } listened_port_ = port; struct rlimit rt; rt.rlim_max = rt.rlim_cur = MAXEPOLLSIZE; if (setrlimit(RLIMIT_NOFILE, &rt) == -1) { return false; } listener_sock_ = socket(AF_INET, SOCK_DGRAM, 0); if (listener_sock_ == -1) { return false; } int opt = SO_REUSEADDR; setsockopt(listener_sock_, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); setnonblocking(listener_sock_); struct sockaddr_in serv_addr; serv_addr.sin_family = PF_INET; serv_addr.sin_port = htons((uint16_t)listened_port_); serv_addr.sin_addr.s_addr = INADDR_ANY; if (bind(listener_sock_, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1) { close(listener_sock_); return false; } kdpfd_ = epoll_create(MAXEPOLLSIZE); struct epoll_event ev; ev.events = EPOLLIN | EPOLLET; ev.data.fd = listener_sock_; if (epoll_ctl(kdpfd_, EPOLL_CTL_ADD, listener_sock_, &ev) < 0) { close(listener_sock_); return false; } return true; } template <typename T> bool UDPListener<T>::Listen() { int nfds = -1; bool res = true; struct epoll_event events[MAXEPOLLSIZE]; while (true) { nfds = epoll_wait(kdpfd_, events, 10000, -1); if (nfds == -1) { res = false; break; } for (int i = 0; i < nfds; ++i) { if (events[i].data.fd == listener_sock_) { pthread_t thread; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); Param *par = new Param; par->fd_ = events[i].data.fd; par->listener_ = this; if (pthread_create(&thread, &attr, &UDPListener<T>::pthread_handle_message, reinterpret_cast<void *>(par))) { res = false; return res; } } } } close(listener_sock_); return res; } template <typename T> bool UDPListener<T>::setnonblocking(int sockfd) { if (fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFD, 0) | O_NONBLOCK) == -1) { return false; } return true; } template <typename T> void *UDPListener<T>::pthread_handle_message(void *param) { Param *par = static_cast<Param *>(param); int fd = par->fd_; UDPListener<T> *listener = par->listener_; if (par) { delete par; } par = nullptr; if (!listener) { pthread_exit(nullptr); } listener->MessageHandle(fd); pthread_exit(nullptr); } template <typename T> void UDPListener<T>::MessageHandle(int fd) { if (!receiver_ || !msg_handle_) { return; } (receiver_->*msg_handle_)(fd); } } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test", "cc_binary") load("//tools:cpplint.bzl", "cpplint") load("//tools/install:install.bzl", "install", "install_files", "install_src_files") package(default_visibility = ["//visibility:public"]) install( name = "install", targets = ["libbridge_gflags.so"], library_dest = "bridge/lib", ) cc_library( name = "bridge_buffer", srcs = ["bridge_buffer.cc"], hdrs = ["bridge_buffer.h"], ) cc_binary( name = "libbridge_gflags.so", srcs = ["bridge_gflags.cc", "bridge_gflags.h"], deps = [ "@com_github_gflags_gflags//:gflags", ], linkshared = True, linkstatic = True, ) cc_library( name = "bridge_gflags", srcs = [":libbridge_gflags.so"], hdrs = ["bridge_gflags.h"], alwayslink = True, deps = [ "@com_github_gflags_gflags//:gflags", ], ) cc_library( name = "util", srcs = ["util.cc"], hdrs = ["util.h"], deps = [ ":bridge_buffer", ":macro", ], ) cc_library( name = "macro", hdrs = ["macro.h"], ) cc_library( name = "bridge_proto_serialized_buf", hdrs = ["bridge_proto_serialized_buf.h"], ) cc_library( name = "bridge_proto_diserialized_buf", hdrs = ["bridge_proto_diserialized_buf.h"], ) cc_library( name = "bridge_proto_diser_buf_factory", hdrs = ["bridge_proto_diser_buf_factory.h"], deps = [ "//modules/common/adapters:adapter_gflags", ], ) cc_library( name = "udp_listener", hdrs = ["udp_listener.h"], ) cc_library( name = "bridge_header", srcs = ["bridge_header.cc"], hdrs = [ "bridge_header.h", "bridge_header_item.h", ], ) cc_test( name = "bridge_buffer_test", size = "small", srcs = ["bridge_buffer_test.cc"], deps = [ ":bridge_buffer", "@com_google_googletest//:gtest_main", ], ) cc_test( name = "bridge_proto_buf_test", size = "small", srcs = ["bridge_proto_buf_test.cc"], deps = [ "//modules/bridge:udp_bridge", "@com_google_googletest//:gtest_main", ], ) cpplint()
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_proto_diser_buf_factory.h
/******************************************************************************der * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #pragma once #include <memory> #include <string> #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "modules/bridge/common/bridge_proto_diserialized_buf.h" #include "modules/common/adapters/adapter_gflags.h" namespace apollo { namespace bridge { class ProtoDiserializedBufBaseFactory { public: static std::shared_ptr<ProtoDiserializedBufBase> CreateObj( const BridgeHeader &header) { std::shared_ptr<ProtoDiserializedBufBase> obj; if (strcmp("Chassis", header.GetMsgName().c_str()) == 0) { obj = std::make_shared<BridgeProtoDiserializedBuf<canbus::Chassis>>( FLAGS_chassis_topic); } return obj; } }; } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/common/bridge_buffer.cc
/****************************************************************************** * Copyright 2019 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/bridge/common/bridge_buffer.h" #include <memory.h> namespace apollo { namespace bridge { #define BRIDGE_IMPL(type) template class BridgeBuffer<type> template <typename T> BridgeBuffer<T>::BridgeBuffer() {} template <typename T> BridgeBuffer<T>::BridgeBuffer(size_t size) { reset(size); } template <typename T> BridgeBuffer<T>::~BridgeBuffer() { std::lock_guard<std::mutex> lg(mutex_); if (buf_) { delete[] buf_; } buf_ = nullptr; size_ = 0; capacity_ = 0; } template <typename T> BridgeBuffer<T>::operator T *() { return buf_; } template <typename T> void BridgeBuffer<T>::reset(size_t size) { std::lock_guard<std::mutex> lg(mutex_); if (capacity_ < size) { if (buf_) { delete[] buf_; } capacity_ = size; buf_ = new T[capacity_]; } size_ = size; memset(buf_, 0, sizeof(T) * capacity_); } template <typename T> void BridgeBuffer<T>::write(size_t index, const T *data, size_t size) { std::lock_guard<std::mutex> lg(mutex_); reset(size + index); T *p = buf_ + index; memcpy(p, data, size); } BRIDGE_IMPL(char); BRIDGE_IMPL(int); BRIDGE_IMPL(double); } // namespace bridge } // namespace apollo
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/conf/udp_bridge_receiver_chassis.pb.txt
topic_name: "/apollo/canbus/Chassis" bind_port: 8900 proto_name: "Chassis" enable_timeout: false
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/conf/bridge.conf
--flagfile=/apollo/modules/common/data/global_flagfile.txt --timeout=10000.0
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/conf/udp_bridge_sender_localization.pb.txt
remote_ip: "127.0.0.1" remote_port: 8901 proto_name: "LocalizationEstimate"
0
apollo_public_repos/apollo/modules/bridge
apollo_public_repos/apollo/modules/bridge/conf/udp_bridge_sender_adctrajectory.pb.txt
remote_ip: "127.0.0.1" remote_port: 8900 proto_name: "ADCTrajectory"
0
apollo_public_repos/apollo/modules
apollo_public_repos/apollo/modules/canbus_vehicle/BUILD
load("//tools/install:install.bzl", "install", "install_src_files") package(default_visibility = ["//visibility:public"]) install( name = "install", deps = [ "//modules/canbus_vehicle/ch:install", "//modules/canbus_vehicle/devkit:install", "//modules/canbus_vehicle/ge3:install", "//modules/canbus_vehicle/gem:install", "//modules/canbus_vehicle/lexus:install", "//modules/canbus_vehicle/lincoln:install", "//modules/canbus_vehicle/neolix_edu:install", "//modules/canbus_vehicle/transit:install", "//modules/canbus_vehicle/wey:install", "//modules/canbus_vehicle/zhongyun:install", ], ) install_src_files( name = "install_src", deps = [ "//modules/canbus_vehicle/ch:install_src", "//modules/canbus_vehicle/devkit:install_src", "//modules/canbus_vehicle/ge3:install_src", "//modules/canbus_vehicle/gem:install_src", "//modules/canbus_vehicle/lexus:install_src", "//modules/canbus_vehicle/lincoln:install_src", "//modules/canbus_vehicle/neolix_edu:install_src", "//modules/canbus_vehicle/transit:install_src", "//modules/canbus_vehicle/wey:install_src", "//modules/canbus_vehicle/zhongyun:install_src", ], )
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/lincoln_vehicle_factory.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ /** * @file lincoln_vehicle_factory.h */ #pragma once #include <memory> #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/canbus/proto/vehicle_parameter.pb.h" #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/common_msgs/control_msgs/control_cmd.pb.h" #include "cyber/cyber.h" #include "modules/canbus/vehicle/abstract_vehicle_factory.h" #include "modules/canbus/vehicle/vehicle_controller.h" #include "modules/common/status/status.h" #include "modules/drivers/canbus/can_client/can_client.h" #include "modules/drivers/canbus/can_comm/can_receiver.h" #include "modules/drivers/canbus/can_comm/can_sender.h" #include "modules/drivers/canbus/can_comm/message_manager.h" /** * @namespace apollo::canbus * @brief apollo::canbus */ namespace apollo { namespace canbus { /** * @class LincolnVehicleFactory * * @brief this class is inherited from AbstractVehicleFactory. It can be used to * create controller and message manager for lincoln vehicle. */ class LincolnVehicleFactory : public AbstractVehicleFactory { public: /** * @brief destructor */ virtual ~LincolnVehicleFactory() = default; /** * @brief init vehicle factory * @returns true if successfully initialized */ bool Init(const CanbusConf *canbus_conf) override; /** * @brief start canclient, cansender, canreceiver, vehicle controller * @returns true if successfully started */ bool Start() override; /** * @brief stop canclient, cansender, canreceiver, vehicle controller */ void Stop() override; /** * @brief update control command */ void UpdateCommand( const apollo::control::ControlCommand *control_command) override; /** * @brief publish chassis messages */ Chassis publish_chassis() override; /** * @brief publish chassis for vehicle messages */ void PublishChassisDetail() override; private: /** * @brief create Lincoln vehicle controller * @returns a unique_ptr that points to the created controller */ std::unique_ptr<VehicleController<::apollo::canbus::Lincoln>> CreateVehicleController(); /** * @brief create lincoln message manager * @returns a unique_ptr that points to the created message manager */ std::unique_ptr<MessageManager<::apollo::canbus::Lincoln>> CreateMessageManager(); std::unique_ptr<::apollo::cyber::Node> node_ = nullptr; std::unique_ptr<apollo::drivers::canbus::CanClient> can_client_; CanSender<::apollo::canbus::Lincoln> can_sender_; apollo::drivers::canbus::CanReceiver<::apollo::canbus::Lincoln> can_receiver_; std::unique_ptr<MessageManager<::apollo::canbus::Lincoln>> message_manager_; std::unique_ptr<VehicleController<::apollo::canbus::Lincoln>> vehicle_controller_; std::shared_ptr<::apollo::cyber::Writer<::apollo::canbus::Lincoln>> chassis_detail_writer_; }; CYBER_REGISTER_VEHICLEFACTORY(LincolnVehicleFactory) } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/lincoln_vehicle_factory.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/lincoln_vehicle_factory.h" #include "cyber/common/log.h" #include "modules/canbus/common/canbus_gflags.h" #include "modules/canbus_vehicle/lincoln/lincoln_controller.h" #include "modules/canbus_vehicle/lincoln/lincoln_message_manager.h" #include "modules/common/adapters/adapter_gflags.h" #include "modules/common/util/util.h" #include "modules/drivers/canbus/can_client/can_client_factory.h" using apollo::common::ErrorCode; using apollo::control::ControlCommand; using apollo::drivers::canbus::CanClientFactory; namespace apollo { namespace canbus { bool LincolnVehicleFactory::Init(const CanbusConf *canbus_conf) { // Init can client auto can_factory = CanClientFactory::Instance(); can_factory->RegisterCanClients(); can_client_ = can_factory->CreateCANClient(canbus_conf->can_card_parameter()); if (!can_client_) { AERROR << "Failed to create can client."; return false; } AINFO << "Can client is successfully created."; message_manager_ = this->CreateMessageManager(); if (message_manager_ == nullptr) { AERROR << "Failed to create message manager."; return false; } AINFO << "Message manager is successfully created."; if (can_receiver_.Init(can_client_.get(), message_manager_.get(), canbus_conf->enable_receiver_log()) != ErrorCode::OK) { AERROR << "Failed to init can receiver."; return false; } AINFO << "The can receiver is successfully initialized."; if (can_sender_.Init(can_client_.get(), message_manager_.get(), canbus_conf->enable_sender_log()) != ErrorCode::OK) { AERROR << "Failed to init can sender."; return false; } AINFO << "The can sender is successfully initialized."; vehicle_controller_ = CreateVehicleController(); if (vehicle_controller_ == nullptr) { AERROR << "Failed to create vehicle controller."; return false; } AINFO << "The vehicle controller is successfully created."; if (vehicle_controller_->Init(canbus_conf->vehicle_parameter(), &can_sender_, message_manager_.get()) != ErrorCode::OK) { AERROR << "Failed to init vehicle controller."; return false; } AINFO << "The vehicle controller is successfully" << " initialized with canbus conf as : " << canbus_conf->vehicle_parameter().ShortDebugString(); node_ = ::apollo::cyber::CreateNode("chassis_detail"); chassis_detail_writer_ = node_->CreateWriter<::apollo::canbus::Lincoln>( FLAGS_chassis_detail_topic); return true; } bool LincolnVehicleFactory::Start() { // 1. init and start the can card hardware if (can_client_->Start() != ErrorCode::OK) { AERROR << "Failed to start can client"; return false; } AINFO << "Can client is started."; // 2. start receive first then send if (can_receiver_.Start() != ErrorCode::OK) { AERROR << "Failed to start can receiver."; return false; } AINFO << "Can receiver is started."; // 3. start send if (can_sender_.Start() != ErrorCode::OK) { AERROR << "Failed to start can sender."; return false; } // 4. start controller if (!vehicle_controller_->Start()) { AERROR << "Failed to start vehicle controller."; return false; } return true; } void LincolnVehicleFactory::Stop() { can_sender_.Stop(); can_receiver_.Stop(); can_client_->Stop(); vehicle_controller_->Stop(); AINFO << "Cleanup cansender, canreceiver, canclient, vehicle controller."; } void LincolnVehicleFactory::UpdateCommand( const apollo::control::ControlCommand *control_command) { if (vehicle_controller_->Update(*control_command) != ErrorCode::OK) { AERROR << "Failed to process callback function OnControlCommand because " "vehicle_controller_->Update error."; return; } can_sender_.Update(); } Chassis LincolnVehicleFactory::publish_chassis() { Chassis chassis = vehicle_controller_->chassis(); ADEBUG << chassis.ShortDebugString(); return chassis; } void LincolnVehicleFactory::PublishChassisDetail() { Lincoln chassis_detail; message_manager_->GetSensorData(&chassis_detail); ADEBUG << chassis_detail.ShortDebugString(); chassis_detail_writer_->Write(chassis_detail); } std::unique_ptr<VehicleController<::apollo::canbus::Lincoln>> LincolnVehicleFactory::CreateVehicleController() { return std::unique_ptr<VehicleController<::apollo::canbus::Lincoln>>( new lincoln::LincolnController()); } std::unique_ptr<MessageManager<::apollo::canbus::Lincoln>> LincolnVehicleFactory::CreateMessageManager() { return std::unique_ptr<MessageManager<::apollo::canbus::Lincoln>>( new lincoln::LincolnMessageManager()); } } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/lincoln_message_manager_test.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/lincoln_message_manager.h" #include "gtest/gtest.h" #include "modules/canbus_vehicle/lincoln/protocol/accel_6b.h" #include "modules/canbus_vehicle/lincoln/protocol/brake_60.h" #include "modules/canbus_vehicle/lincoln/protocol/brake_61.h" #include "modules/canbus_vehicle/lincoln/protocol/brakeinfo_74.h" #include "modules/canbus_vehicle/lincoln/protocol/fuellevel_72.h" #include "modules/canbus_vehicle/lincoln/protocol/gear_66.h" #include "modules/canbus_vehicle/lincoln/protocol/gear_67.h" #include "modules/canbus_vehicle/lincoln/protocol/gps_6d.h" #include "modules/canbus_vehicle/lincoln/protocol/gps_6e.h" #include "modules/canbus_vehicle/lincoln/protocol/gps_6f.h" #include "modules/canbus_vehicle/lincoln/protocol/gyro_6c.h" #include "modules/canbus_vehicle/lincoln/protocol/misc_69.h" #include "modules/canbus_vehicle/lincoln/protocol/steering_64.h" #include "modules/canbus_vehicle/lincoln/protocol/steering_65.h" #include "modules/canbus_vehicle/lincoln/protocol/throttle_62.h" #include "modules/canbus_vehicle/lincoln/protocol/throttle_63.h" #include "modules/canbus_vehicle/lincoln/protocol/throttleinfo_75.h" #include "modules/canbus_vehicle/lincoln/protocol/tirepressure_71.h" #include "modules/canbus_vehicle/lincoln/protocol/turnsignal_68.h" #include "modules/canbus_vehicle/lincoln/protocol/version_7f.h" #include "modules/canbus_vehicle/lincoln/protocol/wheelspeed_6a.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::canbus::Lincoln; using ::apollo::drivers::canbus::ProtocolData; class LincolnMessageManagerTest : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(LincolnMessageManagerTest, Accel6b) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Accel6b::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Accel6b *>(pd)->ID, Accel6b::ID); } TEST_F(LincolnMessageManagerTest, Brake60) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Brake60::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Brake60 *>(pd)->ID, Brake60::ID); } TEST_F(LincolnMessageManagerTest, Brake61) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Brake61::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Brake61 *>(pd)->ID, Brake61::ID); } TEST_F(LincolnMessageManagerTest, Brakeinfo74) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Brakeinfo74::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Brakeinfo74 *>(pd)->ID, Brakeinfo74::ID); } TEST_F(LincolnMessageManagerTest, Fuellevel72) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Fuellevel72::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Fuellevel72 *>(pd)->ID, Fuellevel72::ID); } TEST_F(LincolnMessageManagerTest, Gear66) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Gear66::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Gear66 *>(pd)->ID, Gear66::ID); } TEST_F(LincolnMessageManagerTest, Gear67) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Gear67::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Gear67 *>(pd)->ID, Gear67::ID); } TEST_F(LincolnMessageManagerTest, Gps6d) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Gps6d::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Gps6d *>(pd)->ID, Gps6d::ID); } TEST_F(LincolnMessageManagerTest, Gps6e) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Gps6e::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Gps6e *>(pd)->ID, Gps6e::ID); } TEST_F(LincolnMessageManagerTest, Gps6f) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Gps6f::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Gps6f *>(pd)->ID, Gps6f::ID); } TEST_F(LincolnMessageManagerTest, Gyro6c) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Gyro6c::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Gyro6c *>(pd)->ID, Gyro6c::ID); } TEST_F(LincolnMessageManagerTest, Misc69) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Misc69::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Misc69 *>(pd)->ID, Misc69::ID); } TEST_F(LincolnMessageManagerTest, Steering64) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Steering64::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Steering64 *>(pd)->ID, Steering64::ID); } TEST_F(LincolnMessageManagerTest, Steering65) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Steering65::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Steering65 *>(pd)->ID, Steering65::ID); } TEST_F(LincolnMessageManagerTest, Throttle62) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Throttle62::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Throttle62 *>(pd)->ID, Throttle62::ID); } TEST_F(LincolnMessageManagerTest, Throttle63) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Throttle63::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Throttle63 *>(pd)->ID, Throttle63::ID); } TEST_F(LincolnMessageManagerTest, Throttleinfo75) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Throttleinfo75::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Throttleinfo75 *>(pd)->ID, Throttleinfo75::ID); } TEST_F(LincolnMessageManagerTest, Tirepressure71) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Tirepressure71::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Tirepressure71 *>(pd)->ID, Tirepressure71::ID); } TEST_F(LincolnMessageManagerTest, Turnsignal68) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Turnsignal68::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Turnsignal68 *>(pd)->ID, Turnsignal68::ID); } TEST_F(LincolnMessageManagerTest, Version7f) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Version7f::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Version7f *>(pd)->ID, Version7f::ID); } TEST_F(LincolnMessageManagerTest, Wheelspeed6a) { LincolnMessageManager manager; ProtocolData<Lincoln> *pd = manager.GetMutableProtocolDataById(Wheelspeed6a::ID); EXPECT_NE(pd, nullptr); EXPECT_EQ(static_cast<Wheelspeed6a *>(pd)->ID, Wheelspeed6a::ID); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/lincoln_message_manager.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ /** * @file lincoln_message_manager.h * @brief the class of LincolnMessageManager */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/message_manager.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::MessageManager; /** * @class LincolnMessageManager * * @brief implementation of MessageManager for lincoln vehicle */ class LincolnMessageManager : public MessageManager<::apollo::canbus::Lincoln> { public: /** * @brief construct a lincoln message manager. protocol data for send and * receive are added in the construction. */ LincolnMessageManager(); virtual ~LincolnMessageManager(); }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/lincoln_controller_test.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/lincoln_controller.h" #include "cyber/common/file.h" #include "gtest/gtest.h" #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/canbus_vehicle/lincoln/lincoln_message_manager.h" #include "modules/common_msgs/basic_msgs/vehicle_signal.pb.h" #include "modules/common_msgs/control_msgs/control_cmd.pb.h" #include "modules/drivers/canbus/can_comm/can_sender.h" namespace apollo { namespace canbus { namespace lincoln { using apollo::common::ErrorCode; using apollo::common::VehicleSignal; using apollo::control::ControlCommand; class LincolnControllerTest : public ::testing::Test { public: virtual void SetUp() { std::string canbus_conf_file = "/apollo/modules/canbus/testdata/conf/mkz_canbus_conf_test.pb.txt"; cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_); params_ = canbus_conf_.vehicle_parameter(); control_cmd_.set_throttle(20.0); control_cmd_.set_brake(0.0); control_cmd_.set_steering_rate(80.0); control_cmd_.set_horn(false); } protected: LincolnController controller_; ControlCommand control_cmd_; VehicleSignal vehicle_signal_; CanSender<::apollo::canbus::Lincoln> sender_; LincolnMessageManager msg_manager_; CanbusConf canbus_conf_; VehicleParameter params_; }; TEST_F(LincolnControllerTest, Init) { ErrorCode ret = controller_.Init(params_, &sender_, &msg_manager_); EXPECT_EQ(ret, ErrorCode::OK); } TEST_F(LincolnControllerTest, SetDrivingMode) { Chassis chassis; chassis.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(chassis.driving_mode()); EXPECT_EQ(controller_.driving_mode(), chassis.driving_mode()); EXPECT_EQ(controller_.SetDrivingMode(chassis.driving_mode()), ErrorCode::OK); } TEST_F(LincolnControllerTest, Status) { controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.Update(control_cmd_), ErrorCode::OK); controller_.SetHorn(control_cmd_); controller_.SetBeam(control_cmd_); controller_.SetTurningSignal(control_cmd_); EXPECT_FALSE(controller_.CheckChassisError()); EXPECT_EQ(controller_.chassis_error_code(), Chassis::NO_ERROR); } TEST_F(LincolnControllerTest, UpdateDrivingMode) { controller_.Init(params_, &sender_, &msg_manager_); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.SetDrivingMode(Chassis::COMPLETE_MANUAL), ErrorCode::OK); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.SetDrivingMode(Chassis::AUTO_STEER_ONLY), ErrorCode::OK); controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); EXPECT_EQ(controller_.SetDrivingMode(Chassis::AUTO_SPEED_ONLY), ErrorCode::OK); EXPECT_EQ(controller_.SetDrivingMode(Chassis::COMPLETE_AUTO_DRIVE), ErrorCode::CANBUS_ERROR); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/cyberfile.xml
<package format="2"> <name>canbus-vehicle-lincoln</name> <version>local</version> <description> Dynamic loading for canbus module </description> <maintainer email="apollo-support@baidu.com">Apollo</maintainer> <license>Apache License 2.0</license> <url type="website">https://www.apollo.auto/</url> <url type="repository">https://github.com/ApolloAuto/apollo</url> <url type="bugtracker">https://github.com/ApolloAuto/apollo/issues</url> <type>module</type> <src_path url="https://github.com/ApolloAuto/apollo">//modules/canbus_vehicle/lincoln</src_path> <depend type="binary" repo_name="cyber">cyber-dev</depend> <depend type="binary" repo_name="common" lib_names="common">common-dev</depend> <depend type="binary" repo_name="canbus" lib_names="canbus">canbus-dev</depend> <depend repo_name="common-msgs" lib_names="common-msgs">common-msgs-dev</depend> <depend type="binary" repo_name="drivers">drivers-dev</depend> <depend repo_name="com_google_googletest" lib_names="gtest,gtest_main">3rd-gtest-dev</depend> </package>
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/lincoln_vehicle_factory_test.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/lincoln_vehicle_factory.h" #include "gtest/gtest.h" #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/canbus/proto/vehicle_parameter.pb.h" #include "cyber/common/file.h" namespace apollo { namespace canbus { class LincolnVehicleFactoryTest : public ::testing::Test { public: virtual void SetUp() { std::string canbus_conf_file = "/apollo/modules/canbus_vehicle/lincoln/testdata/" "mkz_canbus_conf_test.pb.txt"; cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_); params_ = canbus_conf_.vehicle_parameter(); params_.set_brand(apollo::common::LINCOLN_MKZ); lincoln_factory_.SetVehicleParameter(params_); } virtual void TearDown() {} protected: LincolnVehicleFactory lincoln_factory_; CanbusConf canbus_conf_; VehicleParameter params_; }; TEST_F(LincolnVehicleFactoryTest, InitVehicleController) { apollo::cyber::Init("vehicle_factory_test"); EXPECT_EQ(lincoln_factory_.Init(&canbus_conf_), true); } } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/lincoln_controller.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ /** * @file lincoln_controller.h * @brief The class of LincolnController */ #pragma once #include <memory> #include <thread> #include "gtest/gtest_prod.h" #include "modules/canbus/proto/canbus_conf.pb.h" #include "modules/canbus/proto/vehicle_parameter.pb.h" #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/common_msgs/basic_msgs/error_code.pb.h" #include "modules/common_msgs/chassis_msgs/chassis.pb.h" #include "modules/common_msgs/control_msgs/control_cmd.pb.h" #include "cyber/common/macros.h" #include "modules/canbus_vehicle/lincoln/protocol/brake_60.h" #include "modules/canbus_vehicle/lincoln/protocol/gear_66.h" #include "modules/canbus_vehicle/lincoln/protocol/steering_64.h" #include "modules/canbus_vehicle/lincoln/protocol/throttle_62.h" #include "modules/canbus_vehicle/lincoln/protocol/turnsignal_68.h" #include "modules/canbus/vehicle/vehicle_controller.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class LincolnController * * @brief this class implements the vehicle controller for lincoln vehicle. */ class LincolnController final : public VehicleController<::apollo::canbus::Lincoln> { public: /** * @brief initialize the lincoln vehicle controller. * @return init error_code */ common::ErrorCode Init(const VehicleParameter &params, CanSender<::apollo::canbus::Lincoln> *const can_sender, MessageManager<::apollo::canbus::Lincoln> *const message_manager) override; /** * @brief start the vehicle controller. * @return true if successfully started. */ bool Start() override; /** * @brief stop the vehicle controller. */ void Stop() override; /** * @brief calculate and return the chassis. * @returns a copy of chassis. Use copy here to avoid multi-thread issues. */ Chassis chassis() override; FRIEND_TEST(LincolnControllerTest, SetDrivingMode); FRIEND_TEST(LincolnControllerTest, Status); FRIEND_TEST(LincolnControllerTest, UpdateDrivingMode); private: // main logical function for operation the car enter or exit the auto driving void Emergency() override; common::ErrorCode EnableAutoMode() override; common::ErrorCode DisableAutoMode() override; common::ErrorCode EnableSteeringOnlyMode() override; common::ErrorCode EnableSpeedOnlyMode() override; // NEUTRAL, REVERSE, DRIVE void Gear(Chassis::GearPosition state) override; // brake with new acceleration // acceleration:0.00~99.99, unit:% // acceleration_spd: 60 ~ 100, suggest: 90 void Brake(double acceleration) override; // drive with old acceleration // gas:0.00~99.99 unit:% void Throttle(double throttle) override; // drive with acceleration/deceleration // acc:-7.0~5.0 unit:m/s^2 void Acceleration(double acc) override; // steering with old angle speed // angle:-99.99~0.00~99.99, unit:%, left:+, right:- void Steer(double angle) override; // steering with new angle speed // angle:-99.99~0.00~99.99, unit:%, left:+, right:- // angle_spd:0.00~99.99, unit:deg/s void Steer(double angle, double angle_spd) override; // set Electrical Park Brake void SetEpbBreak(const control::ControlCommand &command) override; void SetBeam(const control::ControlCommand &command) override; void SetHorn(const control::ControlCommand &command) override; void SetTurningSignal(const control::ControlCommand &command) override; bool VerifyID() override; void ResetProtocol(); bool CheckChassisError(); bool CheckSafetyError(const canbus::Lincoln &chassis); private: void SecurityDogThreadFunc(); virtual bool CheckResponse(const int32_t flags, bool need_wait); void set_chassis_error_mask(const int32_t mask); int32_t chassis_error_mask(); Chassis::ErrorCode chassis_error_code(); void set_chassis_error_code(const Chassis::ErrorCode &error_code); private: // control protocol Brake60 *brake_60_ = nullptr; Throttle62 *throttle_62_ = nullptr; Steering64 *steering_64_ = nullptr; Gear66 *gear_66_ = nullptr; Turnsignal68 *turnsignal_68_ = nullptr; Chassis chassis_; std::unique_ptr<std::thread> thread_; bool is_chassis_error_ = false; std::mutex chassis_error_code_mutex_; Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR; std::mutex chassis_mask_mutex_; int32_t chassis_error_mask_ = 0; bool received_vin_ = false; canbus::Chassis::GearPosition gear_tmp_; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/BUILD
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test") load("//tools/install:install.bzl", "install", "install_files", "install_src_files") load("//tools:cpplint.bzl", "cpplint") package(default_visibility = ["//visibility:public"]) CANBUS_COPTS = ["-DMODULE_NAME=\\\"canbus\\\""] cc_library( name = "lincoln_vehicle_factory", srcs = ["lincoln_vehicle_factory.cc"], hdrs = ["lincoln_vehicle_factory.h"], copts = CANBUS_COPTS, alwayslink = True, deps = [ ":lincoln_controller", ":lincoln_message_manager", "//modules/canbus/common:canbus_gflags", "//modules/common/adapters:adapter_gflags", "//modules/common/status", "//modules/canbus/vehicle:abstract_vehicle_factory", "//modules/drivers/canbus:sensor_canbus_lib", ], ) cc_binary( name = "liblincoln_vehicle_factory_lib.so", linkshared = True, linkstatic = True, deps = [":lincoln_vehicle_factory"], ) cc_library( name = "lincoln_message_manager", srcs = ["lincoln_message_manager.cc"], hdrs = ["lincoln_message_manager.h"], copts = CANBUS_COPTS, deps = [ "//modules/canbus_vehicle/lincoln/proto:lincoln_cc_proto", "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", ], ) cc_library( name = "lincoln_controller", srcs = ["lincoln_controller.cc"], hdrs = ["lincoln_controller.h"], copts = CANBUS_COPTS, deps = [ ":lincoln_message_manager", "//modules/common_msgs/chassis_msgs:chassis_cc_proto", "//modules/canbus_vehicle/lincoln/proto:lincoln_cc_proto", "//modules/canbus/vehicle:vehicle_controller_base", "//modules/canbus_vehicle/lincoln/protocol:canbus_lincoln_protocol", "//modules/common/kv_db", "//modules/drivers/canbus/can_comm:can_sender", "//modules/drivers/canbus/can_comm:message_manager_base", "//modules/drivers/canbus/common:canbus_common", "@com_google_googletest//:gtest", ], ) cc_test( name = "lincoln_controller_test", size = "small", srcs = ["lincoln_controller_test.cc"], data = ["//modules/canbus:test_data"], deps = [ "//modules/canbus_vehicle/lincoln:lincoln_controller", "@com_google_googletest//:gtest_main", ], ) cc_test( name = "lincoln_message_manager_test", size = "small", srcs = ["lincoln_message_manager_test.cc"], deps = [ "//modules/canbus_vehicle/lincoln:lincoln_message_manager", "@com_google_googletest//:gtest_main", ], ) cc_test( name = "lincoln_vehicle_factory_test", size = "small", srcs = ["lincoln_vehicle_factory_test.cc"], data = ["//modules/canbus:test_data"], linkstatic = True, deps = [ ":lincoln_vehicle_factory", "@com_google_googletest//:gtest_main", ], ) install( name = "install", library_dest = "canbus-vehicle-lincoln/lib", data_dest = "canbus-vehicle-lincoln", data = [ ":runtime_data", ":cyberfile.xml", ":canbus-vehicle-lincoln.BUILD", ], targets = [ ":liblincoln_vehicle_factory_lib.so", ], deps = [ ":pb_lincoln", ":pb_hdrs", ], ) install( name = "pb_hdrs", data_dest = "canbus-vehicle-lincoln/include", data = [ "//modules/canbus_vehicle/lincoln/proto:lincoln_cc_proto", ], ) install_files( name = "pb_lincoln", dest = "canbus-vehicle-lincoln", files = [ "//modules/canbus_vehicle/lincoln/proto:lincoln_py_pb2", ], ) filegroup( name = "runtime_data", srcs = glob([ "testdata/**", ]), ) install_src_files( name = "install_src", deps = [ ":install_lincoln_src", ":install_lincoln_hdrs" ], ) install_src_files( name = "install_lincoln_src", src_dir = ["."], dest = "canbus-vehicle-lincoln/src", filter = "*", ) install_src_files( name = "install_lincoln_hdrs", src_dir = ["."], dest = "canbus-vehicle-lincoln/include", filter = "*.h", ) cpplint()
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/lincoln_message_manager.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/lincoln_message_manager.h" #include "modules/canbus_vehicle/lincoln/protocol/accel_6b.h" #include "modules/canbus_vehicle/lincoln/protocol/brake_60.h" #include "modules/canbus_vehicle/lincoln/protocol/brake_61.h" #include "modules/canbus_vehicle/lincoln/protocol/brakeinfo_74.h" #include "modules/canbus_vehicle/lincoln/protocol/fuellevel_72.h" #include "modules/canbus_vehicle/lincoln/protocol/gear_66.h" #include "modules/canbus_vehicle/lincoln/protocol/gear_67.h" #include "modules/canbus_vehicle/lincoln/protocol/gps_6d.h" #include "modules/canbus_vehicle/lincoln/protocol/gps_6e.h" #include "modules/canbus_vehicle/lincoln/protocol/gps_6f.h" #include "modules/canbus_vehicle/lincoln/protocol/gyro_6c.h" #include "modules/canbus_vehicle/lincoln/protocol/license_7e.h" #include "modules/canbus_vehicle/lincoln/protocol/misc_69.h" #include "modules/canbus_vehicle/lincoln/protocol/steering_64.h" #include "modules/canbus_vehicle/lincoln/protocol/steering_65.h" #include "modules/canbus_vehicle/lincoln/protocol/surround_73.h" #include "modules/canbus_vehicle/lincoln/protocol/throttle_62.h" #include "modules/canbus_vehicle/lincoln/protocol/throttle_63.h" #include "modules/canbus_vehicle/lincoln/protocol/throttleinfo_75.h" #include "modules/canbus_vehicle/lincoln/protocol/tirepressure_71.h" #include "modules/canbus_vehicle/lincoln/protocol/turnsignal_68.h" #include "modules/canbus_vehicle/lincoln/protocol/version_7f.h" #include "modules/canbus_vehicle/lincoln/protocol/wheelspeed_6a.h" namespace apollo { namespace canbus { namespace lincoln { LincolnMessageManager::LincolnMessageManager() { // TODO(Authors): verify which one is recv/sent AddSendProtocolData<Brake60, true>(); AddSendProtocolData<Throttle62, true>(); AddSendProtocolData<Steering64, true>(); AddSendProtocolData<Gear66, true>(); AddSendProtocolData<Turnsignal68, true>(); AddRecvProtocolData<Brake61, true>(); AddRecvProtocolData<Throttle63, true>(); AddRecvProtocolData<Steering65, true>(); AddRecvProtocolData<Gear67, true>(); AddRecvProtocolData<Misc69, true>(); AddRecvProtocolData<Wheelspeed6a, true>(); AddRecvProtocolData<Accel6b, true>(); AddRecvProtocolData<Gyro6c, true>(); AddRecvProtocolData<Gps6d, true>(); AddRecvProtocolData<Gps6e, true>(); AddRecvProtocolData<Gps6f, true>(); AddRecvProtocolData<Tirepressure71, true>(); AddRecvProtocolData<Fuellevel72, true>(); AddRecvProtocolData<Surround73, true>(); AddRecvProtocolData<Brakeinfo74, true>(); AddRecvProtocolData<Throttleinfo75, true>(); AddRecvProtocolData<Version7f, true>(); AddRecvProtocolData<License7e, true>(); } LincolnMessageManager::~LincolnMessageManager() {} } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/lincoln_controller.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/lincoln_controller.h" #include "modules/common_msgs/basic_msgs/vehicle_signal.pb.h" #include "cyber/common/log.h" #include "cyber/time/time.h" #include "modules/canbus_vehicle/lincoln/lincoln_message_manager.h" #include "modules/canbus_vehicle/lincoln/protocol/brake_60.h" #include "modules/canbus_vehicle/lincoln/protocol/gear_66.h" #include "modules/canbus_vehicle/lincoln/protocol/steering_64.h" #include "modules/canbus_vehicle/lincoln/protocol/throttle_62.h" #include "modules/canbus_vehicle/lincoln/protocol/turnsignal_68.h" #include "modules/canbus/vehicle/vehicle_controller.h" #include "modules/common/kv_db/kv_db.h" #include "modules/drivers/canbus/can_comm/can_sender.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::ProtocolData; using common::ErrorCode; using control::ControlCommand; namespace { const int32_t kMaxFailAttempt = 10; const int32_t CHECK_RESPONSE_STEER_UNIT_FLAG = 1; const int32_t CHECK_RESPONSE_SPEED_UNIT_FLAG = 2; } // namespace ErrorCode LincolnController::Init( const VehicleParameter &params, CanSender<::apollo::canbus::Lincoln> *const can_sender, MessageManager<::apollo::canbus::Lincoln> *const message_manager) { if (is_initialized_) { AINFO << "LincolnController has already been initiated."; return ErrorCode::CANBUS_ERROR; } vehicle_params_.CopyFrom( common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param()); params_.CopyFrom(params); if (!params_.has_driving_mode()) { AERROR << "Vehicle conf pb not set driving_mode."; return ErrorCode::CANBUS_ERROR; } if (can_sender == nullptr) { AERROR << "Canbus sender is null."; return ErrorCode::CANBUS_ERROR; } can_sender_ = can_sender; if (message_manager == nullptr) { AERROR << "Protocol manager is null."; return ErrorCode::CANBUS_ERROR; } message_manager_ = message_manager; // Sender part brake_60_ = dynamic_cast<Brake60 *>( message_manager_->GetMutableProtocolDataById(Brake60::ID)); if (brake_60_ == nullptr) { AERROR << "Brake60 does not exist in the LincolnMessageManager!"; return ErrorCode::CANBUS_ERROR; } throttle_62_ = dynamic_cast<Throttle62 *>( message_manager_->GetMutableProtocolDataById(Throttle62::ID)); if (throttle_62_ == nullptr) { AERROR << "Throttle62 does not exist in the LincolnMessageManager!"; return ErrorCode::CANBUS_ERROR; } steering_64_ = dynamic_cast<Steering64 *>( message_manager_->GetMutableProtocolDataById(Steering64::ID)); if (steering_64_ == nullptr) { AERROR << "Steering64 does not exist in the LincolnMessageManager!"; return ErrorCode::CANBUS_ERROR; } gear_66_ = dynamic_cast<Gear66 *>( message_manager_->GetMutableProtocolDataById(Gear66::ID)); if (gear_66_ == nullptr) { AERROR << "Gear66 does not exist in the LincolnMessageManager!"; return ErrorCode::CANBUS_ERROR; } turnsignal_68_ = dynamic_cast<Turnsignal68 *>( message_manager_->GetMutableProtocolDataById(Turnsignal68::ID)); if (turnsignal_68_ == nullptr) { AERROR << "Turnsignal68 does not exist in the LincolnMessageManager!"; return ErrorCode::CANBUS_ERROR; } can_sender_->AddMessage(Brake60::ID, brake_60_, false); can_sender_->AddMessage(Throttle62::ID, throttle_62_, false); can_sender_->AddMessage(Steering64::ID, steering_64_, false); can_sender_->AddMessage(Gear66::ID, gear_66_, false); can_sender_->AddMessage(Turnsignal68::ID, turnsignal_68_, false); // Need to sleep to ensure all messages received AINFO << "LincolnController is initialized."; gear_tmp_ = Chassis::GEAR_INVALID; is_initialized_ = true; return ErrorCode::OK; } bool LincolnController::Start() { if (!is_initialized_) { AERROR << "LincolnController has NOT been initiated."; return false; } const auto &update_func = [this] { SecurityDogThreadFunc(); }; thread_.reset(new std::thread(update_func)); return true; } void LincolnController::Stop() { if (!is_initialized_) { AERROR << "LincolnController stops or starts improperly!"; return; } if (thread_ != nullptr && thread_->joinable()) { thread_->join(); thread_.reset(); AINFO << "LincolnController stopped."; } } Chassis LincolnController::chassis() { chassis_.Clear(); Lincoln chassis_detail; message_manager_->GetSensorData(&chassis_detail); // 21, 22, previously 1, 2 if (driving_mode() == Chassis::EMERGENCY_MODE) { set_chassis_error_code(Chassis::NO_ERROR); } chassis_.set_driving_mode(driving_mode()); chassis_.set_error_code(chassis_error_code()); // 3 chassis_.set_engine_started(true); // 4 if (chassis_detail.has_ems() && chassis_detail.ems().has_engine_rpm()) { chassis_.set_engine_rpm( static_cast<float>(chassis_detail.ems().engine_rpm())); } else { chassis_.set_engine_rpm(0); } // 5 if (chassis_detail.has_vehicle_spd() && chassis_detail.vehicle_spd().has_vehicle_spd()) { chassis_.set_speed_mps( static_cast<float>(chassis_detail.vehicle_spd().vehicle_spd())); chassis_.mutable_wheel_speed()->set_is_wheel_spd_rr_valid( chassis_detail.vehicle_spd().is_wheel_spd_rr_valid()); chassis_.mutable_wheel_speed()->set_wheel_direction_rr( chassis_detail.vehicle_spd().wheel_direction_rr()); chassis_.mutable_wheel_speed()->set_wheel_spd_rr( chassis_detail.vehicle_spd().wheel_spd_rr()); chassis_.mutable_wheel_speed()->set_is_wheel_spd_rl_valid( chassis_detail.vehicle_spd().is_wheel_spd_rl_valid()); chassis_.mutable_wheel_speed()->set_wheel_direction_rl( chassis_detail.vehicle_spd().wheel_direction_rl()); chassis_.mutable_wheel_speed()->set_wheel_spd_rl( chassis_detail.vehicle_spd().wheel_spd_rl()); chassis_.mutable_wheel_speed()->set_is_wheel_spd_fr_valid( chassis_detail.vehicle_spd().is_wheel_spd_fr_valid()); chassis_.mutable_wheel_speed()->set_wheel_direction_fr( chassis_detail.vehicle_spd().wheel_direction_fr()); chassis_.mutable_wheel_speed()->set_wheel_spd_fr( chassis_detail.vehicle_spd().wheel_spd_fr()); chassis_.mutable_wheel_speed()->set_is_wheel_spd_fl_valid( chassis_detail.vehicle_spd().is_wheel_spd_fl_valid()); chassis_.mutable_wheel_speed()->set_wheel_direction_fl( chassis_detail.vehicle_spd().wheel_direction_fl()); chassis_.mutable_wheel_speed()->set_wheel_spd_fl( chassis_detail.vehicle_spd().wheel_spd_fl()); } else { chassis_.set_speed_mps(0); } // 6 if (chassis_detail.has_basic() && chassis_detail.basic().has_odo_meter()) { // odo_meter is in km chassis_.set_odometer_m( static_cast<float>(chassis_detail.basic().odo_meter() * 1000.0)); } else { chassis_.set_odometer_m(0); } // 7 // lincoln only has fuel percentage // to avoid confusing, just don't set chassis_.set_fuel_range_m(0); // 8 if (chassis_detail.has_gas() && chassis_detail.gas().has_throttle_output()) { chassis_.set_throttle_percentage( static_cast<float>(chassis_detail.gas().throttle_output())); } else { chassis_.set_throttle_percentage(0); } // 9 if (chassis_detail.has_brake() && chassis_detail.brake().has_brake_output()) { chassis_.set_brake_percentage( static_cast<float>(chassis_detail.brake().brake_output())); } else { chassis_.set_brake_percentage(0); } // 23, previously 10 if (chassis_detail.has_gear() && chassis_detail.gear().has_gear_state()) { chassis_.set_gear_location(chassis_detail.gear().gear_state()); } else { chassis_.set_gear_location(Chassis::GEAR_NONE); } // 11 if (chassis_detail.has_eps() && chassis_detail.eps().has_steering_angle()) { chassis_.set_steering_percentage( static_cast<float>(chassis_detail.eps().steering_angle() * 100.0 / vehicle_params_.max_steer_angle() * M_PI / 180.0)); } else { chassis_.set_steering_percentage(0); } // 12 if (chassis_detail.has_eps() && chassis_detail.eps().has_epas_torque()) { chassis_.set_steering_torque_nm( static_cast<float>(chassis_detail.eps().epas_torque())); } else { chassis_.set_steering_torque_nm(0); } // 13 if (chassis_detail.has_eps() && chassis_detail.epb().has_parking_brake_status()) { chassis_.set_parking_brake(chassis_detail.epb().parking_brake_status() == Epb::PBRAKE_ON); } else { chassis_.set_parking_brake(false); } // 14, 15 if (chassis_detail.has_light() && chassis_detail.light().has_lincoln_lamp_type()) { chassis_.mutable_signal()->set_high_beam( chassis_detail.light().lincoln_lamp_type() == Light::BEAM_HIGH); } else { chassis_.mutable_signal()->set_high_beam(false); } // 16, 17 if (chassis_detail.has_light() && chassis_detail.light().has_turn_light_type() && chassis_detail.light().turn_light_type() != Light::TURN_LIGHT_OFF) { if (chassis_detail.light().turn_light_type() == Light::TURN_LEFT_ON) { chassis_.mutable_signal()->set_turn_signal( common::VehicleSignal::TURN_LEFT); } else if (chassis_detail.light().turn_light_type() == Light::TURN_RIGHT_ON) { chassis_.mutable_signal()->set_turn_signal( common::VehicleSignal::TURN_RIGHT); } else { chassis_.mutable_signal()->set_turn_signal( common::VehicleSignal::TURN_NONE); } } else { chassis_.mutable_signal()->set_turn_signal( common::VehicleSignal::TURN_NONE); } // 18 if (chassis_detail.has_light() && chassis_detail.light().has_is_horn_on() && chassis_detail.light().is_horn_on()) { chassis_.mutable_signal()->set_horn(true); } else { chassis_.mutable_signal()->set_horn(false); } // 19, lincoln wiper is too complicated // 24 if (chassis_detail.has_eps() && chassis_detail.eps().has_timestamp_65()) { chassis_.set_steering_timestamp(chassis_detail.eps().timestamp_65()); } // 26 if (chassis_error_mask_) { chassis_.set_chassis_error_mask(chassis_error_mask_); } // 6d, 6e, 6f, if gps valid is available, assume all gps related field // available if (chassis_detail.basic().has_gps_valid()) { chassis_.mutable_chassis_gps()->set_latitude( chassis_detail.basic().latitude()); chassis_.mutable_chassis_gps()->set_longitude( chassis_detail.basic().longitude()); chassis_.mutable_chassis_gps()->set_gps_valid( chassis_detail.basic().gps_valid()); chassis_.mutable_chassis_gps()->set_year(chassis_detail.basic().year()); chassis_.mutable_chassis_gps()->set_month(chassis_detail.basic().month()); chassis_.mutable_chassis_gps()->set_day(chassis_detail.basic().day()); chassis_.mutable_chassis_gps()->set_hours(chassis_detail.basic().hours()); chassis_.mutable_chassis_gps()->set_minutes( chassis_detail.basic().minutes()); chassis_.mutable_chassis_gps()->set_seconds( chassis_detail.basic().seconds()); chassis_.mutable_chassis_gps()->set_compass_direction( chassis_detail.basic().compass_direction()); chassis_.mutable_chassis_gps()->set_pdop(chassis_detail.basic().pdop()); chassis_.mutable_chassis_gps()->set_is_gps_fault( chassis_detail.basic().is_gps_fault()); chassis_.mutable_chassis_gps()->set_is_inferred( chassis_detail.basic().is_inferred()); chassis_.mutable_chassis_gps()->set_altitude( chassis_detail.basic().altitude()); chassis_.mutable_chassis_gps()->set_heading( chassis_detail.basic().heading()); chassis_.mutable_chassis_gps()->set_hdop(chassis_detail.basic().hdop()); chassis_.mutable_chassis_gps()->set_vdop(chassis_detail.basic().vdop()); chassis_.mutable_chassis_gps()->set_quality( chassis_detail.basic().quality()); chassis_.mutable_chassis_gps()->set_num_satellites( chassis_detail.basic().num_satellites()); chassis_.mutable_chassis_gps()->set_gps_speed( chassis_detail.basic().gps_speed()); } else { chassis_.mutable_chassis_gps()->set_gps_valid(false); } // VIN number will be written into KVDB once. if (chassis_detail.vehicle_id().has_vin()) { chassis_.mutable_vehicle_id()->set_vin(chassis_detail.vehicle_id().vin()); if (!received_vin_) { apollo::common::KVDB::Put("apollo:canbus:vin", chassis_detail.vehicle_id().vin()); received_vin_ = true; } } if (chassis_detail.has_surround()) { chassis_.mutable_surround()->CopyFrom(chassis_detail.surround()); } // Give engage_advice based on error_code and canbus feedback if (chassis_error_mask_ || chassis_.throttle_percentage() == 0.0 || chassis_.brake_percentage() == 0.0) { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::DISALLOW_ENGAGE); chassis_.mutable_engage_advice()->set_reason("Chassis error!"); } else if (chassis_.parking_brake() || CheckSafetyError(chassis_detail)) { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::DISALLOW_ENGAGE); chassis_.mutable_engage_advice()->set_reason( "Vehicle is not in a safe state to engage!"); } else { chassis_.mutable_engage_advice()->set_advice( apollo::common::EngageAdvice::READY_TO_ENGAGE); } return chassis_; } bool LincolnController::VerifyID() { return true; } void LincolnController::Emergency() { set_driving_mode(Chassis::EMERGENCY_MODE); ResetProtocol(); if (chassis_error_code() == Chassis::NO_ERROR) { set_chassis_error_code(Chassis::CHASSIS_ERROR); } } ErrorCode LincolnController::EnableAutoMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE) { AINFO << "Already in COMPLETE_AUTO_DRIVE mode"; return ErrorCode::OK; } brake_60_->set_enable(); throttle_62_->set_enable(); steering_64_->set_enable(); can_sender_->Update(); const int32_t flag = CHECK_RESPONSE_STEER_UNIT_FLAG | CHECK_RESPONSE_SPEED_UNIT_FLAG; if (!CheckResponse(flag, true)) { AERROR << "Failed to switch to COMPLETE_AUTO_DRIVE mode."; CheckChassisError(); Emergency(); return ErrorCode::CANBUS_ERROR; } set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE); AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok."; return ErrorCode::OK; } ErrorCode LincolnController::DisableAutoMode() { ResetProtocol(); can_sender_->Update(); set_driving_mode(Chassis::COMPLETE_MANUAL); set_chassis_error_code(Chassis::NO_ERROR); AINFO << "Switch to COMPLETE_MANUAL ok."; return ErrorCode::OK; } ErrorCode LincolnController::EnableSteeringOnlyMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE || driving_mode() == Chassis::AUTO_STEER_ONLY) { set_driving_mode(Chassis::AUTO_STEER_ONLY); AINFO << "Already in AUTO_STEER_ONLY mode"; return ErrorCode::OK; } brake_60_->set_disable(); throttle_62_->set_disable(); steering_64_->set_enable(); can_sender_->Update(); if (!CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, true)) { AERROR << "Failed to switch to AUTO_STEER_ONLY mode."; CheckChassisError(); Emergency(); return ErrorCode::CANBUS_ERROR; } set_driving_mode(Chassis::AUTO_STEER_ONLY); AINFO << "Switch to AUTO_STEER_ONLY mode ok."; return ErrorCode::OK; } ErrorCode LincolnController::EnableSpeedOnlyMode() { if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE || driving_mode() == Chassis::AUTO_SPEED_ONLY) { set_driving_mode(Chassis::AUTO_SPEED_ONLY); AINFO << "Already in AUTO_SPEED_ONLY mode"; return ErrorCode::OK; } brake_60_->set_enable(); throttle_62_->set_enable(); steering_64_->set_disable(); can_sender_->Update(); if (!CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, true)) { AERROR << "Failed to switch to AUTO_SPEED_ONLY mode."; CheckChassisError(); Emergency(); return ErrorCode::CANBUS_ERROR; } set_driving_mode(Chassis::AUTO_SPEED_ONLY); AINFO << "Switch to AUTO_SPEED_ONLY mode ok."; return ErrorCode::OK; } // NEUTRAL, REVERSE, DRIVE void LincolnController::Gear(Chassis::GearPosition ref_gear_position) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "This drive mode no need to set gear."; return; } Lincoln chassis_detail; message_manager_->GetSensorData(&chassis_detail); const Chassis::GearPosition current_gear_position = chassis_detail.gear().gear_state(); if (ref_gear_position == current_gear_position) { return; } // Need to request neutral gear first if current gear location is not neutral // or none if (ref_gear_position != current_gear_position && current_gear_position != Chassis::GEAR_NEUTRAL && current_gear_position != Chassis::GEAR_NONE) { gear_tmp_ = Chassis::GEAR_NEUTRAL; } else if (current_gear_position == Chassis::GEAR_NEUTRAL) { gear_tmp_ = ref_gear_position; } switch (gear_tmp_) { case Chassis::GEAR_NEUTRAL: { gear_66_->set_gear_neutral(); break; } case Chassis::GEAR_REVERSE: { gear_66_->set_gear_reverse(); break; } case Chassis::GEAR_DRIVE: { gear_66_->set_gear_drive(); break; } case Chassis::GEAR_PARKING: { gear_66_->set_gear_park(); break; } case Chassis::GEAR_LOW: { gear_66_->set_gear_low(); break; } case Chassis::GEAR_NONE: { gear_66_->set_gear_none(); break; } case Chassis::GEAR_INVALID: { AERROR << "Gear command is invalid!"; gear_66_->set_gear_none(); break; } default: { gear_66_->set_gear_none(); break; } } } // brake with new acceleration // acceleration:0.00~99.99, unit:% // acceleration:0.0 ~ 7.0, unit:m/s^2 // acceleration_spd:60 ~ 100, suggest: 90 // -> pedal void LincolnController::Brake(double pedal) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "The current drive mode does not need to set acceleration."; return; } brake_60_->set_pedal(pedal); } // drive with old acceleration // gas:0.00~99.99 unit:% void LincolnController::Throttle(double pedal) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "The current drive mode does not need to set acceleration."; return; } throttle_62_->set_pedal(pedal); } // drive with acceleration/deceleration // acc:-7.0 ~ 5.0, unit:m/s^2 void LincolnController::Acceleration(double acc) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_SPEED_ONLY) { AINFO << "The current drive mode does not need to set acceleration."; return; } // None } // lincoln default, -470 ~ 470, left:+, right:- // need to be compatible with control module, so reverse // steering with old angle speed // angle:-99.99~0.00~99.99, unit:%, left:-, right:+ void LincolnController::Steer(double angle) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_STEER_ONLY) { AINFO << "The current driving mode does not need to set steer."; return; } const double real_angle = vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0; // reverse sign steering_64_->set_steering_angle(real_angle)->set_steering_angle_speed(200); } // steering with new angle speed // angle:-99.99~0.00~99.99, unit:%, left:-, right:+ // angle_spd:0.00~99.99, unit:deg/s void LincolnController::Steer(double angle, double angle_spd) { if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE && driving_mode() != Chassis::AUTO_STEER_ONLY) { AINFO << "The current driving mode does not need to set steer."; return; } const double real_angle = vehicle_params_.max_steer_angle() / M_PI * 180 * angle / 100.0; const double real_angle_spd = ProtocolData<::apollo::canbus::Lincoln>::BoundedValue( vehicle_params_.min_steer_angle_rate() / M_PI * 180, vehicle_params_.max_steer_angle_rate() / M_PI * 180, vehicle_params_.max_steer_angle_rate() / M_PI * 180 * angle_spd / 100.0); steering_64_->set_steering_angle(real_angle) ->set_steering_angle_speed(real_angle_spd); } void LincolnController::SetEpbBreak(const ControlCommand &command) { if (command.parking_brake()) { // None } else { // None } } void LincolnController::SetBeam(const ControlCommand &command) { if (command.signal().high_beam()) { // None } else if (command.signal().low_beam()) { // None } else { // None } } void LincolnController::SetHorn(const ControlCommand &command) { if (command.signal().horn()) { // None } else { // None } } void LincolnController::SetTurningSignal(const ControlCommand &command) { // Set Turn Signal auto signal = command.signal().turn_signal(); if (signal == common::VehicleSignal::TURN_LEFT) { turnsignal_68_->set_turn_left(); } else if (signal == common::VehicleSignal::TURN_RIGHT) { turnsignal_68_->set_turn_right(); } else { turnsignal_68_->set_turn_none(); } } void LincolnController::ResetProtocol() { message_manager_->ResetSendMessages(); } bool LincolnController::CheckChassisError() { Lincoln chassis_detail; message_manager_->GetSensorData(&chassis_detail); int32_t error_cnt = 0; int32_t chassis_error_mask = 0; // Steer fault bool steer_fault = chassis_detail.eps().watchdog_fault() | chassis_detail.eps().channel_1_fault() | chassis_detail.eps().channel_2_fault() | chassis_detail.eps().calibration_fault() | chassis_detail.eps().connector_fault(); chassis_error_mask |= ((chassis_detail.eps().watchdog_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.eps().channel_1_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.eps().channel_2_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.eps().calibration_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.eps().connector_fault()) << (++error_cnt)); if (!chassis_detail.has_brake()) { AERROR_EVERY(100) << "Lincoln has NO brake." << chassis_detail.DebugString(); return false; } // Brake fault bool brake_fault = chassis_detail.brake().watchdog_fault() | chassis_detail.brake().channel_1_fault() | chassis_detail.brake().channel_2_fault() | chassis_detail.brake().boo_fault() | chassis_detail.brake().connector_fault(); chassis_error_mask |= ((chassis_detail.brake().watchdog_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.brake().channel_1_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.brake().channel_2_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.brake().boo_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.brake().connector_fault()) << (++error_cnt)); if (!chassis_detail.has_gas()) { AERROR_EVERY(100) << "Lincoln has NO gas." << chassis_detail.DebugString(); return false; } // Throttle fault bool throttle_fault = chassis_detail.gas().watchdog_fault() | chassis_detail.gas().channel_1_fault() | chassis_detail.gas().channel_2_fault() | chassis_detail.gas().connector_fault(); chassis_error_mask |= ((chassis_detail.gas().watchdog_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.gas().channel_1_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.gas().channel_2_fault()) << (++error_cnt)); chassis_error_mask |= ((chassis_detail.gas().connector_fault()) << (++error_cnt)); if (!chassis_detail.has_gear()) { AERROR_EVERY(100) << "Lincoln has NO gear." << chassis_detail.DebugString(); return false; } // Gear fault bool gear_fault = chassis_detail.gear().canbus_fault(); chassis_error_mask |= ((chassis_detail.gear().canbus_fault()) << (++error_cnt)); set_chassis_error_mask(chassis_error_mask); if (steer_fault) { set_chassis_error_code(Chassis::CHASSIS_ERROR_ON_STEER); AERROR_EVERY(100) << "Steering fault detected: " << chassis_detail.eps().watchdog_fault() << ", " << chassis_detail.eps().channel_1_fault() << ", " << chassis_detail.eps().channel_2_fault() << ", " << chassis_detail.eps().calibration_fault() << ", " << chassis_detail.eps().connector_fault(); } if (brake_fault) { set_chassis_error_code(Chassis::CHASSIS_ERROR_ON_BRAKE); AERROR_EVERY(100) << "Brake fault detected: " << chassis_detail.brake().watchdog_fault() << ", " << chassis_detail.brake().channel_1_fault() << ", " << chassis_detail.brake().channel_2_fault() << ", " << chassis_detail.brake().boo_fault() << ", " << chassis_detail.brake().connector_fault(); } if (throttle_fault) { set_chassis_error_code(Chassis::CHASSIS_ERROR_ON_THROTTLE); AERROR_EVERY(100) << "Throttle fault detected: " << chassis_detail.gas().watchdog_fault() << ", " << chassis_detail.gas().channel_1_fault() << ", " << chassis_detail.gas().channel_2_fault() << ", " << chassis_detail.gas().connector_fault(); } if (gear_fault) { set_chassis_error_code(Chassis::CHASSIS_ERROR_ON_GEAR); AERROR_EVERY(100) << "Gear fault detected: " << chassis_detail.gear().canbus_fault(); } if (steer_fault || brake_fault || throttle_fault) { return true; } return false; } void LincolnController::SecurityDogThreadFunc() { if (can_sender_ == nullptr) { AERROR << "Failed to run SecurityDogThreadFunc() because can_sender_ is " "nullptr."; return; } while (!can_sender_->IsRunning()) { std::this_thread::yield(); } std::chrono::duration<double, std::micro> default_period{50000}; int64_t start = cyber::Time::Now().ToMicrosecond(); int32_t speed_ctrl_fail = 0; int32_t steer_ctrl_fail = 0; while (can_sender_->IsRunning()) { const Chassis::DrivingMode mode = driving_mode(); bool emergency_mode = false; // 1. Steer control check if ((mode == Chassis::COMPLETE_AUTO_DRIVE || mode == Chassis::AUTO_STEER_ONLY) && !CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, false)) { ++steer_ctrl_fail; if (steer_ctrl_fail >= kMaxFailAttempt) { emergency_mode = true; set_chassis_error_code(Chassis::MANUAL_INTERVENTION); } } else { steer_ctrl_fail = 0; } // 2. Speed control check if ((mode == Chassis::COMPLETE_AUTO_DRIVE || mode == Chassis::AUTO_SPEED_ONLY) && !CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, false)) { ++speed_ctrl_fail; if (speed_ctrl_fail >= kMaxFailAttempt) { emergency_mode = true; set_chassis_error_code(Chassis::MANUAL_INTERVENTION); } } else { speed_ctrl_fail = 0; } if (CheckChassisError()) { emergency_mode = true; } if (emergency_mode && mode != Chassis::EMERGENCY_MODE) { Emergency(); } int64_t end = cyber::Time::Now().ToMicrosecond(); std::chrono::duration<double, std::micro> elapsed{end - start}; if (elapsed < default_period) { std::this_thread::sleep_for(default_period - elapsed); start = cyber::Time::Now().ToMicrosecond(); } else { AERROR_EVERY(100) << "Too much time consumption in LincolnController looping process:" << elapsed.count(); start = end; } } } bool LincolnController::CheckResponse(const int32_t flags, bool need_wait) { // for Lincoln, CheckResponse commonly takes 300ms. We leave a 100ms buffer // for it. int32_t retry_num = 20; Lincoln chassis_detail; bool is_eps_online = false; bool is_vcu_online = false; bool is_esp_online = false; do { if (message_manager_->GetSensorData(&chassis_detail) != ErrorCode::OK) { AERROR_EVERY(100) << "Get chassis detail failed."; return false; } bool check_ok = true; if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) { is_eps_online = chassis_detail.has_check_response() && chassis_detail.check_response().has_is_eps_online() && chassis_detail.check_response().is_eps_online(); check_ok = check_ok && is_eps_online; } if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) { is_vcu_online = chassis_detail.has_check_response() && chassis_detail.check_response().has_is_vcu_online() && chassis_detail.check_response().is_vcu_online(); is_esp_online = chassis_detail.has_check_response() && chassis_detail.check_response().has_is_esp_online() && chassis_detail.check_response().is_esp_online(); check_ok = check_ok && is_vcu_online && is_esp_online; } if (check_ok) { return true; } AINFO << "Need to check response again."; if (need_wait) { --retry_num; std::this_thread::sleep_for( std::chrono::duration<double, std::milli>(20)); } } while (need_wait && retry_num); AINFO << "check_response fail: is_eps_online:" << is_eps_online << ", is_vcu_online:" << is_vcu_online << ", is_esp_online:" << is_esp_online; return false; } void LincolnController::set_chassis_error_mask(const int32_t mask) { std::lock_guard<std::mutex> lock(chassis_mask_mutex_); chassis_error_mask_ = mask; } int32_t LincolnController::chassis_error_mask() { std::lock_guard<std::mutex> lock(chassis_mask_mutex_); return chassis_error_mask_; } Chassis::ErrorCode LincolnController::chassis_error_code() { std::lock_guard<std::mutex> lock(chassis_error_code_mutex_); return chassis_error_code_; } void LincolnController::set_chassis_error_code( const Chassis::ErrorCode &error_code) { std::lock_guard<std::mutex> lock(chassis_error_code_mutex_); chassis_error_code_ = error_code; } bool LincolnController::CheckSafetyError( const ::apollo::canbus::Lincoln &chassis_detail) { bool safety_error = chassis_detail.safety().is_passenger_door_open() || chassis_detail.safety().is_rearleft_door_open() || chassis_detail.safety().is_rearright_door_open() || chassis_detail.safety().is_hood_open() || chassis_detail.safety().is_trunk_open() || (chassis_detail.safety().is_passenger_detected() && (!chassis_detail.safety().is_passenger_airbag_enabled() || !chassis_detail.safety().is_passenger_buckled())); ADEBUG << "Vehicle safety error status is : " << safety_error; return safety_error; } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/testdata/mkz_canbus_conf_test.pb.txt
vehicle_parameter { brand: LINCOLN_MKZ max_enable_fail_attempt: 5 driving_mode: COMPLETE_AUTO_DRIVE } can_card_parameter { brand:SOCKET_CAN_RAW type: PCI_CARD channel_id: CHANNEL_ID_ZERO } enable_debug_mode: false
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/proto/lincoln.proto
syntax = "proto2"; package apollo.canbus; import "modules/common_msgs/basic_msgs/vehicle_id.proto"; import "modules/common_msgs/basic_msgs/geometry.proto"; import "modules/common_msgs/chassis_msgs/chassis.proto"; message Lincoln { enum Type { QIRUI_EQ_15 = 0; CHANGAN_RUICHENG = 1; } optional Type car_type = 1; // car type optional BasicInfo basic = 2; // basic info optional Safety safety = 3; // safety optional Gear gear = 4; // gear optional Ems ems = 5; // engine manager system optional Esp esp = 6; // Electronic Stability Program optional Gas gas = 7; // gas pedal optional Epb epb = 8; // Electronic parking brake optional Brake brake = 9; // brake pedal optional Deceleration deceleration = 10; // deceleration optional VehicleSpd vehicle_spd = 11; // vehicle speed optional Eps eps = 12; // Electronic Power Steering optional Light light = 13; // Light optional Battery battery = 14; // Battery info optional CheckResponseSignal check_response = 15; optional Surround surround = 17; // Surround information // Reserve fields for other vehicles optional apollo.common.VehicleID vehicle_id = 101; } // CheckResponseSignal message CheckResponseSignal { optional bool is_eps_online = 1 [default = false]; // byd:0x34C qirui:0x505 optional bool is_epb_online = 2 [default = false]; // byd:0x218 optional bool is_esp_online = 3 [default = false]; // byd:0x122 qirui:0x451 optional bool is_vtog_online = 4 [default = false]; // byd:0x242 optional bool is_scu_online = 5 [default = false]; // byd:0x35C optional bool is_switch_online = 6 [default = false]; // byd:0x133 optional bool is_vcu_online = 7 [default = false]; // qirui:0x400 } // Battery message Battery { optional double battery_percent = 1; // unit:%, battery percentage left // lincoln fuellevel 72 optional double fuel_level = 2; } // light message Light { enum TurnLightType { TURN_LIGHT_OFF = 0; TURN_LEFT_ON = 1; TURN_RIGHT_ON = 2; TURN_LIGHT_ON = 3; } enum BeamLampType { BEAM_OFF = 0; HIGH_BEAM_ON = 1; LOW_BEAM_ON = 2; } enum LincolnLampType { BEAM_NULL = 0; BEAM_FLASH_TO_PASS = 1; BEAM_HIGH = 2; BEAM_INVALID = 3; } enum LincolnWiperType { WIPER_OFF = 0; WIPER_AUTO_OFF = 1; WIPER_OFF_MOVING = 2; WIPER_MANUAL_OFF = 3; WIPER_MANUAL_ON = 4; WIPER_MANUAL_LOW = 5; WIPER_MANUAL_HIGH = 6; WIPER_MIST_FLICK = 7; WIPER_WASH = 8; WIPER_AUTO_LOW = 9; WIPER_AUTO_HIGH = 10; WIPER_COURTESY_WIPE = 11; WIPER_AUTO_ADJUST = 12; WIPER_RESERVED = 13; WIPER_STALLED = 14; WIPER_NO_DATA = 15; } enum LincolnAmbientType { AMBIENT_DARK = 0; AMBIENT_LIGHT = 1; AMBIENT_TWILIGHT = 2; AMBIENT_TUNNEL_ON = 3; AMBIENT_TUNNEL_OFF = 4; AMBIENT_INVALID = 5; AMBIENT_NO_DATA = 7; } optional TurnLightType turn_light_type = 1; optional BeamLampType beam_lamp_type = 2; optional bool is_brake_lamp_on = 3; // byd switch 133 optional bool is_auto_light = 4; optional int32 wiper_gear = 5; optional int32 lotion_gear = 6; optional bool is_horn_on = 7; // lincoln misc 69 optional LincolnLampType lincoln_lamp_type = 8; optional LincolnWiperType lincoln_wiper = 9; optional LincolnAmbientType lincoln_ambient = 10; } // Electrical Power Steering message Eps { enum Type { NOT_AVAILABLE = 0; READY = 1; ACTIVE = 2; INVALID = 3; } // changan: eps 2a0 optional bool is_eps_fail = 1; // eps 2a0 optional Type eps_control_state = 2; // for changan to control steering optional double eps_driver_hand_torq = 3; // unit:Nm optional bool is_steering_angle_valid = 4; optional double steering_angle = 5; // unit:degree optional double steering_angle_spd = 6; // unit:degree/s // byd sas 11f optional bool is_trimming_status = 7; optional bool is_calibration_status = 8; optional bool is_failure_status = 9; optional int32 allow_enter_autonomous_mode = 10; optional int32 current_driving_mode = 11; // lincoln steering 65 optional double steering_angle_cmd = 12; optional double vehicle_speed = 13; optional double epas_torque = 14; optional bool steering_enabled = 15; optional bool driver_override = 16; optional bool driver_activity = 17; optional bool watchdog_fault = 18; optional bool channel_1_fault = 19; optional bool channel_2_fault = 20; optional bool calibration_fault = 21; optional bool connector_fault = 22; optional double timestamp_65 = 23; // lincoln version 7f optional int32 major_version = 24; optional int32 minor_version = 25; optional int32 build_number = 26; } message VehicleSpd { // esp 277 optional bool is_vehicle_standstill = 1; // esp 218 optional bool is_vehicle_spd_valid = 2; optional double vehicle_spd = 3 [default = 0]; // unit:m/s // esp 208 optional bool is_wheel_spd_rr_valid = 4; optional WheelSpeed.WheelSpeedType wheel_direction_rr = 5; optional double wheel_spd_rr = 6; optional bool is_wheel_spd_rl_valid = 7; optional WheelSpeed.WheelSpeedType wheel_direction_rl = 8; optional double wheel_spd_rl = 9; optional bool is_wheel_spd_fr_valid = 10; optional WheelSpeed.WheelSpeedType wheel_direction_fr = 11; optional double wheel_spd_fr = 12; optional bool is_wheel_spd_fl_valid = 13; optional WheelSpeed.WheelSpeedType wheel_direction_fl = 14; optional double wheel_spd_fl = 15; // byd esp 222 optional bool is_yaw_rate_valid = 16; optional double yaw_rate = 17; optional double yaw_rate_offset = 18; // byd esp 223 optional bool is_ax_valid = 19; optional double ax = 20; optional double ax_offset = 21; optional bool is_ay_valid = 22; optional double ay = 23; optional double ay_offset = 24; // lincoln accel 6b optional double lat_acc = 25; optional double long_acc = 26; optional double vert_acc = 27; // lincoln gyro 6c optional double roll_rate = 28; // lincoln brakeinfo 74 optional double acc_est = 29; // lincoln wheelspeed 6a optional double timestamp_sec = 30; } message Deceleration { // esp 277 optional bool is_deceleration_available = 1; // for changan to send deceleration value optional bool is_deceleration_active = 2; // for changan to send deceleration value optional double deceleration = 3 [default = 0]; optional double is_evb_fail = 4; optional double evb_pressure = 5 [default = 0]; // mpa, 0~25.5 optional double brake_pressure = 6 [default = 0]; optional double brake_pressure_spd = 7 [default = 0]; } message Brake { enum HSAStatusType { HSA_INACTIVE = 0; HSA_FINDING_GRADIENT = 1; HSA_ACTIVE_PRESSED = 2; HSA_ACTIVE_RELEASED = 3; HSA_FAST_RELEASE = 4; HSA_SLOW_RELEASE = 5; HSA_FAILED = 6; HSA_UNDEFINED = 7; } enum HSAModeType { HSA_OFF = 0; HSA_AUTO = 1; HSA_MANUAL = 2; HSA_MODE_UNDEFINED = 3; } // ems 255 optional bool is_brake_pedal_pressed = 1 [default = false]; // only manual brake // esp 277 optional bool is_brake_force_exist = 2; // no matter auto mode brake or manual brake optional bool is_brake_over_heat = 3; optional bool is_hand_brake_on = 4; // hand brake optional double brake_pedal_position = 5; // byd vtog 342 optional bool is_brake_valid = 6; // lincoln brake 61 optional double brake_input = 7; optional double brake_cmd = 8; optional double brake_output = 9; optional bool boo_input = 10; optional bool boo_cmd = 11; optional bool boo_output = 12; optional bool watchdog_applying_brakes = 13; optional int32 watchdog_source = 14; optional bool brake_enabled = 15; optional bool driver_override = 16; optional bool driver_activity = 17; optional bool watchdog_fault = 18; optional bool channel_1_fault = 19; optional bool channel_2_fault = 20; optional bool boo_fault = 21; optional bool connector_fault = 22; // lincoln brakeinfo 74 optional double brake_torque_req = 23; optional HSAStatusType hsa_status = 24; optional double brake_torque_act = 25; optional HSAModeType hsa_mode = 26; optional double wheel_torque_act = 27; // lincoln version 7f optional int32 major_version = 28; optional int32 minor_version = 29; optional int32 build_number = 30; } // Electrical Parking Brake message Epb { enum PBrakeType { PBRAKE_OFF = 0; PBRAKE_TRANSITION = 1; PBRAKE_ON = 2; PBRAKE_FAULT = 3; } // epb 256 optional bool is_epb_error = 1; optional bool is_epb_released = 2; // byd epb 218 optional int32 epb_status = 3; // lincoln brakeinfo 74 optional PBrakeType parking_brake_status = 4; } message Gas { // ems 255 optional bool is_gas_pedal_error = 1; // ems 26a optional bool is_gas_pedal_pressed_more = 2; // more than auto mode gas torq optional double gas_pedal_position = 3 [default = 0]; // manual gas // byd vtog 342 optional bool is_gas_valid = 4 [default = false]; // lincoln throttle 63 optional double throttle_input = 5; optional double throttle_cmd = 6; optional double throttle_output = 7; optional int32 watchdog_source = 8; optional bool throttle_enabled = 9; optional bool driver_override = 10; optional bool driver_activity = 11; optional bool watchdog_fault = 12; optional bool channel_1_fault = 13; optional bool channel_2_fault = 14; optional bool connector_fault = 15; // lincoln throttleinfo 75 optional double accelerator_pedal = 16; optional double accelerator_pedal_rate = 17; // lincoln version 7f optional int32 major_version = 18; optional int32 minor_version = 19; optional int32 build_number = 20; } // Electronic Stability Program message Esp { // esp 277 optional bool is_esp_acc_error = 1; // for changan to control car // esp 218 optional bool is_esp_on = 2; optional bool is_esp_active = 3; optional bool is_abs_error = 4; optional bool is_abs_active = 5; optional bool is_tcsvdc_fail = 6; // lincoln brakeinfo 74 optional bool is_abs_enabled = 7; optional bool is_stab_active = 8; optional bool is_stab_enabled = 9; optional bool is_trac_active = 10; optional bool is_trac_enabled = 11; } // Engine Manager System message Ems { enum Type { STOP = 0; CRANK = 1; RUNNING = 2; INVALID = 3; } // ems 26a optional bool is_engine_acc_available = 1; // for changan to control car optional bool is_engine_acc_error = 2; // for changan to control car // ems 265 optional Type engine_state = 3; optional double max_engine_torq_percent = 4; // for engine torq control, unit:% optional double min_engine_torq_percent = 5; // for engine torq control, unit:% optional int32 base_engine_torq_constant = 6; // for engine torq control, unit:Nm // ems 255 optional bool is_engine_speed_error = 7; optional double engine_speed = 8; // byd vtog 241 optional int32 engine_torque = 9; // byd vtog 242 optional bool is_over_engine_torque = 10; // lincoln mkz throttleinfo 75 optional double engine_rpm = 11; } message Gear { // tcu 268 optional bool is_shift_position_valid = 1; // chanan: tcu 268 optional Chassis.GearPosition gear_state = 2; // lincoln gear 67 optional bool driver_override = 3; optional Chassis.GearPosition gear_cmd = 4; optional bool canbus_fault = 5; } message Safety { // ip 270 optional bool is_driver_car_door_close = 1; // sas 50 optional bool is_driver_buckled = 2; // byd sws 4a8 optional int32 emergency_button = 3; // qirui:403 // when car chassis error, like system fault, or warning report optional bool has_error = 4 [default = false]; optional bool is_motor_invertor_fault = 5; optional bool is_system_fault = 6; optional bool is_power_battery_fault = 7; optional bool is_motor_invertor_over_temperature = 8; optional bool is_small_battery_charge_discharge_fault = 9; optional int32 driving_mode = 10; // lincoln misc 69 optional bool is_passenger_door_open = 11; optional bool is_rearleft_door_open = 12; optional bool is_rearright_door_open = 13; optional bool is_hood_open = 14; optional bool is_trunk_open = 15; optional bool is_passenger_detected = 16; optional bool is_passenger_airbag_enabled = 17; optional bool is_passenger_buckled = 18; // lincoln tirepressure 71 optional int32 front_left_tire_press = 19; optional int32 front_right_tire_press = 20; optional int32 rear_left_tire_press = 21; optional int32 rear_right_tire_press = 22; optional DrivingMode car_driving_mode = 23; } enum DrivingMode { COMPLETE_MANUAL = 0; // human drive COMPLETE_AUTO_DRIVE = 1; AUTO_STEER_ONLY = 2; // only steer AUTO_SPEED_ONLY = 3; // include throttle and brake // security mode when manual intervention happens, only response status EMERGENCY_MODE = 4; } message BasicInfo { enum Type { OFF = 0; ACC = 1; ON = 2; START = 3; INVALID = 4; } optional bool is_auto_mode = 1; optional Type power_state = 2; optional bool is_air_bag_deployed = 3; optional double odo_meter = 4; // odo meter, unit:km optional double drive_range = 5; // the meter left when drive continuously, unit:km optional bool is_system_error = 6; optional bool is_human_interrupt = 7; // human interrupt // lincoln misc 69 optional bool acc_on_button = 8; // acc on button pressed optional bool acc_off_button = 9; optional bool acc_res_button = 10; optional bool acc_cancel_button = 11; optional bool acc_on_off_button = 12; optional bool acc_res_cancel_button = 13; optional bool acc_inc_spd_button = 14; optional bool acc_dec_spd_button = 15; optional bool acc_inc_gap_button = 16; optional bool acc_dec_gap_button = 17; optional bool lka_button = 18; optional bool canbus_fault = 19; // lincoln gps 6d optional double latitude = 20; optional double longitude = 21; optional bool gps_valid = 22; // lincoln gps 6e optional int32 year = 23; optional int32 month = 24; optional int32 day = 25; optional int32 hours = 26; optional int32 minutes = 27; optional int32 seconds = 28; optional double compass_direction = 29; optional double pdop = 30; optional bool is_gps_fault = 31; optional bool is_inferred = 32; // lincoln gps 6f optional double altitude = 33; optional double heading = 34; optional double hdop = 35; optional double vdop = 36; optional GpsQuality quality = 37; optional int32 num_satellites = 38; optional double gps_speed = 39; }
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/proto/BUILD
## Auto generated by `proto_build_generator.py` load("@rules_proto//proto:defs.bzl", "proto_library") load("@rules_cc//cc:defs.bzl", "cc_proto_library") load("//tools:python_rules.bzl", "py_proto_library") package(default_visibility = ["//visibility:public"]) cc_proto_library( name = "lincoln_cc_proto", deps = [ ":lincoln_proto", ], ) proto_library( name = "lincoln_proto", srcs = ["lincoln.proto"], deps = [ "//modules/common_msgs/basic_msgs:geometry_proto", "//modules/common_msgs/basic_msgs:vehicle_id_proto", "//modules/common_msgs/chassis_msgs:chassis_proto", ] ) py_proto_library( name = "lincoln_py_pb2", deps = [ ":lincoln_proto", ], )
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/turnsignal_68_test.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/protocol/turnsignal_68.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { TEST(Turnsignal68Test, General) { uint8_t data[8] = {0x67, 0x62, 0x63, 0x64, 0x51, 0x52, 0x53, 0x54}; Turnsignal68 turn_signal; EXPECT_EQ(turn_signal.GetPeriod(), 50 * 1000); EXPECT_EQ(turn_signal.turn_cmd(), 0); turn_signal.UpdateData(data); EXPECT_EQ(data[0], 0b01100100); EXPECT_EQ(data[1], 0b01100010); EXPECT_EQ(data[2], 0b01100011); EXPECT_EQ(data[3], 0b01100100); EXPECT_EQ(data[4], 0b01010001); EXPECT_EQ(data[5], 0b01010010); EXPECT_EQ(data[6], 0b01010011); EXPECT_EQ(data[7], 0b01010100); EXPECT_EQ(turn_signal.turn_cmd(), 0); turn_signal.set_turn_none(); EXPECT_EQ(turn_signal.turn_cmd(), 0x00); turn_signal.set_turn_left(); EXPECT_EQ(turn_signal.turn_cmd(), 0x01); turn_signal.set_turn_right(); EXPECT_EQ(turn_signal.turn_cmd(), 0x02); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gear_66.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/protocol/gear_66.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; // public const int32_t Gear66::ID = 0x66; uint32_t Gear66::GetPeriod() const { // on event, so value nonsense static const uint32_t PERIOD = 10 * 1000; return PERIOD; } void Gear66::UpdateData(uint8_t *data) { set_gear_p(data, gear_); set_clear_driver_override_flag_p(data); } void Gear66::Reset() { gear_ = 0; } Gear66 *Gear66::set_gear_none() { gear_ = 0x00; return this; } Gear66 *Gear66::set_gear_park() { gear_ = 0x01; return this; } Gear66 *Gear66::set_gear_reverse() { gear_ = 0x02; return this; } Gear66 *Gear66::set_gear_neutral() { gear_ = 0x03; return this; } Gear66 *Gear66::set_gear_drive() { gear_ = 0x04; return this; } Gear66 *Gear66::set_gear_low() { gear_ = 0x05; return this; } // private void Gear66::set_gear_p(uint8_t *data, int32_t gear) { gear = ProtocolData::BoundedValue(0, 5, gear); Byte frame(data); frame.set_value(static_cast<uint8_t>(gear), 0, 3); } void Gear66::set_clear_driver_override_flag_p(uint8_t *bytes) { Byte frame(bytes); frame.set_bit_0(7); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/turnsignal_68.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/protocol/turnsignal_68.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Turnsignal68::ID = 0x68; uint32_t Turnsignal68::GetPeriod() const { static const uint32_t PERIOD = 50 * 1000; return PERIOD; } int32_t Turnsignal68::turn_cmd() const { return turn_cmd_; } void Turnsignal68::UpdateData(uint8_t *data) { set_turn_cmd_p(data, turn_cmd_); } void Turnsignal68::Reset() { turn_cmd_ = 0; } Turnsignal68 *Turnsignal68::set_turn_none() { turn_cmd_ = 0x00; return this; } Turnsignal68 *Turnsignal68::set_turn_left() { turn_cmd_ = 0x01; return this; } Turnsignal68 *Turnsignal68::set_turn_right() { turn_cmd_ = 0x02; return this; } // 0x03 not used // private void Turnsignal68::set_turn_cmd_p(uint8_t *data, int32_t turn_cmd) { turn_cmd = ProtocolData::BoundedValue(0, 3, turn_cmd); Byte frame(data + 0); frame.set_value(static_cast<uint8_t>(turn_cmd), 0, 2); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gps_6d.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/protocol/gps_6d.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Gps6d::ID = 0x6D; void Gps6d::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { chassis_detail->mutable_basic()->set_latitude(latitude(bytes, length)); chassis_detail->mutable_basic()->set_longitude(longitude(bytes, length)); chassis_detail->mutable_basic()->set_gps_valid(is_valid(bytes, length)); } double Gps6d::latitude(const std::uint8_t *bytes, int32_t length) const { Byte frame_0(bytes + 3); int32_t value = frame_0.get_byte(0, 7); Byte frame_1(bytes + 2); int32_t t = frame_1.get_byte(0, 8); value <<= 8; value |= t; Byte frame_2(bytes + 1); t = frame_2.get_byte(0, 8); value <<= 8; value |= t; Byte frame_3(bytes); t = frame_3.get_byte(0, 8); value <<= 8; value |= t; if (value > 0x3FFFFFFF) { value -= 0x80000000; } return value * (1.000000 / 3.000000) * 1e-6; } double Gps6d::longitude(const std::uint8_t *bytes, int32_t length) const { Byte frame_0(bytes + 7); int32_t value = frame_0.get_byte(0, 7); Byte frame_1(bytes + 6); int32_t t = frame_1.get_byte(0, 8); value <<= 8; value |= t; Byte frame_2(bytes + 5); t = frame_2.get_byte(0, 8); value <<= 8; value |= t; Byte frame_3(bytes + 4); t = frame_3.get_byte(0, 8); value <<= 8; value |= t; if (value > 0x3FFFFFFF) { value -= 0x80000000; } return value * (1.000000 / 3.000000) * 1e-6; } bool Gps6d::is_valid(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 7); return frame.is_bit_1(7); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/gps_6f.h
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ /** * @file gps_6f.h * @brief the class of Gps6f (for lincoln vehicle) */ #pragma once #include "modules/canbus_vehicle/lincoln/proto/lincoln.pb.h" #include "modules/drivers/canbus/can_comm/protocol_data.h" /** * @namespace apollo::canbus::lincoln * @brief apollo::canbus::lincoln */ namespace apollo { namespace canbus { namespace lincoln { /** * @class Gps6f * * @brief one of the protocol data of lincoln vehicle */ class Gps6f : public ::apollo::drivers::canbus::ProtocolData< ::apollo::canbus::Lincoln> { public: static const int32_t ID; /* * @brief parse received data * @param bytes a pointer to the input bytes * @param length the length of the input bytes * @param timestamp the timestamp of input data * @param chassis_detail the parsed chassis_detail */ virtual void Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const; /** * @brief get altitude from byte array * config detail: {'name': 'altitude', 'offset': 0.0, 'precision': 0.25, * 'len': 16, 'f_type': 'value', 'is_signed_var': True, 'physical_range': * '[0|0]', 'bit': 0, 'type': 'double', 'order': 'intel', 'physical_unit': * '"m"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of altitude */ double altitude(const std::uint8_t *bytes, int32_t length) const; /** * @brief get heading from byte array * config detail: {'name': 'heading', 'offset': 0.0, 'precision': 0.01, 'len': * 16, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 16, 'type': 'double', 'order': 'intel', 'physical_unit': * '"degrees"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of heading */ double heading(const std::uint8_t *bytes, int32_t length) const; /** * @brief get speed from byte array * config detail: {'name': 'speed', 'offset': 0.0, 'precision': 1.0, 'len': 8, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': '"mph"'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of speed */ int32_t speed(const std::uint8_t *bytes, int32_t length) const; /** * @brief get hdop from byte array * config detail: {'name': 'hdop', 'offset': 0.0, 'precision': 0.2, 'len': 5, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 40, 'type': 'double', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of hdop */ double hdop(const std::uint8_t *bytes, int32_t length) const; /** * @brief get vdop from byte array * config detail: {'name': 'vdop', 'offset': 0.0, 'precision': 0.2, 'len': 5, * 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 48, 'type': 'double', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of vdop */ double vdop(const std::uint8_t *bytes, int32_t length) const; /** * @brief get fix quality from byte array * config detail: {'name': 'quality', 'offset': 0.0, 'precision': 1.0, 'len': * 3, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 56, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the value of fix quality */ int32_t fix_quality(const std::uint8_t *bytes, int32_t length) const; /** * @brief get number of satellites from byte array * config detail: {'name': 'numsat', 'offset': 0.0, 'precision': 1.0, 'len': * 5, 'f_type': 'value', 'is_signed_var': False, 'physical_range': '[0|0]', * 'bit': 59, 'type': 'int', 'order': 'intel', 'physical_unit': '""'} * @param bytes a pointer to the byte array * @param length the length of the byte array * @return the number of satellites */ int32_t num_satellites(const std::uint8_t *bytes, int32_t length) const; }; } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/misc_69.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/protocol/misc_69.h" #include "modules/drivers/canbus/common/byte.h" namespace apollo { namespace canbus { namespace lincoln { using ::apollo::drivers::canbus::Byte; const int32_t Misc69::ID = 0x69; void Misc69::Parse(const std::uint8_t *bytes, int32_t length, Lincoln *chassis_detail) const { int32_t turn_light_type = turn_signal_status(bytes, length); switch (turn_light_type) { case 0: chassis_detail->mutable_light()->set_turn_light_type( Light::TURN_LIGHT_OFF); break; case 1: chassis_detail->mutable_light()->set_turn_light_type(Light::TURN_LEFT_ON); break; case 2: chassis_detail->mutable_light()->set_turn_light_type( Light::TURN_RIGHT_ON); break; case 3: break; default: break; } int32_t hi_beam_status = high_beam_status(bytes, length); switch (hi_beam_status) { case 0: chassis_detail->mutable_light()->set_lincoln_lamp_type(Light::BEAM_NULL); break; case 1: chassis_detail->mutable_light()->set_lincoln_lamp_type( Light::BEAM_FLASH_TO_PASS); break; case 2: chassis_detail->mutable_light()->set_lincoln_lamp_type(Light::BEAM_HIGH); break; case 3: default: chassis_detail->mutable_light()->set_lincoln_lamp_type( Light::BEAM_INVALID); break; } // wiper status, non-compatible int32_t wiper = wiper_status(bytes, length); switch (wiper) { case 0: chassis_detail->mutable_light()->set_lincoln_wiper(Light::WIPER_OFF); break; case 1: chassis_detail->mutable_light()->set_lincoln_wiper(Light::WIPER_AUTO_OFF); break; case 2: chassis_detail->mutable_light()->set_lincoln_wiper( Light::WIPER_OFF_MOVING); break; case 3: chassis_detail->mutable_light()->set_lincoln_wiper( Light::WIPER_MANUAL_OFF); break; case 4: chassis_detail->mutable_light()->set_lincoln_wiper( Light::WIPER_MANUAL_ON); break; case 5: chassis_detail->mutable_light()->set_lincoln_wiper( Light::WIPER_MANUAL_LOW); break; case 6: chassis_detail->mutable_light()->set_lincoln_wiper( Light::WIPER_MANUAL_HIGH); break; case 7: chassis_detail->mutable_light()->set_lincoln_wiper( Light::WIPER_MIST_FLICK); break; case 8: chassis_detail->mutable_light()->set_lincoln_wiper(Light::WIPER_WASH); break; case 9: chassis_detail->mutable_light()->set_lincoln_wiper(Light::WIPER_AUTO_LOW); break; case 10: chassis_detail->mutable_light()->set_lincoln_wiper( Light::WIPER_AUTO_HIGH); break; case 11: chassis_detail->mutable_light()->set_lincoln_wiper( Light::WIPER_COURTESY_WIPE); break; case 12: chassis_detail->mutable_light()->set_lincoln_wiper( Light::WIPER_AUTO_ADJUST); break; case 13: chassis_detail->mutable_light()->set_lincoln_wiper(Light::WIPER_RESERVED); break; case 14: chassis_detail->mutable_light()->set_lincoln_wiper(Light::WIPER_STALLED); break; case 15: chassis_detail->mutable_light()->set_lincoln_wiper(Light::WIPER_NO_DATA); break; } int32_t ambient = ambient_light_status(bytes, length); switch (ambient) { case 0: chassis_detail->mutable_light()->set_lincoln_ambient(Light::AMBIENT_DARK); break; case 1: chassis_detail->mutable_light()->set_lincoln_ambient( Light::AMBIENT_LIGHT); break; case 2: chassis_detail->mutable_light()->set_lincoln_ambient( Light::AMBIENT_TWILIGHT); break; case 3: chassis_detail->mutable_light()->set_lincoln_ambient( Light::AMBIENT_TUNNEL_ON); break; case 4: chassis_detail->mutable_light()->set_lincoln_ambient( Light::AMBIENT_TUNNEL_OFF); break; case 7: chassis_detail->mutable_light()->set_lincoln_ambient( Light::AMBIENT_NO_DATA); break; default: chassis_detail->mutable_light()->set_lincoln_ambient( Light::AMBIENT_INVALID); break; } // acc button related chassis_detail->mutable_basic()->set_acc_on_button( is_acc_on_pressed(bytes, length)); chassis_detail->mutable_basic()->set_acc_off_button( is_acc_off_pressed(bytes, length)); chassis_detail->mutable_basic()->set_acc_res_button( is_acc_resume_pressed(bytes, length)); chassis_detail->mutable_basic()->set_acc_cancel_button( is_acc_cancel_pressed(bytes, length)); chassis_detail->mutable_basic()->set_acc_on_off_button( is_acc_on_or_off_pressed(bytes, length)); chassis_detail->mutable_basic()->set_acc_res_cancel_button( is_acc_resume_or_cancel_pressed(bytes, length)); chassis_detail->mutable_basic()->set_acc_inc_spd_button( is_acc_increment_set_speed_pressed(bytes, length)); chassis_detail->mutable_basic()->set_acc_dec_spd_button( is_acc_decrement_set_speed_pressed(bytes, length)); chassis_detail->mutable_basic()->set_acc_inc_gap_button( is_acc_increment_following_gap_pressed(bytes, length)); chassis_detail->mutable_basic()->set_acc_dec_gap_button( is_acc_decrement_following_gap_pressed(bytes, length)); chassis_detail->mutable_basic()->set_lka_button( is_lka_on_or_off_pressed(bytes, length)); chassis_detail->mutable_basic()->set_canbus_fault( is_canbus_fault(bytes, length)); // driver door if (is_driver_door_open(bytes, length)) { chassis_detail->mutable_safety()->set_is_driver_car_door_close(false); } else { chassis_detail->mutable_safety()->set_is_driver_car_door_close(true); } chassis_detail->mutable_safety()->set_is_passenger_door_open( is_passenger_door_open(bytes, length)); chassis_detail->mutable_safety()->set_is_rearleft_door_open( is_rear_left_door_open(bytes, length)); chassis_detail->mutable_safety()->set_is_rearright_door_open( is_rear_right_door_open(bytes, length)); chassis_detail->mutable_safety()->set_is_hood_open( is_hood_open(bytes, length)); chassis_detail->mutable_safety()->set_is_trunk_open( is_trunk_open(bytes, length)); chassis_detail->mutable_safety()->set_is_passenger_detected( is_passenger_detected(bytes, length)); chassis_detail->mutable_safety()->set_is_passenger_airbag_enabled( is_passenger_airbag_enabled(bytes, length)); // airbag ? driver airbag? // chassis_detail->mutable_basic()->set_is_air_bag_deployed( // is_passenger_airbag_enabled(bytes, length)); // driver buckled chassis_detail->mutable_safety()->set_is_driver_buckled( is_driver_belt_buckled(bytes, length)); chassis_detail->mutable_safety()->set_is_passenger_buckled( is_passenger_belt_buckled(bytes, length)); // has error?, non-compatible // chassis_detail->mutable_safety()->set_has_error( // is_canbus_fault(bytes, length)); } int32_t Misc69::turn_signal_status(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); int32_t x = frame.get_byte(0, 2); return x; } int32_t Misc69::high_beam_status(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); int32_t x = frame.get_byte(2, 2); return x; } int32_t Misc69::wiper_status(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 0); int32_t x = frame.get_byte(4, 4); return x; } int32_t Misc69::ambient_light_status(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 1); int32_t x = frame.get_byte(0, 3); return x; } bool Misc69::is_acc_on_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 1); return frame.is_bit_1(3); } bool Misc69::is_acc_off_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 1); return frame.is_bit_1(4); } bool Misc69::is_acc_resume_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 1); return frame.is_bit_1(5); } bool Misc69::is_acc_cancel_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 1); return frame.is_bit_1(6); } bool Misc69::is_acc_on_or_off_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); return frame.is_bit_1(0); } bool Misc69::is_acc_resume_or_cancel_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); return frame.is_bit_1(1); } bool Misc69::is_acc_increment_set_speed_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); return frame.is_bit_1(2); } bool Misc69::is_acc_decrement_set_speed_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); return frame.is_bit_1(3); } bool Misc69::is_acc_increment_following_gap_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); return frame.is_bit_1(4); } bool Misc69::is_acc_decrement_following_gap_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); return frame.is_bit_1(5); } bool Misc69::is_lka_on_or_off_pressed(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); return frame.is_bit_1(6); } bool Misc69::is_canbus_fault(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 2); return frame.is_bit_1(7); } bool Misc69::is_driver_door_open(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); return frame.is_bit_1(0); } bool Misc69::is_passenger_door_open(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); return frame.is_bit_1(1); } bool Misc69::is_rear_left_door_open(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); return frame.is_bit_1(2); } bool Misc69::is_rear_right_door_open(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); return frame.is_bit_1(3); } bool Misc69::is_hood_open(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); return frame.is_bit_1(4); } bool Misc69::is_trunk_open(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); return frame.is_bit_1(5); } bool Misc69::is_passenger_detected(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); return frame.is_bit_1(6); } bool Misc69::is_passenger_airbag_enabled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 3); return frame.is_bit_1(7); } bool Misc69::is_driver_belt_buckled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 4); return frame.is_bit_1(0); } bool Misc69::is_passenger_belt_buckled(const std::uint8_t *bytes, int32_t length) const { Byte frame(bytes + 4); return frame.is_bit_1(1); } } // namespace lincoln } // namespace canbus } // namespace apollo
0
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln
apollo_public_repos/apollo/modules/canbus_vehicle/lincoln/protocol/brake_60_test.cc
/****************************************************************************** * Copyright 2017 The Apollo Authors. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * 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. *****************************************************************************/ #include "modules/canbus_vehicle/lincoln/protocol/brake_60.h" #include "gtest/gtest.h" namespace apollo { namespace canbus { namespace lincoln { class Brake60Test : public ::testing::Test { public: virtual void SetUp() {} }; TEST_F(Brake60Test, simple) { Brake60 brake; EXPECT_EQ(brake.GetPeriod(), 10 * 1000); uint8_t data[8] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68}; brake.UpdateData(data); EXPECT_EQ(data[0], 0b00000000); EXPECT_EQ(data[1], 0b00000000); EXPECT_EQ(data[2], 0b01100010); EXPECT_EQ(data[3], 0b01100100); EXPECT_EQ(data[4], 0b01100101); EXPECT_EQ(data[5], 0b01100110); EXPECT_EQ(data[6], 0b01100111); EXPECT_EQ(data[7], 0b00000000); } } // namespace lincoln } // namespace canbus } // namespace apollo
0