Skip to content

Commit

Permalink
Major 2019 update
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Feb 18, 2019
1 parent 43c3bba commit 123bb00
Show file tree
Hide file tree
Showing 134 changed files with 11,866 additions and 1,599 deletions.
65 changes: 65 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
=== FW 3.48 ===
* Added pairing flag to appconf.
* Decreased CAN TX timeout.

=== FW 3.47 ===
* Current percentage limits.
* Mcconf_temp based on current scale instead of absolute current.
* Removed battery current from mcconf_temp.
* Added current scale parameter.
* Different braking behavior: prefer cogging over locking the brakes.

=== FW 3.46 ===
* DC motor RPM measurement and RPM control when using encoder.
* Support for configurable current low pass filter.
* Much better recovery when failing to decode packets.
* Run all detect functions in separate thread.
* Fixed bug introduced when adding support for dual UARTs.
* Added support for reverse state on NRF remote.
* Support to disable app output for a specified time.

=== FW 3.45 ===
* Default CAN ID from UUID, and hook to define it in hwconf.
* CAN ping support.
* Simultaneous firmware update over CAN-bus.
* Fully automated motor detection, based on maximum motor power losses.
* Sensor autodetection and configuration support.
* Softer encoder detection.
* Better NRF_EXT support.
* New more reliable flux linkage measurement.
* Simpler to add hardware versions to build system.
* More DAS hardware support.
* DRV8323s support.
* Initial UAVCAN support.
* Moved from uart to serial driver to avoid DMA conflicts.
* Support for permanent UART.

=== FW 3.44 ===
* NRF_EXT commands support.
- Use NRF51822 with ESB remotes.
* Different radio channel for NRF pairing.

=== FW 3.43 ===
* Added battery ah to setup info.
* Changed tacho values in COMM_GET_VALUES_SETUP to meters.
* Added battery wh COMM_GET_VALUES_SETUP.
* Better remaining battery capacity calculation.

=== FW 3.42 ===
* Added setup info parameters:
- Motor Poles
- Gear Ratio
- Wheel Diameter
- Battery Type
- Battery Cells
* Added more CAN status messages.
* Updated speed PID to start properly when braking is disabled.
* Added COMM_GET_VALUES_SETUP.
* Added COMM_SET_MCCONF_TEMP.
* Added COMM_SET_MCCONF_TEMP_SETUP.
* Added COMM_GET_VALUES_SELECTIVE.
* Added COMM_GET_VALUES_SETUP_SELECTIVE.

=== FW 3.41 ===
* First general purpose DC output implementation.

=== FW 3.40 ===
* Added motor controller ID to COMM_GET_VALUES.

Expand Down
22 changes: 20 additions & 2 deletions CONTRIBUTING
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,36 @@ and

* If you write function comments, write them Doxygen-style.

* There is no limit on line length, so long lines in general should not be wrapped.
* Line lengths should be kept below 90 characters if possible, but that is not a strict requirement if braking the line looks ugly.

* Source files should end with a new line.

* Avoid more than one conscutive empty line.


=== Make sure that all hardware versions and configuration variations work ===

When making updates it is easy to break things for different configurations. In order to make sure that the firmware at least builds for different hardwares and configurations it is a good idea to run the build_all/rebuild_all script and ensure that is finished without warnings and/or errors.


=== Other guidelines ===

* Use single precition floating point operations, as the FPU in the STM32F4 is 32 bits only. Double precision operations can take up to 50 times (!) longer.
- float instead if double
- Use the math library functions ending with f (sinf, cosf, powf, fabsf etc.)

* Make sure that the code compiles without warnings.

* Avoid dynamic memory allocation if possible, so that the RAM usage is known at compile time.

* If the code crashed randomly, use the ChibiOS state checker:
http://www.chibios.org/dokuwiki/doku.php?id=chibios:articles:state_checker


=== Be patient, and don't take criticism personally ===

Be prepared to have to rework your contribution several times before it is considered acceptable. Once code is in, it's difficult to get it reworked for better quality, so it's important that this is done before the code is even accepted. Don't take it personally; instead appreciate that it is this peer review that makes the code great in the end!



Thanks for reading!

7 changes: 5 additions & 2 deletions ChibiOS_3.0.2/os/hal/src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) {
usbp->ep0state = USB_EP0_WAITING_TX0;
return;
}
/* Falls through. */
/* Falls into, it is intentional.*/
case USB_EP0_WAITING_TX0:
/* Transmit phase over, receiving the zero sized status packet.*/
Expand All @@ -782,7 +783,8 @@ void _usb_ep0in(USBDriver *usbp, usbep_t ep) {
case USB_EP0_RX:
/* All the above are invalid states in the IN phase.*/
osalDbgAssert(false, "EP0 state machine error");
/* Falling through is intentional.*/
/* Falls through. */
/* Falling into is intentional.*/
case USB_EP0_ERROR:
/* Error response, the state machine goes into an error state, the low
level layer will have to reset it to USB_EP0_WAITING_SETUP after
Expand Down Expand Up @@ -842,7 +844,8 @@ void _usb_ep0out(USBDriver *usbp, usbep_t ep) {
case USB_EP0_SENDING_STS:
/* All the above are invalid states in the IN phase.*/
osalDbgAssert(false, "EP0 state machine error");
/* Falling through is intentional.*/
/* Falls through. */
/* Falling into is intentional.*/
case USB_EP0_ERROR:
/* Error response, the state machine goes into an error state, the low
level layer will have to reset it to USB_EP0_WAITING_SETUP after
Expand Down
2 changes: 2 additions & 0 deletions ChibiOS_3.0.2/os/rt/src/chschd.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,11 @@ static void wakeup(void *p) {
#if CH_CFG_USE_SEMAPHORES == TRUE
case CH_STATE_WTSEM:
chSemFastSignalI(tp->p_u.wtsemp);
/* Falls through. */
/* Falls into, intentional. */
#endif
#if (CH_CFG_USE_CONDVARS == TRUE) && (CH_CFG_USE_CONDVARS_TIMEOUT == TRUE)
/* Falls through. */
case CH_STATE_WTCOND:
#endif
case CH_STATE_QUEUED:
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_v7m.mk
include hwconf/hwconf.mk
include applications/applications.mk
include nrf/nrf.mk
include libcanard/canard.mk

# Define linker script file here
LDSCRIPT= ld_eeprom_emu.ld
Expand Down Expand Up @@ -147,9 +148,11 @@ CSRC = $(STARTUPSRC) \
flash_helper.c \
mc_interface.c \
mcpwm_foc.c \
gpdrive.c \
$(HWSRC) \
$(APPSRC) \
$(NRFSRC)
$(NRFSRC) \
$(CANARDSRC)

# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
Expand Down Expand Up @@ -186,7 +189,8 @@ INCDIR = $(STARTUPINC) $(KERNINC) $(PORTINC) $(OSALINC) \
appconf \
$(HWINC) \
$(APPINC) \
$(NRFINC)
$(NRFINC) \
$(CANARDINC)

#
# Project, sources and paths
Expand Down
23 changes: 16 additions & 7 deletions appconf/appconf_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

// Default app configuration
#ifndef APPCONF_CONTROLLER_ID
#define APPCONF_CONTROLLER_ID 0
#define APPCONF_CONTROLLER_ID -1 // Controller id. -1 means it should be calculated from UUID.
#endif
#ifndef APPCONF_TIMEOUT_MSEC
#define APPCONF_TIMEOUT_MSEC 1000
Expand All @@ -31,14 +31,23 @@
#define APPCONF_TIMEOUT_BRAKE_CURRENT 0.0
#endif
#ifndef APPCONF_SEND_CAN_STATUS
#define APPCONF_SEND_CAN_STATUS false
#define APPCONF_SEND_CAN_STATUS CAN_STATUS_DISABLED
#endif
#ifndef APPCONF_UAVCAN_ENABLE
#define APPCONF_UAVCAN_ENABLE false
#endif
#ifndef APPCONF_UAVCAN_ESC_INDEX
#define APPCONF_UAVCAN_ESC_INDEX 0
#endif
#ifndef APPCONF_SEND_CAN_STATUS_RATE_HZ
#define APPCONF_SEND_CAN_STATUS_RATE_HZ 100
#define APPCONF_SEND_CAN_STATUS_RATE_HZ 50
#endif
#ifndef APPCONF_CAN_BAUD_RATE
#define APPCONF_CAN_BAUD_RATE CAN_BAUD_500K
#endif
#ifndef APPCONF_PAIRING_DONE
#define APPCONF_PAIRING_DONE false
#endif

// The default app is UART in case the UART port is used for
// firmware updates.
Expand Down Expand Up @@ -87,7 +96,7 @@
#define APPCONF_PPM_RAMP_TIME_NEG 0.1
#endif
#ifndef APPCONF_PPM_MULTI_ESC
#define APPCONF_PPM_MULTI_ESC false
#define APPCONF_PPM_MULTI_ESC true
#endif
#ifndef APPCONF_PPM_TC
#define APPCONF_PPM_TC false
Expand Down Expand Up @@ -116,7 +125,7 @@
#define APPCONF_ADC_VOLTAGE2_START 0.9
#endif
#ifndef APPCONF_ADC_VOLTAGE2_END
#define APPCONF_ADC_VOLTAGE2_END 3.0
#define APPCONF_ADC_VOLTAGE2_END 3.0
#endif
#ifndef APPCONF_ADC_USE_FILTER
#define APPCONF_ADC_USE_FILTER true
Expand Down Expand Up @@ -152,7 +161,7 @@
#define APPCONF_ADC_RAMP_TIME_NEG 0.1
#endif
#ifndef APPCONF_ADC_MULTI_ESC
#define APPCONF_ADC_MULTI_ESC false
#define APPCONF_ADC_MULTI_ESC true
#endif
#ifndef APPCONF_ADC_TC
#define APPCONF_ADC_TC false
Expand Down Expand Up @@ -195,7 +204,7 @@
#define APPCONF_CHUK_THROTTLE_EXP_MODE THR_EXP_POLY
#endif
#ifndef APPCONF_CHUK_MULTI_ESC
#define APPCONF_CHUK_MULTI_ESC false
#define APPCONF_CHUK_MULTI_ESC true
#endif
#ifndef APPCONF_CHUK_TC
#define APPCONF_CHUK_TC false
Expand Down
43 changes: 42 additions & 1 deletion applications/app.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016 Benjamin Vedder [email protected]
Copyright 2016 - 2019 Benjamin Vedder [email protected]
This file is part of the VESC firmware.
Expand Down Expand Up @@ -27,6 +27,12 @@

// Private variables
static app_configuration appconf;
static virtual_timer_t output_vt;
static bool output_vt_init_done = false;
static volatile bool output_disabled_now = false;

// Private functions
static void output_vt_cb(void *arg);

const app_configuration* app_get_configuration(void) {
return &appconf;
Expand Down Expand Up @@ -117,3 +123,38 @@ void app_set_configuration(app_configuration *conf) {

rfhelp_update_conf(&appconf.app_nrf_conf);
}

/**
* Disable output on apps
*
* @param time_ms
* The amount of time to disable output in ms
* 0: Enable output now
* -1: Disable forever
* >0: Amount of milliseconds to disable output
*/
void app_disable_output(int time_ms) {
if (!output_vt_init_done) {
chVTObjectInit(&output_vt);
output_vt_init_done = true;
}

if (time_ms == 0) {
output_disabled_now = false;
} else if (time_ms == -1) {
output_disabled_now = true;
chVTReset(&output_vt);
} else {
output_disabled_now = true;
chVTSet(&output_vt, MS2ST(time_ms), output_vt_cb, 0);
}
}

bool app_is_output_disabled(void) {
return output_disabled_now;
}

static void output_vt_cb(void *arg) {
(void)arg;
output_disabled_now = false;
}
4 changes: 4 additions & 0 deletions applications/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
// Functions
const app_configuration* app_get_configuration(void);
void app_set_configuration(app_configuration *conf);
void app_disable_output(int time_ms);
bool app_is_output_disabled(void);

// Standard apps
void app_ppm_start(void);
Expand All @@ -41,8 +43,10 @@ float app_adc_get_decoded_level2(void);
float app_adc_get_voltage2(void);

void app_uartcomm_start(void);
void app_uartcomm_start_permanent(void);
void app_uartcomm_stop(void);
void app_uartcomm_configure(uint32_t baudrate);
void app_uartcomm_send_packet(unsigned char *data, unsigned int len);

void app_nunchuk_start(void);
void app_nunchuk_stop(void);
Expand Down
6 changes: 6 additions & 0 deletions applications/app_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ static THD_FUNCTION(adc_thread, arg) {
}
}

// All pins and buttons are still decoded for debugging, even
// when output is disabled.
if (app_is_output_disabled()) {
continue;
}

switch (config.ctrl_type) {
case ADC_CTRL_TYPE_CURRENT_REV_CENTER:
case ADC_CTRL_TYPE_CURRENT_NOREV_BRAKE_CENTER:
Expand Down
Loading

0 comments on commit 123bb00

Please sign in to comment.