void motion_init(void) // Initialize the curve buffer. { // Initialize the counter. motion_counter = 0; // Initialize the duration. motion_duration = 0; // Initialize the queue. motion_head = 0; motion_tail = 0; // Initialize the keypoint. keys[0].delta = 0; keys[0].position = 512.0; keys[0].in_velocity = 0.0; keys[0].out_velocity = 0.0; // Initialize an empty hermite curve at the center servo position. curve_init(0, 0, 512.0, 512.0, 0.0, 0.0); // Reset the registers. motion_registers_reset(); }
void motion_reset(int16_t position) // Reset the motion buffer to the specified position. The enabled state is preserved. { // Reset the counter. motion_counter = 0; // Reset the duration. motion_duration = 0; // Reset the queue. motion_head = 0; motion_tail = 0; // Reset the keypoint. keys[0].delta = 0; keys[0].position = int_to_float(position); keys[0].in_velocity = 0.0; keys[0].out_velocity = 0.0; // Initialize an empty hermite curve. This is a degenerate case for the hermite // curve that will always return the position of the curve without velocity. curve_init(0, 0, keys[0].position, keys[0].position, 0.0, 0.0); // Reset the registers. motion_registers_reset(); }
uint8_t motion_append(void) // Append a new curve keypoint from data stored in the curve registers. The keypoint // is offset from the previous curve by the specified delta. An error is returned if // there is no more room to store the new keypoint in the buffer or if the delta is // less than one (a zero delta is not allowed). { int16_t position; int16_t in_velocity; int16_t out_velocity; uint8_t next; uint16_t delta; // Get the next index in the buffer. next = (motion_head + 1) & MOTION_BUFFER_MASK; // Return error if we have looped the head to the tail and the buffer is filled. if (next == motion_tail) return 0; // Get the position, velocity and time delta values from the registers. position = (int16_t) registers_read_word(REG_CURVE_POSITION_HI, REG_CURVE_POSITION_LO); in_velocity = (int16_t) registers_read_word(REG_CURVE_IN_VELOCITY_HI, REG_CURVE_IN_VELOCITY_LO); out_velocity = (int16_t) registers_read_word(REG_CURVE_OUT_VELOCITY_HI, REG_CURVE_OUT_VELOCITY_LO); delta = (uint16_t) registers_read_word(REG_CURVE_DELTA_HI, REG_CURVE_DELTA_LO); // Keypoint delta must be greater than zero. if (delta < 1) return 0; // Fill in the next keypoint. keys[next].delta = delta; keys[next].position = int_to_float(position); keys[next].in_velocity = fixed_to_float(in_velocity); keys[next].out_velocity = fixed_to_float(out_velocity); // Is this keypoint being added to an empty buffer? if (motion_tail == motion_head) { // Initialize a new hermite curve that gets us from the current position to the new position. // We use a velocity of zero at each end to smoothly transition from one to the other. curve_init(0, delta, curve_get_p1(), keys[next].position, 0.0, 0.0); } // Increase the duration of the buffer. motion_duration += delta; // Set the new head index. motion_head = next; // Reset the motion registers and update the buffer status. motion_registers_reset(); return 1; }
static void initpq(params_t params) //calculate system parameters that can be determined from p and q //also initialize the elliptic curve library so points can be used { mpz_init(params->p1onq); mpz_add_ui(params->p1onq, params->p, 1); mpz_divexact(params->p1onq, params->p1onq, params->q); //initialize the elliptic curve library curve_init(params->curve, params->p, params->q); fp2_init(params->zeta); fp2_set_cbrt_unity(params->zeta, params->p); }
//============================================ // メインプログラム //============================================ int main(void) { EC_GROUP ec; curve_init(ec, "ec_bn254_tw"); test_feature(ec); test_arithmetic_operation(ec); test_map_to_point(ec); test_io(ec); curve_clear(ec); fprintf(stderr, "ok\n"); return 0; }
void init_all() { // Field Initialisation: Kfield_init(); // Curve Initialisation: curve_init(); // Generator Initalisation: generator_init(); // Order of the subgroup: mpz_init_set_str(p, "53919893334301279666889509884200806281039951735555151719046432375393",10); size_of_p = mpz_sizeinbase(p,2); // Initialisation of global dummys: int i; for(i = 0; i < NUMBER_OF_DUMMYELTS; i++) { Kinit(&(dummyelts[i])); } }
void motion_next(uint16_t delta) // Increment the buffer counter by the indicated delta and return the position // and velocity from the buffered curves. If the delta is zero the current // position and velocity is returned. { float fposition; float fvelocity; // Determine if curve motion is disabled in the registers. if (!(registers_read_byte(REG_FLAGS_LO) & (1<<FLAGS_LO_MOTION_ENABLED))) return; // Are we processing an empty curve? if (motion_tail == motion_head) { // Yes. Keep the counter and duration at zero. motion_counter = 0; motion_duration = 0; } else { // Increment the counter. motion_counter += delta; // Have we exceeded the duration of the currently buffered curve? while (motion_counter > curve_get_duration()) { // Reduce the buffer counter by the currently buffered curve duration. motion_counter -= curve_get_duration(); // Reduce the buffer duration by the currently buffered curve duration. motion_duration -= curve_get_duration(); // Increment the tail to process the next buffered curve. motion_tail = (motion_tail + 1) & MOTION_BUFFER_MASK; // Has the tail caught up with the head? if (motion_tail == motion_head) { // Initialize an empty hermite curve with a zero duration. This is a degenerate case for // the hermite cuve that will always return the position of the curve without velocity. curve_init(0, 0, keys[motion_head].position, keys[motion_head].position, 0.0, 0.0); // Reset the buffer counter and duration to zero. motion_counter = 0; motion_duration = 0; } else { uint8_t curr_point; uint8_t next_point; // Get the current point and next point for the curve. curr_point = motion_tail; next_point = (curr_point + 1) & MOTION_BUFFER_MASK; // Initialize the hermite curve from the current and next point. curve_init(0, keys[next_point].delta, keys[curr_point].position, keys[next_point].position, keys[curr_point].out_velocity, keys[next_point].in_velocity); } // Update the space available in the buffer. registers_write_byte(REG_CURVE_BUFFER, motion_buffer_left()); } } // Get the position and velocity from the hermite curve. curve_solve(motion_counter, &fposition, &fvelocity); // The velocity is in position units a millisecond, but we really need the // velocity to be measured in position units every 10 milliseconds to match // the sample period of the ADC. fvelocity *= 10.0; // Update the seek position register. registers_write_word(REG_SEEK_POSITION_HI, REG_SEEK_POSITION_LO, float_to_int(fposition)); // Update the seek velocity register. registers_write_word(REG_SEEK_VELOCITY_HI, REG_SEEK_VELOCITY_LO, float_to_int(fvelocity)); }
// Create and handle the plugin's dialog gboolean dialog(PluginData *pd) { gimp_ui_init (PLUG_IN_BINARY, FALSE); GtkWidget *dialog, *main_hbox, *hbox_buttons, *preview, *graph, *vbox, *preview_button, *preview_hd_checkbox; dialog = gimp_dialog_new ("Frequency Curves", PLUG_IN_BINARY, NULL, (GtkDialogFlags)0, gimp_standard_help_func, PLUG_IN_NAME, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); main_hbox = gtk_hbox_new (FALSE, 12); gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 12); gtk_container_add (GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), main_hbox); curve_init(&pd->curve_user); curve_copy(&pd->curve_user, &pd->curve_fft); pd->preview = gimp_drawable_preview_new (pd->drawable, 0); gtk_box_pack_start (GTK_BOX (main_hbox), pd->preview, TRUE, TRUE, 0); gtk_widget_show (pd->preview); g_signal_connect_swapped (pd->preview, "invalidated", G_CALLBACK (preview_invalidated), pd); vbox = gtk_vbox_new (FALSE, 12); gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); gtk_container_add (GTK_CONTAINER(main_hbox), vbox); gtk_widget_show(vbox); graph = pd->graph = gtk_drawing_area_new(); pd->graph_pixmap = NULL; gtk_widget_set_size_request (graph, GRAPH_WIDTH, GRAPH_HEIGHT); gtk_widget_set_events (graph, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_ENTER_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON1_MOTION_MASK); gtk_container_add (GTK_CONTAINER (vbox), graph); gtk_widget_show (graph); g_signal_connect (graph, "event", G_CALLBACK (graph_events), pd); hbox_buttons = gtk_hbox_new (FALSE, 12); gtk_container_set_border_width (GTK_CONTAINER (hbox_buttons), 12); gtk_container_add (GTK_CONTAINER(vbox), hbox_buttons); gtk_widget_show(hbox_buttons); preview_button = gtk_button_new_with_mnemonic ("HD _Preview"); gtk_box_pack_start (GTK_BOX (hbox_buttons), preview_button, FALSE, FALSE, 0); gtk_widget_show (preview_button); g_signal_connect (preview_button, "clicked", G_CALLBACK (preview_hd), pd); preview_hd_checkbox = gtk_check_button_new_with_label("Always preview HD"); gtk_box_pack_start (GTK_BOX (hbox_buttons), preview_hd_checkbox, FALSE, FALSE, 0); gtk_widget_show (preview_hd_checkbox); pd->do_preview_hd = FALSE; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(preview_hd_checkbox), FALSE); g_signal_connect (preview_hd_checkbox, "toggled", G_CALLBACK (preview_hd_toggled), pd); gtk_widget_show(main_hbox); gtk_widget_show(dialog); fft_prepare(pd); histogram_generate(pd); wavelet_prepare(pd); gboolean run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK); if (run) { // set the region mode to actual writing gimp_pixel_rgn_init(&pd->region, pd->drawable, 0, 0, pd->image_width, pd->image_height, TRUE, TRUE); fft_apply(pd); gimp_pixel_rgn_set_rect(&pd->region, pd->img_pixels, 0, 0, pd->image_width, pd->image_height); // show the result gimp_drawable_flush(pd->drawable); gimp_drawable_merge_shadow(pd->drawable->drawable_id, TRUE); gimp_drawable_update(pd->drawable->drawable_id, pd->selection_offset_x, pd->selection_offset_y, pd->selection_width, pd->selection_height); gimp_displays_flush(); } fft_destroy(pd); wavelet_destroy(pd); gtk_widget_destroy (dialog); return run; }