From: Jérémie D. <Ba...@us...> - 2011-06-06 17:16:06
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 5448c6c59e14ca827106721dd5da9bc189952a6a (commit) via 1f60ccac92bf4c5f4597967b7e9d773334a90f63 (commit) via f380ee8973895face4d5b2295fb0a4e135eda780 (commit) via ea1a197d8eeec4d917b127bdba6742423df9cab7 (commit) via 9da6a855b7370e34be331b77e0d6760349b5e18a (commit) via 9dbb59a3e7a35fe6c6f64ddf17916b6274ec2517 (commit) via 1a049cd04a302b1113d8f5adf4107a1547103a12 (commit) via 58fb6c64e33a183f0b6028fbe244a0452e70458c (commit) via 9ec7d0af2555087d2114180cdb3a3bc04266660d (commit) via 49f90e1ad727f5aa40a543f013b533f010e86c2b (commit) via c500a6d35431f4d3eb8ae13350acb8840ffdcc62 (commit) via 6a58ff4e127d43b98d4c1f234d85aeea2ba8bd76 (commit) via 14b0879b2e34bfd343d1a069e680190bdae2953f (commit) via 293297b22b18781349744a0ac794ab8445a81779 (commit) via 8620279d6c6599c37ae0e51e9b85457495ea8dde (commit) via 8b6cca05ed5c410de10241fb12bf87e73321f5b2 (commit) via 51a2b998f311f37d80faa1a6e3154ec59fb78fd8 (commit) via f996695c754fadf4a5ab183549f73e8d7adeaf1d (commit) via a60c1722847b46333113b4824b7776aa87936a9a (commit) via 06dc02a7d39cd1bbef4d6841097135f41a064971 (commit) via b95e2ac49537041b9fe76bf1db69a2c26ccc7cfe (commit) via 2c975f20991be791d7e86dced5fc182c4287d7f0 (commit) via c28241399972b072537bae9c73a19b999ace17be (commit) via 06392258468fa1238e3555db960cd75b09a28e81 (commit) via e349d8f7e8a74cb7436f9e292180c7b12c210f69 (commit) via 752ea3cb1fbadd518d490e725a127eff6ead49f2 (commit) via fdf21325685b6d202aa167d559ae502d76bb65e1 (commit) via 59373c990c400c44f3214d1ff2e43b3a5b01a708 (commit) via 1d95af89a718001da9a730643476e8215b2548c9 (commit) via d7edbd72e9edfd86072f4ea657ed95cca0c816ee (commit) via 6e293aee63a51caa184477fa263a876bafa1f71f (commit) via 5be42dcf5fd15446cbaea97c894117afe32d6f33 (commit) via 276b192e754122dbc1b84c2b80ca0290b8901d84 (commit) via 3d7abff0b47dfc753b022e807926319c234f60d2 (commit) via 2eba87a8645c11f9aad9c4605f7ebe63dfc3ad4d (commit) via 62378cac5d536830654e5d132b0581ddf680de46 (commit) via b3f3a19d35c2e91ada6035f1cf7c77fa45948c6a (commit) via c19e9d21d23a0a7102db38745c8673a718a9a9bc (commit) from 617b3078e3af5ed2d37e4a380167ef65d924f3ab (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 5448c6c59e14ca827106721dd5da9bc189952a6a Author: Nicolas Dandrimont <Nic...@cr...> Date: Fri Jun 3 08:56:52 2011 +0200 [Sensor_Actuator] Fix AX-12 Torque Enable commit 1f60ccac92bf4c5f4597967b7e9d773334a90f63 Author: chambart <cha...@cr...> Date: Fri Jun 3 07:04:19 2011 +0200 [info] start of krobot_run commit f380ee8973895face4d5b2295fb0a4e135eda780 Author: chambart <cha...@cr...> Date: Thu Jun 2 22:34:29 2011 +0200 [control] correct some factors in beacon, hack to stop when seeing beacon commit ea1a197d8eeec4d917b127bdba6742423df9cab7 Author: Nicolas Dandrimont <Nic...@cr...> Date: Fri Jun 3 02:21:47 2011 +0200 [info/control2011] Disable AX-12 reset and enable AX-12 set torque enable commit 9da6a855b7370e34be331b77e0d6760349b5e18a Author: Nicolas Dandrimont <Nic...@cr...> Date: Fri Jun 3 02:09:42 2011 +0200 [Sensor_Actuator] Add an AX-12 torque enable CAN message. commit 9dbb59a3e7a35fe6c6f64ddf17916b6274ec2517 Author: Olivier BICHLER <oli...@gm...> Date: Thu Jun 2 22:25:14 2011 +0200 [Sensor Actuator] New calibration data commit 1a049cd04a302b1113d8f5adf4107a1547103a12 Author: chambart <cha...@cr...> Date: Thu Jun 2 20:43:54 2011 +0200 [info] correct successive back curves commit 58fb6c64e33a183f0b6028fbe244a0452e70458c Author: Olivier BICHLER <oli...@gm...> Date: Thu Jun 2 17:51:58 2011 +0200 [Sensor Actuator] Enable buzzer alarm in Battery Monitoring commit 9ec7d0af2555087d2114180cdb3a3bc04266660d Author: Nicolas Dandrimont <Nic...@cr...> Date: Thu Jun 2 17:26:18 2011 +0200 [Sensor_Actuator] Add a firmware allowing AX12 resets on the STM32-P103 board Plug the AX12 data wire on the 3rd pin of the UEXT1 port commit 49f90e1ad727f5aa40a543f013b533f010e86c2b Author: Nicolas Dandrimont <Nic...@cr...> Date: Thu Jun 2 17:25:46 2011 +0200 [Sensor_Actuator] Working AX12 protocol commit c500a6d35431f4d3eb8ae13350acb8840ffdcc62 Author: chambart <cha...@cr...> Date: Thu Jun 2 17:32:21 2011 +0200 [vision] detect imbricated ellipses commit 6a58ff4e127d43b98d4c1f234d85aeea2ba8bd76 Author: chambart <cha...@cr...> Date: Thu Jun 2 14:55:33 2011 +0200 [vision] add camfilter_edge commit 14b0879b2e34bfd343d1a069e680190bdae2953f Author: Jérémie Dimino <je...@di...> Date: Thu Jun 2 14:34:21 2011 +0200 [krobot_pathfinding] fix check_point commit 293297b22b18781349744a0ac794ab8445a81779 Author: Jérémie Dimino <je...@di...> Date: Thu Jun 2 12:29:05 2011 +0200 [krobot_homo] handle the jack commit 8620279d6c6599c37ae0e51e9b85457495ea8dde Author: Jérémie Dimino <je...@di...> Date: Thu Jun 2 12:18:49 2011 +0200 [info] fix smart goto commit 8b6cca05ed5c410de10241fb12bf87e73321f5b2 Author: chambart <cha...@cr...> Date: Thu Jun 2 11:43:37 2011 +0200 [info] pathfinding don't give nan when it is in invalid situation commit 51a2b998f311f37d80faa1a6e3154ec59fb78fd8 Author: Jérémie Dimino <je...@di...> Date: Thu Jun 2 09:52:10 2011 +0200 [krobot_hub] better handling of errors commit f996695c754fadf4a5ab183549f73e8d7adeaf1d Author: Nicolas Dandrimont <Nic...@cr...> Date: Thu Jun 2 09:48:48 2011 +0200 [control2011] Update the Sensor_Actuator board messages commit a60c1722847b46333113b4824b7776aa87936a9a Author: Jérémie Dimino <je...@di...> Date: Thu Jun 2 08:31:36 2011 +0200 [info] add commands for the elevators commit 06dc02a7d39cd1bbef4d6841097135f41a064971 Author: Jérémie Dimino <je...@di...> Date: Thu Jun 2 08:02:07 2011 +0200 [info] start homologuation program commit b95e2ac49537041b9fe76bf1db69a2c26ccc7cfe Author: Nicolas Dandrimont <Nic...@cr...> Date: Thu Jun 2 09:28:03 2011 +0200 [Sensor_Actuator] Add AX-12 processing commit 2c975f20991be791d7e86dced5fc182c4287d7f0 Author: Nicolas Dandrimont <Nic...@cr...> Date: Thu Jun 2 05:25:56 2011 +0200 [meca] Support de balise plus épais commit c28241399972b072537bae9c73a19b999ace17be Author: Xavier Lagorce <Xav...@cr...> Date: Thu Jun 2 08:28:34 2011 +0200 [Controller_Motor_STM32/Effectors] Added can messages for lift command commit 06392258468fa1238e3555db960cd75b09a28e81 Author: Xavier Lagorce <Xav...@cr...> Date: Thu Jun 2 04:20:10 2011 +0200 [Controller_Motor_STM32/Effectors] Refactored lift_controller code. Now uses homing for bottom and up. commit e349d8f7e8a74cb7436f9e292180c7b12c210f69 Merge: 6e293aee63a51caa184477fa263a876bafa1f71f 752ea3cb1fbadd518d490e725a127eff6ead49f2 Author: Stephane Glondu <st...@gl...> Date: Thu Jun 2 03:43:20 2011 +0200 Merge remote-tracking branch 'eeepc/master' commit 752ea3cb1fbadd518d490e725a127eff6ead49f2 Author: Olivier BICHLER <oli...@gm...> Date: Thu Jun 2 03:24:22 2011 +0200 [Sensor_Actuator] Fixes and additions by bibiche. commit fdf21325685b6d202aa167d559ae502d76bb65e1 Author: Nicolas Dandrimont <Nic...@cr...> Date: Wed Jun 1 17:42:12 2011 +0200 [Sensor_Actuator] Update switch config commit 59373c990c400c44f3214d1ff2e43b3a5b01a708 Author: Nicolas Dandrimont <Nic...@cr...> Date: Wed Jun 1 17:41:34 2011 +0200 [Sensor_Actuator] CAN configuration commit 1d95af89a718001da9a730643476e8215b2548c9 Author: Xavier Lagorce <Xav...@cr...> Date: Thu Jun 2 03:06:48 2011 +0200 [Controller_Motor_STM32/Effectors] Initial import of working lift controller code commit d7edbd72e9edfd86072f4ea657ed95cca0c816ee Author: Xavier Lagorce <Xav...@cr...> Date: Thu Jun 2 02:41:49 2011 +0200 [Controller_Motor_STM32/Propulsion_Drive] Prevent Bezier curve parameter to be bigger than 1 commit 6e293aee63a51caa184477fa263a876bafa1f71f Author: chambart <cha...@cr...> Date: Thu Jun 2 00:45:39 2011 +0200 [vision] beginning opencv ocaml binding commit 5be42dcf5fd15446cbaea97c894117afe32d6f33 Author: Jérémie Dimino <je...@di...> Date: Thu Jun 2 00:08:12 2011 +0200 [info] add Krobot_path commit 276b192e754122dbc1b84c2b80ca0290b8901d84 Author: Jérémie Dimino <je...@di...> Date: Wed Jun 1 22:56:13 2011 +0200 [krobot_webcam] add a fourth parameter to krobot-find-objects commit 3d7abff0b47dfc753b022e807926319c234f60d2 Author: Jérémie Dimino <je...@di...> Date: Wed Jun 1 22:55:04 2011 +0200 [vision] add parsing of the homography matrix commit 2eba87a8645c11f9aad9c4605f7ebe63dfc3ad4d Author: Jérémie Dimino <je...@di...> Date: Wed Jun 1 22:37:04 2011 +0200 [info] add a service to convert raw sharps data commit 62378cac5d536830654e5d132b0581ddf680de46 Author: Jérémie Dimino <je...@di...> Date: Wed Jun 1 22:18:00 2011 +0200 [info] add a program to calibrate the sharps commit b3f3a19d35c2e91ada6035f1cf7c77fa45948c6a Author: Jérémie Dimino <je...@di...> Date: Wed Jun 1 19:52:08 2011 +0200 [krobot_planner] fix smart goto commit c19e9d21d23a0a7102db38745c8673a718a9a9bc Author: Jérémie Dimino <je...@di...> Date: Wed Jun 1 18:25:01 2011 +0200 [krobot_planner] handle the beacon in trajectory planning ----------------------------------------------------------------------- Changes: diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_messages.h b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_messages.h index 81a44c2..3fe2b50 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_messages.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_messages.h @@ -32,6 +32,7 @@ #define CAN_MSG_CONTROLLER_MODE 205 // controller_mode_can_msg_t #define CAN_MSG_BEZIER_ADD 206 // bezier_can_msg_t +#define CAN_MSG_LIFT_CMD 231 // lift_cmd_msg_t /* +-----------------------------------------------------------------+ | CAN messages data structures | +-----------------------------------------------------------------+ */ @@ -107,6 +108,11 @@ typedef struct { uint8_t mode; } controller_mode_msg_t; +// Lift command position, a value is ignored if < 0 +typedef struct { + float front_lift __attribute__((__packed__)); + float back_lift __attribute__((__packed__)); +} lift_cmd_msg_t; /* +-----------------------------------------------------------------+ | CAN messages unions for data representation | @@ -162,5 +168,9 @@ typedef union { uint32_t data32[2]; } controller_mode_can_msg_t; +typedef union { + lift_cmd_msg_t data; + uint32_t data32[2]; +} lift_cmd_can_msg_t; #endif /* __CAN_MESSAGES_H */ diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_messages_sensors.h b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_messages_sensors.h new file mode 100644 index 0000000..512077e --- /dev/null +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_messages_sensors.h @@ -0,0 +1,154 @@ +/** + * Sensor-Actuator board messages + * + * Header file for the Sensor and Actuator CAN messages + * + * Copyright © 2011 Nicolas Dandrimont <ol...@cr...> + * Authors: Nicolas Dandrimont <ol...@cr...> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +#ifndef CAN_MESSAGES_H__ +#define CAN_MESSAGES_H__ + +/** + * Message IDs + */ + +// Beacon + +#define CAN_BEACON_POSITION 301 // beacon_position +#define CAN_BEACON_LOWLEVEL_POSITION 302 // beacon_lowlevel_position +#define CAN_BEACON_CALIBRATION 303 // beacon_calibration + +// Switches + +#define CAN_SWITCH_STATUS_1 311 // switch_status +#define CAN_SWITCH_STATUS_2 312 // switch_status +#define CAN_SWITCH_SET 313 // switch_request + + +// ADC + +#define CAN_ADC_VALUES_1 321 // adc_values +#define CAN_ADC_VALUES_2 322 // adc_values + + +/****************************************************************************/ + +/** + * Message Packets + */ + +/** + * Beacon messages + */ + +// Position of the opponent +struct beacon_position_pkt { + uint16_t angle; // in 1/10000th of radians [0; 2*Pi[ + uint16_t distance; // in mm [0; 65536[ + uint16_t period; // in 1/10000th of seconds [0; 1[ +} __attribute__((packed)); + + + +// Beacon low-level position +struct beacon_lowlevel_position_pkt { + uint16_t angle; // in 1/10000th of radians [0; 2*Pi[ + uint16_t width; // in 1/100000th of radians [0; Pi/5[ + uint32_t period; // in timer ticks +} __attribute__((packed)); + + + +// Beacon calibration +struct beacon_calibration_pkt { + uint16_t width; // in 1/100000th of radians [0; Pi/5[ + uint16_t distance; // in mm [0; 65536[ +} __attribute__((packed)); + + +/** + * Switch messages + */ + +// Switch status +struct switch_status_pkt { + uint8_t sw1; + uint8_t sw2; + uint8_t sw3; + uint8_t sw4; + uint8_t sw5; + uint8_t sw6; + uint8_t sw7; + uint8_t sw8; +}; + +// Switch request +struct switch_request_pkt { + uint8_t num; + uint8_t state; +}; + +/** + * ADC messages + */ +// ADC Values +struct adc_values_pkt { + uint16_t val1; + uint16_t val2; + uint16_t val3; + uint16_t val4; +} __attribute__((packed)); + +/****************************************************************************/ + +/** + * Typedefs + */ + +typedef union { + struct beacon_position_pkt p; + uint32_t d[2]; +} beacon_position; + +typedef union { + struct beacon_lowlevel_position_pkt p; + uint32_t d[2]; +} beacon_lowlevel_position; + +typedef union { + struct beacon_calibration_pkt p; + uint32_t d[2]; +} beacon_calibration; + +typedef union { + struct switch_status_pkt p; + uint32_t d[2]; +} switch_status; + +typedef union { + struct switch_request_pkt p; + uint32_t d[2]; +} switch_request; + +typedef union { + struct adc_values_pkt p; + uint32_t d[2]; +} adc_values; + +#endif diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_monitor.c b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_monitor.c index c8bcb2b..43913c8 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_monitor.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_monitor.c @@ -45,13 +45,7 @@ void canMonitorInit(void) { static void NORETURN canMonitor_process(void) { encoder_can_msg_t msg_enc; - motor_can_msg_t msg_mot; - odometry_can_msg_t msg_odo; - ghost_can_msg_t msg_ghost; - status_can_msg_t status_msg; can_tx_frame txm; - robot_state_t odometry; - float u; Timer timer_can; // Initialize constant parameters of TX frame @@ -77,63 +71,6 @@ static void NORETURN canMonitor_process(void) { txm.eid = CAN_MSG_ENCODERS34; can_transmit(CAND1, &txm, ms_to_ticks(10)); - // Sending odometry data if not in HIL mode or motor commands if in HIL mode - /*if (mode != ROBOT_MODE_HIL) { - odo_getState(&odometry); - msg_odo.data.x = (int16_t)(odometry.x * 1000.0); - msg_odo.data.y = (int16_t)(odometry.y * 1000.0); - odometry.theta = fmodf(odometry.theta, 2*M_PI); - if (odometry.theta > M_PI) - odometry.theta -= 2*M_PI; - if (odometry.theta < -M_PI) - odometry.theta += 2*M_PI; - msg_odo.data.theta = (int16_t)(odometry.theta * 10000.0); - - txm.data32[0] = msg_odo.data32[0]; - txm.data32[1] = msg_odo.data32[1]; - txm.eid = CAN_MSG_ODOMETRY; - can_transmit(CAND1, &txm, ms_to_ticks(10)); - } else { - // Sending MOTOR3 data - msg_mot.data.position = mc_getPosition(MOTOR3); - msg_mot.data.speed = mc_getSpeed(MOTOR3); - - txm.data32[0] = msg_mot.data32[0]; - txm.data32[1] = msg_mot.data32[1]; - txm.eid = CAN_MSG_MOTOR3; - can_transmit(CAND1, &txm, ms_to_ticks(10)); - - // Sending MOTOR4 data - msg_mot.data.position = mc_getPosition(MOTOR4); - msg_mot.data.speed = mc_getSpeed(MOTOR4); - - txm.data32[0] = msg_mot.data32[0]; - txm.data32[1] = msg_mot.data32[1]; - txm.eid = CAN_MSG_MOTOR4; - can_transmit(CAND1, &txm, ms_to_ticks(10)); - } - - // Wait before sending the other packets - timer_waitEvent(&timer_can); - timer_add(&timer_can);*/ - - // Sending ghost state - /*msg_ghost.data.state = dd_get_ghost_state(&odometry, &u); - msg_ghost.data.x = (int16_t)(odometry.x * 1000.0); - msg_ghost.data.y = (int16_t)(odometry.y * 1000.0); - msg_ghost.data.theta = (int16_t)(odometry.theta * 10000.0); - msg_ghost.data.u = (uint8_t)(u * 255); - txm.data32[0] = msg_ghost.data32[0]; - txm.data32[1] = msg_ghost.data32[1]; - txm.eid = CAN_MSG_GHOST; - can_transmit(CAND1, &txm, ms_to_ticks(10)); - - status_msg.data.is_moving = tc_is_working(MOTOR1 | MOTOR2 | MOTOR3 | MOTOR4); - txm.data32[0] = status_msg.data32[0]; - txm.data32[1] = status_msg.data32[1]; - txm.eid = CAN_MSG_STATUS; - can_transmit(CAND1, &txm, ms_to_ticks(10));*/ - // Wait for the next transmission timer timer_waitEvent(&timer_can); } @@ -144,14 +81,12 @@ static void NORETURN canMonitorListen_process(void) { can_rx_frame frame; bool received = false; can_tx_frame txm; - robot_state_t odometry; + uint8_t end_stops; - move_can_msg_t move_msg; - turn_can_msg_t turn_msg; - odometry_can_msg_t odometry_msg; - stop_can_msg_t stop_msg; - controller_mode_can_msg_t controller_mode_msg; - bezier_can_msg_t bezier_msg; + //controller_mode_can_msg_t controller_mode_msg; + + switch_status end_courses_msg; + lift_cmd_can_msg_t lift_cmd_msg; // Initialize constant parameters of TX frame txm.dlc = 8; @@ -171,50 +106,7 @@ static void NORETURN canMonitorListen_process(void) { } else { // Handle commands and other informations switch (frame.eid) { - case CAN_MSG_MOVE: - move_msg.data32[0] = frame.data32[0]; - move_msg.data32[1] = frame.data32[1]; - if (!tc_is_working(TC_MASK(DD_LINEAR_SPEED_TC) | TC_MASK(DD_ROTATIONAL_SPEED_TC))) - dd_move(move_msg.data.distance / 1000.0, move_msg.data.speed / 1000.0, move_msg.data.acceleration / 1000.0); - break; - case CAN_MSG_TURN: - turn_msg.data32[0] = frame.data32[0]; - turn_msg.data32[1] = frame.data32[1]; - if (!tc_is_working(TC_MASK(DD_LINEAR_SPEED_TC) | TC_MASK(DD_ROTATIONAL_SPEED_TC))) - dd_turn(turn_msg.data.angle / 10000.0, turn_msg.data.speed / 1000.0, turn_msg.data.acceleration / 1000.0); - break; - case CAN_MSG_BEZIER_ADD: - bezier_msg.data32[0] = frame.data32[0]; - bezier_msg.data32[1] = frame.data32[1]; - dd_add_bezier(bezier_msg.data.x_end/1000.0, bezier_msg.data.y_end/1000.0, - bezier_msg.data.d1/100.0, bezier_msg.data.d2/100.0, - bezier_msg.data.theta_end/100.0, bezier_msg.data.v_end/1000.0); - break; - case CAN_MSG_STOP: - stop_msg.data32[0] = frame.data32[0]; - stop_msg.data32[1] = frame.data32[1]; - dd_interrupt_trajectory(stop_msg.data.rot_acc, stop_msg.data.lin_acc); - break; - case CAN_MSG_ODOMETRY_SET: - odometry_msg.data32[0] = frame.data32[0]; - odometry_msg.data32[1] = frame.data32[1]; - odometry.x = ((float)odometry_msg.data.x) / 1000.0; - odometry.y = ((float)odometry_msg.data.y) / 1000.0; - odometry.theta = ((float)odometry_msg.data.theta) / 10000.0; - odo_setState(&odometry); - break; - case CAN_MSG_ODOMETRY: - // We should only receive such message in HIL mode - if (mode == ROBOT_MODE_HIL) { - odometry_msg.data32[0] = frame.data32[0]; - odometry_msg.data32[1] = frame.data32[1]; - odometry.x = ((float)odometry_msg.data.x) / 1000.0; - odometry.y = ((float)odometry_msg.data.y) / 1000.0; - odometry.theta = ((float)odometry_msg.data.theta) / 10000.0; - odo_setState(&odometry); - } - break; - case CAN_MSG_CONTROLLER_MODE: + /*case CAN_MSG_CONTROLLER_MODE: controller_mode_msg.data32[0] = frame.data32[0]; controller_mode_msg.data32[1] = frame.data32[0]; if (controller_mode_msg.data.mode == 1) { @@ -228,6 +120,27 @@ static void NORETURN canMonitorListen_process(void) { odo_restart(); mode = ROBOT_MODE_NORMAL; } + break;*/ + case CAN_SWITCH_STATUS_1: + end_courses_msg.d[0] = frame.data32[0]; + end_courses_msg.d[1] = frame.data32[1]; + end_stops = 0; + if (!end_courses_msg.p.sw3) + end_stops |= LC_BACK_BOTTOM; + if (!end_courses_msg.p.sw4) + end_stops |= LC_BACK_UP; + lc_end_stop_reached(end_stops); + //if (end_courses_msg.p.sw1) { + // lc_release(); + // motorSetSpeed(MOTOR2,0); + break; + case CAN_MSG_LIFT_CMD: + lift_cmd_msg.data32[0] = frame.data32[0]; + lift_cmd_msg.data32[1] = frame.data32[1]; + if (lift_cmd_msg.data.front_lift >= 0) + lc_goto_position(LC_FRONT_LIFT, lift_cmd_msg.data.front_lift); + if (lift_cmd_msg.data.back_lift >= 0) + lc_goto_position(LC_BACK_LIFT, lift_cmd_msg.data.back_lift); break; } } diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_monitor.h b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_monitor.h index da6ad7f..c55f124 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_monitor.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/can_monitor.h @@ -19,6 +19,8 @@ #include "odometry.h" #include "differential_drive.h" #include "can_messages.h" +#include "can_messages_sensors.h" +#include "lift_controller.h" void canMonitorInit(void); diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/controller_motor_stm32_user.mk b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/controller_motor_stm32_user.mk index bd55ecc..56ea826 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/controller_motor_stm32_user.mk +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/controller_motor_stm32_user.mk @@ -20,6 +20,7 @@ controller_motor_stm32_USER_CSRC = \ $(controller_motor_stm32_SRC_PATH)/bezier_utils.c \ $(controller_motor_stm32_SRC_PATH)/differential_drive.c \ $(controller_motor_stm32_SRC_PATH)/can_monitor.c \ + $(controller_motor_stm32_SRC_PATH)/lift_controller.c \ $(controller_motor_stm32_SRC_PATH)/main.c \ # diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/differential_drive.c b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/differential_drive.c index 179db7f..b566a84 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/differential_drive.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/differential_drive.c @@ -252,14 +252,14 @@ command_generator_t* dd_get_right_wheel_generator(void) { void dd_move(float distance, float speed, float acceleration) { if (params.enabled) { params.last_lin_acceleration = acceleration; - tc_goto(DD_LINEAR_SPEED_TC, distance, speed, params.last_lin_acceleration); + tc_move(DD_LINEAR_SPEED_TC, distance, speed, params.last_lin_acceleration); } } void dd_turn(float angle, float speed, float acceleration) { if (params.enabled) { params.last_rot_acceleration = acceleration; - tc_goto(DD_ROTATIONAL_SPEED_TC, angle, speed, params.last_rot_acceleration); + tc_move(DD_ROTATIONAL_SPEED_TC, angle, speed, params.last_rot_acceleration); } } diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/lift_controller.c b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/lift_controller.c new file mode 100644 index 0000000..56cb686 --- /dev/null +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/lift_controller.c @@ -0,0 +1,139 @@ +/* + * lift_controller.c + * ----------------- + * Copyright : (c) 2011, Xavier Lagorce <Xav...@cr...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + */ + +#include "lift_controller.h" + +#define DIR_UP 0 +#define DIR_DOWN 1 + +typedef struct { + uint8_t enabled, tc_ind; + int8_t direction; + float bottom, extend; + uint8_t end_stop_ind; +} lc_state_t; + +lc_state_t lc_state[2]; + +float pos2angle(uint8_t lift, float position); + +float pos2angle(uint8_t lift, float position) { + + //return lc_state[lift].offset - position / 23.474; + return lc_state[lift].bottom + lc_state[lift].extend*position; +} + +void lc_init(void) { + motor_controller_params_t params; + int i; + + // Init state + for (i=0; i<2; i++) { + lc_state[i].enabled = 1; + lc_state[i].direction = -1; + lc_state[i].bottom = 0; + lc_state[i].extend = 0; + lc_state[i].end_stop_ind = 0; + } + lc_state[LC_FRONT_LIFT].tc_ind = LC_TC_FRONT; + lc_state[LC_BACK_LIFT].tc_ind = LC_TC_BACK; + + // Init Trajectory controllers + tc_new_controller(LC_TC_FRONT); + tc_new_controller(LC_TC_BACK); + // Limit PWM value + motorSetMaxPWM(MOTOR3, 1600); + motorSetMaxPWM(MOTOR4, 1600); + // Common parameters + params.encoder_gain = 2.0*M_PI/588.0; + params.G0 = 0.0035; + params.tau = 0.025; + params.k[0] = -10216; + params.k[1] = -255.39; + params.l = -params.k[0]; + params.l0[0] = 0.0091; + params.l0[1] = 1.6361; + params.T = 0.005; + // Initialize front lift + params.motor = MOTOR4; + params.encoder = ENCODER4; + mc_new_controller(¶ms, tc_get_position_generator(LC_TC_FRONT), CONTROLLER_MODE_NORMAL); + // Initialize back lift + params.motor = MOTOR3; + params.encoder = ENCODER3; + mc_new_controller(¶ms, tc_get_position_generator(LC_TC_BACK), CONTROLLER_MODE_NORMAL); +} + +void lc_end_stop_reached(uint8_t end_stops) { + + // Set the end stop indicators and stop the lift if needed + if ((end_stops & LC_FRONT_UP) || (end_stops & LC_FRONT_BOTTOM)) { + if ((end_stops & LC_FRONT_UP) && (lc_state[LC_FRONT_LIFT].direction == 1)) + tc_stop(LC_TC_FRONT); + if ((end_stops & LC_FRONT_BOTTOM) && (lc_state[LC_FRONT_LIFT].direction == -1)) + tc_stop(LC_TC_FRONT); + lc_state[LC_FRONT_LIFT].end_stop_ind = end_stops & (LC_FRONT_UP|LC_FRONT_BOTTOM); + } + if ((end_stops & LC_BACK_UP) || (end_stops & LC_BACK_BOTTOM)) { + if ((end_stops & LC_BACK_UP) && (lc_state[LC_BACK_LIFT].direction == 1)) + tc_stop(LC_TC_BACK); + if ((end_stops & LC_BACK_BOTTOM) && (lc_state[LC_BACK_LIFT].direction == -1)) + tc_stop(LC_TC_BACK); + lc_state[LC_BACK_LIFT].end_stop_ind = (end_stops & (LC_BACK_UP|LC_BACK_BOTTOM)) >> 2; + } +} + +void lc_homing(uint8_t lift) { + // Go down + lc_state[lift].direction = -1; + tc_goto_speed(lc_state[lift].tc_ind, M_PI/4, 1); + // Wait for the end stop to trigger + while (!(lc_state[lift].end_stop_ind & LC_BOTTOM)) + cpu_relax(); + // Stop the lift + tc_stop(lc_state[lift].tc_ind); + // Assert end stop + lc_state[lift].end_stop_ind &= ~LC_BOTTOM; + // Wait and get current generator position as offset + timer_delay(50); + lc_state[lift].bottom = get_output_value(tc_get_position_generator(lc_state[lift].tc_ind)); + + // Go up + lc_state[lift].direction = 1; + tc_goto_speed(lc_state[lift].tc_ind, -M_PI/4, 1); + // Wait for the end stop to trigger + while (!(lc_state[lift].end_stop_ind & LC_UP)) + cpu_relax(); + // Stop the lift + tc_stop(lc_state[lift].tc_ind); + // Assert end stop + lc_state[lift].end_stop_ind &= ~LC_UP; + // Wait and get current generator position as offset + timer_delay(50); + lc_state[lift].extend = get_output_value(tc_get_position_generator(lc_state[lift].tc_ind)) - lc_state[lift].bottom; +} + +void lc_goto_position(uint8_t lift, float position) { + float goal = pos2angle(lift, position); + + if (goal > get_output_value(tc_get_position_generator(lc_state[lift].tc_ind))) { + lc_state[lift].direction = -1; + } else { + lc_state[lift].direction = 1; + } + tc_goto(lift, goal, M_PI, 5); +} + +void lc_release(void) { + mc_delete_controller(MOTOR3); + mc_delete_controller(MOTOR4); + + lc_state[LC_FRONT_LIFT].enabled = 0; + lc_state[LC_BACK_LIFT].enabled = 0; +} diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/lift_controller.h b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/lift_controller.h new file mode 100644 index 0000000..717c8cc --- /dev/null +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/lift_controller.h @@ -0,0 +1,41 @@ +/* + * lift_controller.h + * ----------------- + * Copyright : (c) 2011, Xavier Lagorce <Xav...@cr...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + */ + +#ifndef __LIFT_CONTROLLER_H +#define __LIFT_CONTROLLER_H + +#include "motor_controller.h" +#include "trajectory_controller.h" +#include "command_generator.h" + +#define LC_FRONT_LIFT 0 +#define LC_BACK_LIFT 1 + +#define LC_FRONT_UP 1 +#define LC_FRONT_BOTTOM 2 +#define LC_BACK_UP 4 +#define LC_BACK_BOTTOM 8 + +#define LC_UP 1 +#define LC_BOTTOM 2 + +#define LC_POSITION_BOTTOM 1 +#define LC_POSITION_MIDDLE 2 +#define LC_POSITION_UP 4 + +#define LC_TC_FRONT 0 +#define LC_TC_BACK 1 + +void lc_init(void); +void lc_end_stop_reached(uint8_t end_stops); +void lc_homing(uint8_t lift); +void lc_goto_position(uint8_t lift, float position); +void lc_release(void); + +#endif /* __LIFT_CONTROLLER_H */ diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/main.c b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/main.c index b769991..f906450 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/main.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/main.c @@ -21,8 +21,6 @@ PROC_DEFINE_STACK(stack_ind, KERN_MINSTACKSIZE * 2); static void init(void) { - motor_controller_params_t params; - IRQ_ENABLE; /* Initialize debugging module (allow kprintf(), etc.) */ @@ -36,38 +34,25 @@ static void init(void) */ proc_init(); - // Initialize CONTROL driver (will initialize MOTOR and ENCODER subsystems) - motorControllerInit(); - // Initialize CAN_MONITOR canMonitorInit(); - // Start control of drive motors + // Initialize CONTROL driver (will initialize MOTOR and ENCODER subsystems) + motorControllerInit(); + // Initialize Command generator tc_init(); - tc_new_controller(0); - tc_new_controller(1); - motorSetMaxPWM(MOTOR4, 1600); + // Initialize Lift Controller + lc_init(); + + // Init lifts + lc_homing(LC_BACK_LIFT); + lc_goto_position(LC_BACK_LIFT, 0.5); + while(tc_is_working(TC_MASK(LC_TC_BACK))) + timer_delay(100); + // Setup Beacon's motor motorSetMaxPWM(MOTOR2, 1080); enableMotor(MOTOR2); - // Common parameters - params.encoder_gain = 2.0*M_PI/588.0; - params.G0 = 0.0035; - params.tau = 0.025; - params.k[0] = -10216; - params.k[1] = -255.39; - params.l = -params.k[0]; - params.l0[0] = 0.0091; - params.l0[1] = 1.6361; - params.T = 0.005; - // Initialize forward lift - params.motor = MOTOR4; - params.encoder = ENCODER4; - //mc_new_controller(¶ms, tc_get_position_generator(0), CONTROLLER_MODE_NORMAL); - // Initialize backward lift - params.motor = MOTOR3; - params.encoder = ENCODER3; - //mc_new_controller(¶ms, tc_get_position_generator(1), CONTROLLER_MODE_NORMAL); // Blink to say we are ready for (uint8_t i=0; i < 5; i++) { @@ -87,22 +72,16 @@ static void init(void) static void NORETURN ind_process(void) { while(1) { - LED4_ON(); - tc_goto(0, 50/23.475, M_PI, 5); - while(tc_is_working(TC_MASK(0))) + LED1_ON(); + lc_goto_position(LC_BACK_LIFT, 1.); + while(tc_is_working(TC_MASK(LC_TC_BACK))) timer_delay(100); - timer_delay(500); - LED4_OFF(); - tc_goto(0, -50/23.475, M_PI, 5); - while(tc_is_working(TC_MASK(0))) + timer_delay(1000); + LED1_OFF(); + lc_goto_position(LC_BACK_LIFT, 0); + while(tc_is_working(TC_MASK(LC_TC_BACK))) timer_delay(100); - timer_delay(500); - - /*if (dd_get_ghost_state(NULL, NULL) == DD_GHOST_MOVING) { - LED1_ON(); - } else { - LED1_OFF(); - }*/ + timer_delay(1000); } } @@ -114,7 +93,6 @@ int main(void) //proc_new(ind_process, NULL, sizeof(stack_ind), stack_ind); // Tests - //motorSetSpeed(MOTOR4, 400); motorSetSpeed(MOTOR2, 1000); /* diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/trajectory_controller.c b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/trajectory_controller.c index 2ae2d4f..ef59d93 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/trajectory_controller.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/trajectory_controller.c @@ -214,6 +214,23 @@ command_generator_t* tc_get_speed_generator(uint8_t cntr_index) { } void tc_goto(uint8_t cntr_index, float angle, float speed, float acceleration) { + trajectory_controller_t *cont; + + // Verify parameters + if (angle == 0 || speed <= 0 || acceleration <= 0) + return; + + // Get the controller and verifies it is enabled + if (cntr_index >= NUM_TC_MAX) + return; + cont = &controllers[cntr_index]; + if (!cont->enabled) + return; + + tc_move(cntr_index, angle - get_output_value(&cont->position), speed, acceleration); +} + +void tc_move(uint8_t cntr_index, float angle, float speed, float acceleration) { float acc_dist, t_acc, t_end; trajectory_controller_t *cont; @@ -321,46 +338,26 @@ void tc_set_speed(uint8_t cntr_index, float speed) { cont->working = 0; } +void tc_stop(uint8_t cntr_index) { + trajectory_controller_t *cont; + // Get the controller and verifies it is enabled + if (cntr_index >= NUM_TC_MAX) + return; + cont = &controllers[cntr_index]; + if (!cont->enabled) + return; -void tc_move(tc_robot_t *robot, float distance, float speed, float acceleration) { - float dis_s, spe_s, acc_s; - - // Let's pause the wheel's speed generators to synchronize movement start - pause_generator(&controllers[robot->left_wheel].speed); - pause_generator(&controllers[robot->right_wheel].speed); - - // Compute parameters - dis_s = distance / robot->wheel_radius; - spe_s = speed / robot->wheel_radius; - acc_s = acceleration / robot->wheel_radius; + // Disable a possibly running profile + cont->aut.state = TRAPEZOID_STATE_STOP; + remove_callback(&cont->position); + remove_callback(&cont->speed); - // Planify movements - tc_goto(robot->left_wheel, dis_s, spe_s, acc_s); - tc_goto(robot->right_wheel, dis_s, spe_s, acc_s); + // Stop generator evolution + adjust_speed(&cont->speed, 0.); + adjust_value(&cont->speed, 0.); - // Go - start_generator(&controllers[robot->left_wheel].speed); - start_generator(&controllers[robot->right_wheel].speed); + // Trajectory controller is not working anylonger + cont->working = 0; } -void tc_turn(tc_robot_t *robot, float angle, float speed, float acceleration) { - float angle_s, spe_s, acc_s; - - // Let's pause the wheel's speed generators to synchronize movement start - pause_generator(&controllers[robot->left_wheel].speed); - pause_generator(&controllers[robot->right_wheel].speed); - - // Compute parameters - angle_s = angle * robot->shaft_width / 2.0 / robot->wheel_radius; - spe_s = speed * robot->shaft_width / 2.0 / robot->wheel_radius; - acc_s = acceleration * robot->shaft_width / 2.0 / robot->wheel_radius; - - // Planify movements - tc_goto(robot->left_wheel, -angle_s, spe_s, acc_s); - tc_goto(robot->right_wheel, angle_s, spe_s, acc_s); - - // Go - start_generator(&controllers[robot->left_wheel].speed); - start_generator(&controllers[robot->right_wheel].speed); -} diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/trajectory_controller.h b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/trajectory_controller.h index cf8452d..ba4df32 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/trajectory_controller.h +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Effectors/controller_motor_stm32/trajectory_controller.h @@ -61,6 +61,13 @@ command_generator_t* tc_get_position_generator(uint8_t cntr_index); */ command_generator_t* tc_get_speed_generator(uint8_t cntr_index); +/* Moves to a given angle + * - angle : angle to move to. The units corresponds to the given scaling factor + * during initialization. + * - speed : moving speed (in units per second) should be positive. + * - acceleration : in units per second per second, should be positive. + */ +void tc_goto(uint8_t cntr_index, float angle, float speed, float acceleration); /* Moves of a given angle * - angle : angle to move of, can be positive (forward) or negative @@ -69,7 +76,7 @@ command_generator_t* tc_get_speed_generator(uint8_t cntr_index); * - speed : moving speed (in units per second) should be positive. * - acceleration : in units per second per second, should be positive. */ -void tc_goto(uint8_t cntr_index, float angle, float speed, float acceleration); +void tc_move(uint8_t cntr_index, float angle, float speed, float acceleration); /* Accelerates or brakes the robot to the given speed * @@ -81,22 +88,9 @@ void tc_goto_speed(uint8_t cntr_index, float speed, float acceleration); */ void tc_set_speed(uint8_t cntr_index, float speed); -/* Moves along a line - * - robot : pointer to a structure describing the robot configuration - * - distance : distance to move of (in meters), can be positive (forward) - * or negative (backward). - * - speed : moving speed (in meters per second) should be positive. - * - acceleration : in meters per second per second, should be positive. - */ -void tc_move(tc_robot_t *robot, float distance, float speed, float acceleration); - -/* Turns around the propulsion shaft center - * - robot : pointer to a structure describing the robot configuration - * - angle : angle to turn of (in degrees), can be positive (CCW) - * or negative (CW). - * - speed : turning speed (in degrees per second) should be positive. - * - acceleration : in degrees per second per second, should be positive. +/* + * Stops the current movement by keeping the current value */ -void tc_turn(tc_robot_t *robot, float angle, float speed, float acceleration); +void tc_stop(uint8_t cntr_index); #endif /* __TRAJECTORY_CONTROLLER_H */ diff --git a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/differential_drive.c b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/differential_drive.c index 179db7f..ea27a98 100644 --- a/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/differential_drive.c +++ b/elec/boards/Controller_Motor_STM32/Firmwares/Propulsion_Drive/controller_motor_stm32/differential_drive.c @@ -87,6 +87,8 @@ static void NORETURN traj_following_process(void) { params.working = 0; traj->initialized = 0; traj->enabled = 0; + if (params.u > 1.0) + params.u = 1.0; if (!params.trajs[next_traj].initialized) { // We have no other trajectory to follow, let's brake dd_set_rotational_speed(0., params.at_max); diff --git a/elec/boards/Sensor_Actuator/Firmware/reset_ax12/Makefile b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/Makefile new file mode 100644 index 0000000..174ec1b --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/Makefile @@ -0,0 +1,17 @@ +# +# Copyright 2009 Develer S.r.l. (http://www.develer.com/) +# All rights reserved. +# +# Author: Lorenzo Berni <du...@de...> +# + +# Set to 1 for verbose build output, 0 for terse output +V := 0 + +default: all + +include bertos/config.mk + +include test_ax12/test_ax12.mk + +include bertos/rules.mk diff --git a/elec/boards/Sensor_Actuator/Firmware/reset_ax12/VERSION b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/VERSION new file mode 100644 index 0000000..e520145 --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/VERSION @@ -0,0 +1 @@ +BeRTOS 2.6.99 [local copy] diff --git a/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc.c b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc.c new file mode 100644 index 0000000..d4293f9 --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc.c @@ -0,0 +1,102 @@ +/** + * \file + * <!-- + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2003,2004 Develer S.r.l. (http://www.develer.com/) + * Copyright 1999 Bernie Innocenti <be...@co...> + * + * --> + * + * \brief CRC table and support routines + * + * \author Bernie Innocenti <be...@co...> + */ + +#include "crc.h" + +/* + * The boot on AVR cpu is placed at the end of flash memory, but the avr + * address memory by byte and the pointers are 16bits long, so we are able + * to address 64Kbyte memory max. For this reason we can't read the crctab + * from flash, because it is placed at the end of memory. This is true every + * time we have an AVR cpu with more that 64Kbyte of flash. To fix this problem + * we let the compiler copy the table in RAM at startup. Obviously this solution + * is not efficent, but for now this is the only way. + */ +#if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT)) + #define CRC_TABLE const uint16_t PROGMEM crc16tab[256] +#else + #define CRC_TABLE const uint16_t crc16tab[256] +#endif + +/** + * crctab calculated by Mark G. Mendel, Network Systems Corporation + */ +CRC_TABLE = { + 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, + 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, + 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, + 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, + 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, + 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, + 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, + 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, + 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, + 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, + 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, + 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, + 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, + 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, + 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, + 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, + 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, + 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, + 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, + 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, + 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, + 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, + 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, + 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, + 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, + 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, + 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, + 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, + 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, + 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, + 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, + 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 +}; + +uint16_t crc16(uint16_t crc, const void *buffer, size_t len) +{ + const unsigned char *buf = (const unsigned char *)buffer; + while(len--) + crc = UPDCRC16(*buf++, crc); + + return crc; +} + diff --git a/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc.h b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc.h new file mode 100644 index 0000000..c5c1eef --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc.h @@ -0,0 +1,115 @@ +/** + * \file + * <!-- + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/) + * Copyright 1999 Bernie Innocenti <be...@co...> + * + * --> + * + * \brief Cyclic Redundancy Check 16 (CRC). This algorithm is the one used by the XMODEM protocol. + * + * \note This algorithm is incompatible with the CCITT-CRC16. + * + * This code is based on the article Copyright 1986 Stephen Satchell. + * + * Programmers may incorporate any or all code into their programs, + * giving proper credit within the source. Publication of the + * source routines is permitted so long as proper credit is given + * to Stephen Satchell, Satchell Evaluations and Chuck Forsberg, + * Omen Technology. + * + * \author Bernie Innocenti <be...@co...> + * + * $WIZ$ module_name = "crc16" + */ + +#ifndef ALGO_CRC_H +#define ALGO_CRC_H + +#include "cfg/cfg_arch.h" + +#include <cfg/compiler.h> +#include <cpu/pgm.h> + +EXTERN_C_BEGIN + +/* CRC table */ +extern const uint16_t crc16tab[256]; + + +/** + * \brief Compute the updated CRC16 value for one octet (macro version) + * + * \note This version is only intended for old/broken compilers. + * Use the inline function in new code. + * + * \param c New octet (range 0-255) + * \param oldcrc Previous CRC16 value (referenced twice, beware of side effects) + */ +#if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT)) + #define UPDCRC16(c, oldcrc) (pgm_read_uint16_t(&crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8)) +#else + #define UPDCRC16(c, oldcrc) ((crc16tab[((oldcrc) >> 8) ^ ((unsigned char)(c))]) ^ ((oldcrc) << 8)) +#endif + +/** CRC-16 init value */ +#define CRC16_INIT_VAL ((uint16_t)0) + +#ifdef INLINE +/** + * \brief Compute the updated CRC16 value for one octet (inline version) + */ +INLINE uint16_t updcrc16(uint8_t c, uint16_t oldcrc) +{ +#if CPU_HARVARD && !(defined(ARCH_BOOT) && (ARCH & ARCH_BOOT)) + return pgm_read_uint16_t(&crc16tab[(oldcrc >> 8) ^ c]) ^ (oldcrc << 8); +#else + return crc16tab[(oldcrc >> 8) ^ c] ^ (oldcrc << 8); +#endif +} +#endif // INLINE + + +/** + * This function implements the CRC 16 calculation on a buffer. + * + * \param crc Current CRC16 value. + * \param buf The buffer to perform CRC calculation on. + * \param len The length of the Buffer. + * + * \return The updated CRC16 value. + */ +extern uint16_t crc16(uint16_t crc, const void *buf, size_t len); + +int crc_testSetup(void); +int crc_testRun(void); +int crc_testTearDown(void); + +EXTERN_C_END + +#endif /* ALGO_CRC_H */ diff --git a/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc_ccitt.c b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc_ccitt.c new file mode 100644 index 0000000..feaf624 --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc_ccitt.c @@ -0,0 +1,83 @@ +/** + * \file + * <!-- + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2009 Develer S.r.l. (http://www.develer.com/) + * + * --> + * + * \brief CRC-CCITT table and support routines + * + * \author Francesco Sacchi <ba...@de...> + */ + +#include "crc_ccitt.h" + +const uint16_t PROGMEM crc_ccitt_tab[256] = { + 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, + 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, + 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, + 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, + 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, + 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, + 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, + 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, + 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, + 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, + 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, + 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, + 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, + 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, + 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, + 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, + 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, + 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, + 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, + 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, + 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, + 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, + 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, + 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, + 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, + 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, + 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, + 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, + 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, + 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, + 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, + 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78, +}; + +uint16_t crc_ccitt(uint16_t crc, const void *buffer, size_t len) +{ + const unsigned char *buf = (const unsigned char *)buffer; + while (len--) + crc = updcrc_ccitt(*buf++, crc); + + return crc; +} + diff --git a/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc_ccitt.h b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc_ccitt.h new file mode 100644 index 0000000..240e6e1 --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc_ccitt.h @@ -0,0 +1,78 @@ +/** + * \file + * <!-- + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * templates or use macros or inline functions from this file, or you compile + * this file and link it with other files to produce an executable, this + * file does not by itself cause the resulting executable to be covered by + * the GNU General Public License. This exception does not however + * invalidate any other reasons why the executable file might be covered by + * the GNU General Public License. + * + * Copyright 2009 Develer S.r.l. (http://www.develer.com/) + * + * --> + * + * \brief CCITT Cyclic Redundancy Check (CRC-CCITT). + * + * \note This algorithm is incompatible with the CRC16. + * + * \author Francesco Sacchi <ba...@de...> + * + * $WIZ$ module_name = "crc-ccitt" + */ + +#ifndef ALGO_CRC_CCITT_H +#define ALGO_CRC_CCITT_H + +#include <cfg/compiler.h> +#include <cpu/pgm.h> + +EXTERN_C_BEGIN + +/* CRC table */ +extern const uint16_t crc_ccitt_tab[256]; + +/** + * \brief Compute the updated CRC-CCITT value for one octet (inline version) + */ +INLINE uint16_t updcrc_ccitt(uint8_t c, uint16_t oldcrc) +{ + return (oldcrc >> 8) ^ pgm_read16(&crc_ccitt_tab[(oldcrc ^ c) & 0xff]); +} + +/** CRC-CCITT init value */ +#define CRC_CCITT_INIT_VAL ((uint16_t)0xFFFF) + + +/** + * This function implements the CRC-CCITT calculation on a buffer. + * + * \param crc Current CRC-CCITT value. + * \param buf The buffer to perform CRC calculation on. + * \param len The length of the Buffer. + * + * \return The updated CRC-CCITT value. + */ +extern uint16_t crc_ccitt(uint16_t crc, const void *buf, size_t len); + +EXTERN_C_END + +#endif /* ALGO_CRC_CCITT_H */ diff --git a/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc_test.c b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc_test.c new file mode 100644 index 0000000..1a93e3b --- /dev/null +++ b/elec/boards/Sensor_Actuator/Firmware/reset_ax12/bertos/algo/crc_test.c @@ -0,0 +1,75 @@ +/** + * \file + * <!-- + * This file is part of BeRTOS. + * + * Bertos is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * As a special exception, you may use this file as part of a free software + * library without restriction. Specifically, if other files instantiate + * temp... [truncated message content] |