34 #include <memPoolService.h> 37 #include <carme_io1.h> 44 #define BUTTON_T0 0x01 45 #define BUTTON_T1 0x02 46 #define BUTTON_T2 0x04 47 #define BUTTON_T3 0x08 50 #define ROBOT_L_STATUS_REQUEST_ID 0x150 51 #define ROBOT_L_STATUS_RETURN_ID 0x151 52 #define ROBOT_L_COMAND_REQUEST_ID 0x152 53 #define ROBOT_L_COMAND_RETURN_ID 0x153 54 #define ROBOT_L_RESET_ID 0x15F 55 #define COMAND_DLC 0x006 56 #define STATUS_REQEST_DLC 0x002 60 #define ROBOT_R_STATUS_REQUEST_ID 0x160 61 #define ROBOT_R_STATUS_RETURN_ID 0x161 62 #define ROBOT_R_COMAND_REQUEST_ID 0x162 63 #define ROBOT_R_COMAND_RETURN_ID 0x163 64 #define ROBOT_R_RESET_ID 0x16F 66 #define MASK_SWITCH_0 0x01 67 #define MASK_SWITCH_1 0x02 68 #define MASK_SWITCH_2 0x04 69 #define MASK_SWITCH_3 0x08 70 #define MASK_SWITCH_4 0x10 73 #define BLOCK_TIME_MIDDLE_POS 200000 // block time for mutex midle position 74 #define MSG_QUEUE_SIZE 1 75 #define ARM_TASK_PRIORITY 2 76 #define ARM_TASK_STACKSIZE 256 77 #define TASK_DELAY 100 91 static void wait_until_pos(uint8_t *pos,
enum arm_select side);
94 static QueueHandle_t robot_left_queue;
95 static QueueHandle_t robot_right_queue;
96 static QueueHandle_t robot_manual_queue;
98 static SemaphoreHandle_t arm_mid_air_mutex;
118 static void arm_enter_critical_air_space()
121 xSemaphoreTake(arm_mid_air_mutex, portMAX_DELAY);
135 static void arm_leave_critical_air_space()
138 xSemaphoreGive(arm_mid_air_mutex);
156 int id_arm_comand_request;
160 static uint8_t pos_arm_right[11][6] = {
162 {0x02, 0x00, 0x19, 0x1A, 0x21, 0x01},
163 {0x02, 0x00, 0x1F, 0x1A, 0x21, 0x01},
164 {0x02, 0x00, 0x1F, 0x1A, 0x21, 0x00},
165 {0x02, 0x00, 0x19, 0x1A, 0x21, 0x00},
166 {0x02, 0xee, 0x00, 0x40, 0x21, 0x00},
167 {0x02, 0xD2, 0x00, 0x2b, 0x21, 0x00},
168 {0x02, 0xD2, 0x1c, 0x1d, 0x21, 0x00},
169 {0x02, 0xD2, 0x1c, 0x1d, 0x21, 0x01},
170 {0x02, 0xD2, 0x13, 0x1d, 0x21, 0x01},
171 {0x02, 0xD2, 0x00, 0x36, 0x21, 0x01},
172 {0x02, 0xEE, 0x00, 0x36, 0x21, 0x01},
175 arm_mid_air_mutex = xSemaphoreCreateBinary();
176 xSemaphoreGive(arm_mid_air_mutex);
178 robot_right_queue = xQueueCreate(
MSG_QUEUE_SIZE,
sizeof(CARME_CAN_MESSAGE));
181 pos_arm = (uint8_t *)pos_arm_right;
188 static uint8_t pos_arm_left[11][6] = {
190 {0x02, 0x00, 0x19, 0x1A, 0x21, 0x01},
191 {0x02, 0x00, 0x1F, 0x1A, 0x21, 0x01},
192 {0x02, 0x00, 0x1F, 0x1A, 0x21, 0x00},
193 {0x02, 0x00, 0x19, 0x1A, 0x21, 0x00},
194 {0x02, 0x12, 0x00, 0x40, 0x21, 0x00},
195 {0x02, 0x2D, 0x00, 0x2b, 0x21, 0x00},
196 {0x02, 0x2D, 0x1c, 0x1d, 0x21, 0x00},
197 {0x02, 0x2D, 0x1c, 0x1d, 0x21, 0x01},
198 {0x02, 0x2D, 0x13, 0x1d, 0x21, 0x01},
199 {0x02, 0x2D, 0x00, 0x36, 0x21, 0x01},
200 {0x02, 0x12, 0x00, 0x36, 0x21, 0x01},
203 pos_arm = (uint8_t *)pos_arm_left;
206 robot_left_queue = xQueueCreate(
MSG_QUEUE_SIZE,
sizeof(CARME_CAN_MESSAGE));
216 for(
int n = 0; n < 11; n++) {
227 arm_enter_critical_air_space();
237 wait_until_pos(&pos_arm[n*6], left_right_sel);
248 arm_leave_critical_air_space();
267 static void wait_until_pos(uint8_t *pos,
enum arm_select side)
269 uint8_t *temp = (uint8_t *)pos;
270 bool close_enough =
false;
275 while(close_enough !=
true) {
282 for(
int i=1; i<6; i++) {
283 if(abs(temp[i]-robot_msg_buffer_right.data[i])>0x01) {
284 close_enough =
false;
293 while(close_enough !=
true) {
301 for(
int i=1; i<6; i++) {
302 if(abs(temp[i]-robot_msg_buffer_left.data[i])>0x01) {
303 close_enough =
false;
374 uint8_t pos_manuel[6] = {0x02, 0x00, 0x00, 0x00, 0x00, 0x00};
375 bool increment =
false;
376 bool left_select =
false;
378 CARME_CAN_MESSAGE robot_msg_buffer_manual;
379 robot_manual_queue = xQueueCreate(
MSG_QUEUE_SIZE,
sizeof(CARME_CAN_MESSAGE));
384 CARME_IO1_BUTTON_Get(&button_data);
385 CARME_IO1_SWITCH_Get(&switch_data);
405 switch(button_data) {
408 if(increment ==
true) {
416 if(increment ==
true) {
424 if(increment ==
true) {
432 if(increment ==
true) {
442 if(left_select ==
true) {
447 xQueueReceive(robot_manual_queue, (
void *)&robot_msg_buffer_manual, portMAX_DELAY);
453 xQueueReceive(robot_manual_queue, (
void *)&robot_msg_buffer_manual, portMAX_DELAY);
458 robot_msg_buffer_manual.data[1],
459 robot_msg_buffer_manual.data[2],
460 robot_msg_buffer_manual.data[3],
461 robot_msg_buffer_manual.data[4],
462 robot_msg_buffer_manual.data[5]);
void bcs_signal_band_free(enum belt_select belt)
Signal that a block has been removed from a belt and the belt is free again global.
void manual_arm_movement(void *pvData)
Task to move the roboter with the Buttons. To create this task unkomment it in the function init_arm(...
#define ROBOT_R_STATUS_RETURN_ID
uint8_t status_request[2]
void move_roboter(void *pv_data)
Task for left and right arm.
bool ucan_link_message_to_queue(uint16_t message_id, QueueHandle_t queue)
Link a single message type to a queue global.
void bcs_signal_dropped(enum belt_select belt)
Signal that a block has been dropped on a belt global.
bool ucan_send_data(uint8_t n_data_bytes, uint16_t msg_id, const uint8_t *data)
Send data to the can output message queue global.
#define STATUS_REQEST_DLC
void bcs_prepare_drop(enum belt_select belt)
Prepares a block drop operation to a specific belt global.
#define ROBOT_L_STATUS_REQUEST_ID
uint8_t display_log(uint8_t id, const char *fmtstr,...)
Logs a message to the display global.
#define ROBOT_R_STATUS_REQUEST_ID
#define ROBOT_R_COMAND_REQUEST_ID
int8_t bcs_grab(enum belt_select belt)
Instructs the system that we want to grab a block from the bcs global.
#define ROBOT_L_COMAND_REQUEST_ID
#define ARM_TASK_PRIORITY
CARME_CAN_MESSAGE robot_msg_buffer_left
arm_select
The arm_select enum differenciates between the different arms (left/right)
#define ROBOT_L_STATUS_RETURN_ID
void init_arm()
Creates the arm tasks.
#define ARM_TASK_STACKSIZE
CARME_CAN_MESSAGE robot_msg_buffer_right