9 from leo_msgs.msg
import Imu, WheelStates
10 from geometry_msgs.msg
import Twist
11 from std_msgs.msg
import Float32
12 from .utils
import write_flush
13 from .board
import BoardType, determine_board, check_firmware_version
14 from .utils
import CSIColor, parse_yaml
31 is_new_battery_data = 0
35 wheel_data = WheelStates()
36 battery_data = Float32()
44 self.
cmd_vel_pub = rospy.Publisher(
"cmd_vel", Twist, queue_size=1)
46 "firmware/wheel_FL/cmd_pwm_duty", Float32, queue_size=1
49 "firmware/wheel_RL/cmd_pwm_duty", Float32, queue_size=1
52 "firmware/wheel_FR/cmd_pwm_duty", Float32, queue_size=1
55 "firmware/wheel_RR/cmd_pwm_duty", Float32, queue_size=1
58 "firmware/wheel_FL/cmd_velocity", Float32, queue_size=1
61 "firmware/wheel_RL/cmd_velocity", Float32, queue_size=1
64 "firmware/wheel_FR/cmd_velocity", Float32, queue_size=1
67 "firmware/wheel_RR/cmd_velocity", Float32, queue_size=1
103 and self.
wheel_data.velocity[1] < -speed_limit
105 and self.
wheel_data.velocity[3] < -speed_limit
113 print(CSIColor.OKGREEN +
"LOAD" + CSIColor.ENDC)
115 print(CSIColor.OKGREEN +
"UNLOAD" + CSIColor.ENDC)
124 is_error_tab = [0, 0, 0, 0]
131 for wheel_test
in wheel_valid[
"tests"]:
137 rospy.sleep(wheel_test[
"time"])
139 speed_min = wheel_test[
"velocity"] - wheel_test[
"offset"]
140 speed_max = wheel_test[
"velocity"] + wheel_test[
"offset"]
142 for i
in range(0, 4):
143 if not speed_min < self.
wheel_data.velocity[i] < speed_max:
153 error_msg =
"ERROR WHEEL ENCODER "
154 error_msg += str(is_error_tab)
155 print(CSIColor.FAIL + error_msg + CSIColor.ENDC)
158 print(CSIColor.OKGREEN +
"PASSED" + CSIColor.ENDC)
163 is_error_tab = [0, 0, 0, 0]
170 for torque_test
in torque_valid[
"tests"]:
176 rospy.sleep(torque_test[
"time"])
178 torque_min = torque_test[
"torque"]
179 torque_max = torque_test[
"torque"] + 1
181 for i
in range(0, 4):
182 if not torque_min < self.
wheel_data.torque[i] < torque_max:
192 error_msg =
"ERROR WHEEL TORQUE "
193 error_msg += str(is_error_tab)
194 print(CSIColor.FAIL + error_msg + CSIColor.ENDC)
197 print(CSIColor.OKGREEN +
"PASSED" + CSIColor.ENDC)
202 time_now = time.time()
205 accel_del = imu_valid[
"imu"][
"accel_del"]
206 accel_x = imu_valid[
"imu"][
"accel_x"]
207 accel_y = imu_valid[
"imu"][
"accel_y"]
208 accel_z = imu_valid[
"imu"][
"accel_z"]
210 gyro_del = imu_valid[
"imu"][
"gyro_del"]
211 gyro_x = imu_valid[
"imu"][
"gyro_x"]
212 gyro_y = imu_valid[
"imu"][
"gyro_y"]
213 gyro_z = imu_valid[
"imu"][
"gyro_z"]
216 if time_now + imu_valid[
"imu"][
"timeout"] < time.time():
217 print(CSIColor.WARNING +
"TIMEOUT" + CSIColor.ENDC)
221 time_now = time.time()
226 accel_x - accel_del < self.
imu_data.accel_x < accel_x + accel_del
227 and accel_y - accel_del
229 < accel_y + accel_del
230 and accel_z - accel_del
232 < accel_z + accel_del
233 and gyro_x - gyro_del < self.
imu_data.gyro_x < gyro_x + gyro_del
234 and gyro_y - gyro_del < self.
imu_data.gyro_y < gyro_y + gyro_del
235 and gyro_z - gyro_del < self.
imu_data.gyro_z < gyro_z + gyro_del
237 print(CSIColor.FAIL +
"INVALID DATA" + CSIColor.ENDC)
240 print(CSIColor.OKGREEN +
"PASSED" + CSIColor.ENDC)
245 time_now = time.time()
249 if time_now + batt_valid[
"battery"][
"timeout"] < time.time():
250 print(CSIColor.WARNING +
"TIMEOUT" + CSIColor.ENDC)
254 time_now = time.time()
258 if self.
battery_data.data <= batt_valid[
"battery"][
"voltage_min"]:
259 print(CSIColor.FAIL +
"LOW VOLTAGE" + CSIColor.ENDC)
261 if self.
battery_data.data >= batt_valid[
"battery"][
"voltage_max"]:
262 print(CSIColor.FAIL +
"HIGH VOLTAGE" + CSIColor.ENDC)
265 print(CSIColor.OKGREEN +
"PASSED" + CSIColor.ENDC)
271 hardware: TestMode = TestMode.ALL,
273 write_flush(
"--> Checking if rosserial node is active.. ")
275 if rospy.resolve_name(
"serial_node")
in rosnode.get_node_names():
277 serial_node_active =
True
280 serial_node_active =
False
282 "Rosserial node is not active. "
283 "Will not be able to validate hardware."
284 "Try to restart leo.service or reboot system."
288 if serial_node_active:
289 write_flush(
"--> Trying to determine board type.. ")
293 if board_type
is not None:
298 current_firmware_version =
"<unknown>"
300 if serial_node_active:
301 write_flush(
"--> Trying to check the current firmware version.. ")
305 if current_firmware_version !=
"<unknown>":
310 if current_firmware_version ==
"<unknown>" or board_type
is None:
312 "Can not determine firmware version or board type. "
313 "Flash firmware and try to rerun the script"
317 if serial_node_active:
319 rospy.init_node(
"leo_core_validation", anonymous=
True)
322 print(f
"Firmware version: {current_firmware_version}")
323 if board_type == BoardType.CORE2:
324 print(f
"Board type: Core2ROS")
325 elif board_type == BoardType.LEOCORE:
326 print(f
"Board type: LeoCore")
328 print(f
"Can not determine board version")
331 if hardware
in (TestMode.ALL, TestMode.BATTERY):
335 if hardware
in (TestMode.ALL, TestMode.IMU)
and board_type == BoardType.LEOCORE:
339 if hardware
in (TestMode.ALL, TestMode.TORQUE, TestMode.ENCODER):
343 if hardware
in (TestMode.ALL, TestMode.ENCODER):
348 hardware
in (TestMode.ALL, TestMode.TORQUE)
349 and board_type == BoardType.LEOCORE